From a24a2c10b57585afd9fcb6af91a1c736b2ddb30c Mon Sep 17 00:00:00 2001 From: Felix Kollmann Date: Sat, 21 Dec 2019 20:08:49 +0100 Subject: [PATCH] Improve stats dump --- stats.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/stats.go b/stats.go index adfc602..286eefb 100644 --- a/stats.go +++ b/stats.go @@ -2,6 +2,7 @@ package xdelta import ( "fmt" + "github.com/dustin/go-humanize" lib "github.com/konsorten/go-xdelta/xdelta-lib" "sync" "time" @@ -9,14 +10,14 @@ import ( type Stats struct { states map[lib.XdeltaState]time.Duration - dataBytes map[lib.XdeltaState]int64 + dataBytes map[lib.XdeltaState]uint64 lock sync.Mutex } func newStats() *Stats { return &Stats{ states: make(map[lib.XdeltaState]time.Duration), - dataBytes: make(map[lib.XdeltaState]int64), + dataBytes: make(map[lib.XdeltaState]uint64), } } @@ -28,7 +29,7 @@ func (s *Stats) DumpToStdout() { for k, v := range s.states { dataBytes, _ := s.dataBytes[k] - fmt.Printf(" State %10v lastet %v and processed %v bytes\n", k, v, dataBytes) + fmt.Printf(" State %10v lastet %v and processed %v bytes (%v)\n", k, v, dataBytes, humanize.Bytes(dataBytes)) } s.lock.Unlock() @@ -45,11 +46,15 @@ func (s *Stats) addStateTime(state lib.XdeltaState, duration time.Duration) { } func (s *Stats) addDataBytes(state lib.XdeltaState, amount int) { + if amount <= 0 { + return + } + s.lock.Lock() prev, _ := s.dataBytes[state] - s.dataBytes[state] = prev + int64(amount) + s.dataBytes[state] = prev + uint64(amount) s.lock.Unlock() }