Skip to content

Commit

Permalink
feat: humanized durations in stat provide
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel authored and aschmahmann committed May 27, 2021
1 parent c082c73 commit e5ac704
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/commands/stat_provide.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"text/tabwriter"
"time"

humanize "github.com/dustin/go-humanize"
cmds "github.com/ipfs/go-ipfs-cmds"
Expand Down Expand Up @@ -56,8 +57,8 @@ This interface is not stable and may change from release to release.

tp := float64(s.TotalProvides)
fmt.Fprintf(wtr, "TotalProvides:\t%s\t(%s)\n", humanSI(tp, 0), humanFull(tp, 0))
fmt.Fprintf(wtr, "AvgProvideDuration:\t%v\n", s.AvgProvideDuration)
fmt.Fprintf(wtr, "LastReprovideDuration:\t%v\n", s.LastReprovideDuration)
fmt.Fprintf(wtr, "AvgProvideDuration:\t%v\n", humanDuration(s.AvgProvideDuration))
fmt.Fprintf(wtr, "LastReprovideDuration:\t%v\n", humanDuration(s.LastReprovideDuration))
lrbs := float64(s.LastReprovideBatchSize)
fmt.Fprintf(wtr, "LastReprovideBatchSize:\t%s\t(%s)\n", humanSI(lrbs, 0), humanFull(lrbs, 0))
return nil
Expand All @@ -66,6 +67,10 @@ This interface is not stable and may change from release to release.
Type: batched.BatchedProviderStats{},
}

func humanDuration(val time.Duration) string {
return val.Truncate(time.Microsecond).String()
}

func humanSI(val float64, decimals int) string {
v, unit := humanize.ComputeSI(val)
return humanize.SIWithDigits(v, decimals, unit)
Expand Down

0 comments on commit e5ac704

Please sign in to comment.