Change bps and eta calculation to prevent overflow

This commit is contained in:
Alexander Neumann 2014-11-23 14:54:02 +01:00
parent 6d0a6844e2
commit a780462b80

View file

@ -108,9 +108,9 @@ func commandBackup(be backend.Server, key *khepri.Key, args []string) error {
go func(ch <-chan khepri.Stats) { go func(ch <-chan khepri.Stats) {
status := func(d time.Duration) { status := func(sec uint64) {
fmt.Printf("\x1b[2K\r[%s] %3.2f%% %s/s %s / %s ETA %s", fmt.Printf("\x1b[2K\r[%s] %3.2f%% %s/s %s / %s ETA %s",
format_duration(uint64(d/time.Second)), format_duration(sec),
float64(stats.Bytes)/float64(arch.Stats.Bytes)*100, float64(stats.Bytes)/float64(arch.Stats.Bytes)*100,
format_bytes(bps), format_bytes(bps),
format_bytes(stats.Bytes), format_bytes(arch.Stats.Bytes), format_bytes(stats.Bytes), format_bytes(arch.Stats.Bytes),
@ -129,16 +129,16 @@ func commandBackup(be backend.Server, key *khepri.Key, args []string) error {
stats.Other += s.Other stats.Other += s.Other
stats.Bytes += s.Bytes stats.Bytes += s.Bytes
status(time.Since(start)) status(uint64(time.Since(start) / time.Second))
case <-ticker.C: case <-ticker.C:
d := time.Since(start) sec := uint64(time.Since(start) / time.Second)
bps = stats.Bytes * uint64(time.Second) / uint64(d) bps = stats.Bytes / sec
if bps > 0 { if bps > 0 {
eta = (arch.Stats.Bytes - stats.Bytes) / bps eta = (arch.Stats.Bytes - stats.Bytes) / bps
} }
status(d) status(sec)
} }
} }
}(ch) }(ch)