Add resource stats logging

This commit is contained in:
Richard Patel
2018-11-05 22:41:17 +01:00
parent 395a6f30b2
commit add6581804
5 changed files with 72 additions and 22 deletions

18
util.go Normal file
View File

@@ -0,0 +1,18 @@
package main
import "fmt"
// https://programming.guide/go/formatting-byte-size-to-human-readable-format.html
func FormatByteCount(b uint64) string {
const unit = 1024
if b < unit {
return fmt.Sprintf("%d B", b)
} else {
div, exp := int64(unit), 0
for n := b / unit; n >= unit; n /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp])
}
}