feat: humanized durations in stat provide
(cherry picked from commit e5ac70456dadd6723833d67c5cb6dd53b0d880cf)
Marcin Rataj committed
May 27, 2021 at 16:49 UTC
229dfa675557bd539d9c6aa8b3082cc359bf149c
1 file changed
+7
-2
core/commands/stat_provide.go
+7
-2
@@ -4,6 +4,7 @@ import (
4
"fmt"
5
"io"
6
"text/tabwriter"
7
+ "time"
8
9
humanize "github.com/dustin/go-humanize"
10
cmds "github.com/ipfs/go-ipfs-cmds"
@@ -56,8 +57,8 @@ This interface is not stable and may change from release to release.
57
58
tp := float64(s.TotalProvides)
59
fmt.Fprintf(wtr, "TotalProvides:\t%s\t(%s)\n", humanSI(tp, 0), humanFull(tp, 0))
59
- fmt.Fprintf(wtr, "AvgProvideDuration:\t%v\n", s.AvgProvideDuration)
60
- fmt.Fprintf(wtr, "LastReprovideDuration:\t%v\n", s.LastReprovideDuration)
60
+ fmt.Fprintf(wtr, "AvgProvideDuration:\t%v\n", humanDuration(s.AvgProvideDuration))
61
+ fmt.Fprintf(wtr, "LastReprovideDuration:\t%v\n", humanDuration(s.LastReprovideDuration))
62
lrbs := float64(s.LastReprovideBatchSize)
63
fmt.Fprintf(wtr, "LastReprovideBatchSize:\t%s\t(%s)\n", humanSI(lrbs, 0), humanFull(lrbs, 0))
64
return nil
@@ -66,6 +67,10 @@ This interface is not stable and may change from release to release.
67
Type: batched.BatchedProviderStats{},
68
}
69
70
+func humanDuration(val time.Duration) string {
71
+ return val.Truncate(time.Microsecond).String()
72
+}
73
+
74
func humanSI(val float64, decimals int) string {
75
v, unit := humanize.ComputeSI(val)
76
return humanize.SIWithDigits(v, decimals, unit)