Changed large ints to uint64 for 32bit architectures

This commit is contained in:
Caleb Bassi 2018-02-19 20:00:18 -08:00
parent b26c871e28
commit 26942f61ae
4 changed files with 20 additions and 18 deletions

View File

@ -24,6 +24,8 @@ To uninstall:
sudo rm /usr/bin/gotop sudo rm /usr/bin/gotop
``` ```
Currently only tested on Arch Linux x86_64, so create an issue if the binary for you OS doesn't work or if there isn't one.
### Arch Linux ### Arch Linux

View File

@ -4,14 +4,14 @@ import (
"math" "math"
) )
func BytesToKB(b int) int { func BytesToKB(b uint64) uint64 {
return int((float64(b) / math.Pow10(3))) return uint64((float64(b) / math.Pow10(3)))
} }
func BytesToMB(b int) int { func BytesToMB(b uint64) uint64 {
return int((float64(b) / math.Pow10(6))) return uint64((float64(b) / math.Pow10(6)))
} }
func BytesToGB(b int) int { func BytesToGB(b uint64) uint64 {
return int((float64(b) / math.Pow10(9))) return uint64((float64(b) / math.Pow10(9)))
} }

View File

@ -33,5 +33,5 @@ func NewDisk() *Disk {
func (d *Disk) update() { func (d *Disk) update() {
disk, _ := ps.Usage(d.fs) disk, _ := ps.Usage(d.fs)
d.Percent = int(disk.UsedPercent) d.Percent = int(disk.UsedPercent)
d.Description = fmt.Sprintf(" (%dGB free)", utils.BytesToGB(int(disk.Free))) d.Description = fmt.Sprintf(" (%dGB free)", utils.BytesToGB(disk.Free))
} }

View File

@ -12,8 +12,8 @@ import (
type Net struct { type Net struct {
*ui.Sparklines *ui.Sparklines
interval time.Duration interval time.Duration
recvTotal int recvTotal uint64
sentTotal int sentTotal uint64
} }
func NewNet() *Net { func NewNet() *Net {
@ -40,15 +40,15 @@ func NewNet() *Net {
func (n *Net) update() { func (n *Net) update() {
interfaces, _ := ps.IOCounters(false) interfaces, _ := ps.IOCounters(false)
recv := int(interfaces[0].BytesRecv) recv := interfaces[0].BytesRecv
sent := int(interfaces[0].BytesSent) sent := interfaces[0].BytesSent
if n.recvTotal != 0 { // if this isn't the first update if n.recvTotal != 0 { // if this isn't the first update
curRecv := recv - n.recvTotal curRecv := recv - n.recvTotal
curSent := sent - n.sentTotal curSent := sent - n.sentTotal
n.Lines[0].Data = append(n.Lines[0].Data, curRecv) n.Lines[0].Data = append(n.Lines[0].Data, int(curRecv))
n.Lines[1].Data = append(n.Lines[1].Data, curSent) n.Lines[1].Data = append(n.Lines[1].Data, int(curSent))
} }
n.recvTotal = recv n.recvTotal = recv
@ -56,7 +56,7 @@ func (n *Net) update() {
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
var method string var method string
var total int var total uint64
cur := n.Lines[i].Data[len(n.Lines[i].Data)-1] cur := n.Lines[i].Data[len(n.Lines[i].Data)-1]
totalUnit := "B" totalUnit := "B"
curUnit := "B" curUnit := "B"
@ -70,18 +70,18 @@ func (n *Net) update() {
} }
if cur >= 1000000 { if cur >= 1000000 {
cur = int(utils.BytesToMB(cur)) cur = int(utils.BytesToMB(uint64(cur)))
curUnit = "MB" curUnit = "MB"
} else if cur >= 1000 { } else if cur >= 1000 {
cur = int(utils.BytesToKB(cur)) cur = int(utils.BytesToKB(uint64(cur)))
curUnit = "kB" curUnit = "kB"
} }
if total >= 1000000000 { if total >= 1000000000 {
total = int(utils.BytesToGB(total)) total = utils.BytesToGB(total)
totalUnit = "GB" totalUnit = "GB"
} else if total >= 1000000 { } else if total >= 1000000 {
total = int(utils.BytesToMB(total)) total = utils.BytesToMB(total)
totalUnit = "MB" totalUnit = "MB"
} }