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
1 changed files with 6 additions and 6 deletions

View File

@ -108,9 +108,9 @@ func commandBackup(be backend.Server, key *khepri.Key, args []string) error {
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",
format_duration(uint64(d/time.Second)),
format_duration(sec),
float64(stats.Bytes)/float64(arch.Stats.Bytes)*100,
format_bytes(bps),
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.Bytes += s.Bytes
status(time.Since(start))
status(uint64(time.Since(start) / time.Second))
case <-ticker.C:
d := time.Since(start)
bps = stats.Bytes * uint64(time.Second) / uint64(d)
sec := uint64(time.Since(start) / time.Second)
bps = stats.Bytes / sec
if bps > 0 {
eta = (arch.Stats.Bytes - stats.Bytes) / bps
}
status(d)
status(sec)
}
}
}(ch)