Changed large ints to uint64 for 32bit architectures
This commit is contained in:
parent
b26c871e28
commit
26942f61ae
|
@ -24,6 +24,8 @@ To uninstall:
|
|||
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
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"math"
|
||||
)
|
||||
|
||||
func BytesToKB(b int) int {
|
||||
return int((float64(b) / math.Pow10(3)))
|
||||
func BytesToKB(b uint64) uint64 {
|
||||
return uint64((float64(b) / math.Pow10(3)))
|
||||
}
|
||||
|
||||
func BytesToMB(b int) int {
|
||||
return int((float64(b) / math.Pow10(6)))
|
||||
func BytesToMB(b uint64) uint64 {
|
||||
return uint64((float64(b) / math.Pow10(6)))
|
||||
}
|
||||
|
||||
func BytesToGB(b int) int {
|
||||
return int((float64(b) / math.Pow10(9)))
|
||||
func BytesToGB(b uint64) uint64 {
|
||||
return uint64((float64(b) / math.Pow10(9)))
|
||||
}
|
||||
|
|
|
@ -33,5 +33,5 @@ func NewDisk() *Disk {
|
|||
func (d *Disk) update() {
|
||||
disk, _ := ps.Usage(d.fs)
|
||||
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))
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
type Net struct {
|
||||
*ui.Sparklines
|
||||
interval time.Duration
|
||||
recvTotal int
|
||||
sentTotal int
|
||||
recvTotal uint64
|
||||
sentTotal uint64
|
||||
}
|
||||
|
||||
func NewNet() *Net {
|
||||
|
@ -40,15 +40,15 @@ func NewNet() *Net {
|
|||
|
||||
func (n *Net) update() {
|
||||
interfaces, _ := ps.IOCounters(false)
|
||||
recv := int(interfaces[0].BytesRecv)
|
||||
sent := int(interfaces[0].BytesSent)
|
||||
recv := interfaces[0].BytesRecv
|
||||
sent := interfaces[0].BytesSent
|
||||
|
||||
if n.recvTotal != 0 { // if this isn't the first update
|
||||
curRecv := recv - n.recvTotal
|
||||
curSent := sent - n.sentTotal
|
||||
|
||||
n.Lines[0].Data = append(n.Lines[0].Data, curRecv)
|
||||
n.Lines[1].Data = append(n.Lines[1].Data, curSent)
|
||||
n.Lines[0].Data = append(n.Lines[0].Data, int(curRecv))
|
||||
n.Lines[1].Data = append(n.Lines[1].Data, int(curSent))
|
||||
}
|
||||
|
||||
n.recvTotal = recv
|
||||
|
@ -56,7 +56,7 @@ func (n *Net) update() {
|
|||
|
||||
for i := 0; i < 2; i++ {
|
||||
var method string
|
||||
var total int
|
||||
var total uint64
|
||||
cur := n.Lines[i].Data[len(n.Lines[i].Data)-1]
|
||||
totalUnit := "B"
|
||||
curUnit := "B"
|
||||
|
@ -70,18 +70,18 @@ func (n *Net) update() {
|
|||
}
|
||||
|
||||
if cur >= 1000000 {
|
||||
cur = int(utils.BytesToMB(cur))
|
||||
cur = int(utils.BytesToMB(uint64(cur)))
|
||||
curUnit = "MB"
|
||||
} else if cur >= 1000 {
|
||||
cur = int(utils.BytesToKB(cur))
|
||||
cur = int(utils.BytesToKB(uint64(cur)))
|
||||
curUnit = "kB"
|
||||
}
|
||||
|
||||
if total >= 1000000000 {
|
||||
total = int(utils.BytesToGB(total))
|
||||
total = utils.BytesToGB(total)
|
||||
totalUnit = "GB"
|
||||
} else if total >= 1000000 {
|
||||
total = int(utils.BytesToMB(total))
|
||||
total = utils.BytesToMB(total)
|
||||
totalUnit = "MB"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user