X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=lib%2Fcommon.go;h=9d31075e5af5dabc2de6eb722ff9537e9f2b2fdf;hb=da7982a6dc5c0387d4aadc996cfe5dc53dafbd45;hp=c04aab9417699c4f02e4f6892b16b5ee3e0ec701;hpb=38376bf5db9af25660b8183b2c022d079bb2b5ea;p=pstop.git diff --git a/lib/common.go b/lib/common.go index c04aab9..9d31075 100644 --- a/lib/common.go +++ b/lib/common.go @@ -9,8 +9,11 @@ import ( ) const ( - myname = "pstop" + myname = "pstop" copyright = "Copyright (C) 2014 Simon J Mudd " + i_1024_2 = 1024 * 1024 + i_1024_3 = 1024 * 1024 * 1024 + i_1024_4 = 1024 * 1024 * 1024 * 1024 ) // myround converts this floating value to the right width etc. @@ -32,7 +35,7 @@ func Copyright() string { // sec_to_time() converts a number of hours, minutes and seconds into hh:mm:ss format. // e.g. 7384 = 2h 3m 4s, 7200 + 180 + 4 -func sec_to_time(d int) string { +func sec_to_time(d uint64) string { hours := d / 3600 // integer value minutes := (d - hours*3600) / 60 // integer value seconds := d - hours*3600 - minutes*60 @@ -40,11 +43,11 @@ func sec_to_time(d int) string { return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds) } -// FormatTime is based on sys.format_time. It +// FormatTime is based on sys.format_time. It // formats to 10 characters including space and suffix. // All values have 2 decimal places. Zero is returned as // an empty string. -func FormatTime(picoseconds int) string { +func FormatTime(picoseconds uint64) string { if picoseconds == 0 { return "" } @@ -91,7 +94,7 @@ func FormatPct(pct float64) string { // For values = 0 return an empty string. // For values < 1000 show 6,2 decimal places. // For values >= 1000 show 6,1 decimal place. -func FormatAmount(amount int) string { +func FormatAmount(amount uint64) string { var suffix string var formatted string var decimal_amount float64 @@ -100,18 +103,18 @@ func FormatAmount(amount int) string { return "" } if amount <= 1024 { - return strconv.Itoa(amount) + return strconv.Itoa(int(amount)) } - if amount > (1024 * 1024 * 1024 * 1024) { + if amount > i_1024_4 { suffix = "P" - decimal_amount = float64(amount) / 1024 / 1024 / 1024 / 1024 - } else if amount > (1024 * 1024 * 1024) { + decimal_amount = float64(amount) / i_1024_4 + } else if amount > i_1024_3 { suffix = "G" - decimal_amount = float64(amount) / 1024 / 1024 / 1024 - } else if amount > (1024 * 1024) { + decimal_amount = float64(amount) / i_1024_3 + } else if amount > i_1024_2 { suffix = "M" - decimal_amount = float64(amount) / 1024 / 1024 + decimal_amount = float64(amount) / i_1024_2 } else if amount > 1024 { suffix = "k" decimal_amount = float64(amount) / 1024 @@ -126,7 +129,7 @@ func FormatAmount(amount int) string { } // MyDivide() divides a by b except if b is 0 in which case we return 0. -func MyDivide(a int, b int) float64 { +func MyDivide(a uint64, b uint64) float64 { if b == 0 { return float64(0) } else {