mirror of
https://github.com/restic/restic.git
synced 2024-12-25 09:18:55 +00:00
Fix floating point presentation
This commit is contained in:
parent
87a1946417
commit
6c776468ab
1 changed files with 23 additions and 10 deletions
|
@ -56,6 +56,26 @@ func formatSeconds(sec uint64) string {
|
||||||
return fmt.Sprintf("%d:%02d", min, sec)
|
return fmt.Sprintf("%d:%02d", min, sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatPercent(numerator uint64, denominator uint64) string {
|
||||||
|
if denominator == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
percent := 100.0 * float64(numerator) / float64(denominator)
|
||||||
|
|
||||||
|
if percent > 100 {
|
||||||
|
percent = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%3.2f%%", percent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatRate(bytes uint64, duration time.Duration) string {
|
||||||
|
sec := float64(duration) / float64(time.Second)
|
||||||
|
rate := float64(bytes) / sec / (1 << 20)
|
||||||
|
return fmt.Sprintf("%.2fMiB/s", rate)
|
||||||
|
}
|
||||||
|
|
||||||
func formatDuration(d time.Duration) string {
|
func formatDuration(d time.Duration) string {
|
||||||
sec := uint64(d / time.Second)
|
sec := uint64(d / time.Second)
|
||||||
return formatSeconds(sec)
|
return formatSeconds(sec)
|
||||||
|
@ -134,14 +154,10 @@ func newArchiveProgress(todo restic.Stat) *restic.Progress {
|
||||||
}
|
}
|
||||||
|
|
||||||
itemsDone := s.Files + s.Dirs
|
itemsDone := s.Files + s.Dirs
|
||||||
percent := float64(s.Bytes) / float64(todo.Bytes) * 100
|
|
||||||
if percent > 100 {
|
|
||||||
percent = 100
|
|
||||||
}
|
|
||||||
|
|
||||||
status1 := fmt.Sprintf("[%s] %3.2f%% %s/s %s / %s %d / %d items ",
|
status1 := fmt.Sprintf("[%s] %s %s/s %s / %s %d / %d items ",
|
||||||
formatDuration(d),
|
formatDuration(d),
|
||||||
percent,
|
formatPercent(s.Bytes, todo.Bytes),
|
||||||
formatBytes(bps),
|
formatBytes(bps),
|
||||||
formatBytes(s.Bytes), formatBytes(todo.Bytes),
|
formatBytes(s.Bytes), formatBytes(todo.Bytes),
|
||||||
itemsDone, itemsTodo)
|
itemsDone, itemsTodo)
|
||||||
|
@ -159,10 +175,7 @@ func newArchiveProgress(todo restic.Stat) *restic.Progress {
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
archiveProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
sec := uint64(d / time.Second)
|
fmt.Printf("\nduration: %s, %s\n", formatDuration(d), formatRate(todo.Bytes, d))
|
||||||
fmt.Printf("\nduration: %s, %.2fMiB/s\n",
|
|
||||||
formatDuration(d),
|
|
||||||
float64(todo.Bytes)/float64(sec)/(1<<20))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return archiveProgress
|
return archiveProgress
|
||||||
|
|
Loading…
Reference in a new issue