Skip to content

Commit 73e614a

Browse files
authored
Make trace stats more compact (#4999)
Make `mc admin trace -stats` more compact, and hopefully more readable. * Truncates durations more reasonably * Use `-` for 0 TTFB. * Use `↑151B ↓12K` instead of `↑ 151 B ↓ 12 KiB/m` * Reduce FPS from 7 to 3 for less flickering.
1 parent 58c42bc commit 73e614a

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

cmd/trace-stats-ui.go

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/charmbracelet/bubbles/spinner"
2929
tea "github.com/charmbracelet/bubbletea"
3030
"github.com/charmbracelet/lipgloss"
31-
humanize "github.com/dustin/go-humanize"
31+
"github.com/dustin/go-humanize"
3232
"github.com/fatih/color"
3333
"github.com/minio/madmin-go/v3"
3434
"github.com/minio/pkg/v3/console"
@@ -154,7 +154,7 @@ func (m *traceStatsUI) View() string {
154154
}
155155
t = append(t,
156156
console.Colorize("metrics-top-title", "Avg Size"),
157-
console.Colorize("metrics-top-title", "Rate"),
157+
console.Colorize("metrics-top-title", "Rate /min"),
158158
console.Colorize("metrics-top-title", "Errors"),
159159
)
160160

@@ -193,24 +193,24 @@ func (m *traceStatsUI) View() string {
193193
sz := "-"
194194
rate := "-"
195195
if v.Size > 0 && v.Count > 0 {
196-
sz = humanize.IBytes(uint64(v.Size) / uint64(v.Count))
197-
rate = fmt.Sprintf("%s/m", humanize.IBytes(uint64(float64(v.Size)/dur.Minutes())))
196+
sz = ibytesShort(uint64(v.Size) / uint64(v.Count))
197+
rate = ibytesShort(uint64(float64(v.Size) / dur.Minutes()))
198198
}
199199
if v.CallStatsCount > 0 {
200200
var s, r []string
201201
if v.CallStats.Rx > 0 {
202-
s = append(s, fmt.Sprintf("↑ %s", humanize.IBytes(uint64(v.CallStats.Rx/v.CallStatsCount))))
203-
r = append(r, fmt.Sprintf("↑ %s", humanize.IBytes(uint64(float64(v.CallStats.Rx)/dur.Minutes()))))
202+
s = append(s, fmt.Sprintf("↑%s", ibytesShort(uint64(v.CallStats.Rx/v.CallStatsCount))))
203+
r = append(r, fmt.Sprintf("↑%s", ibytesShort(uint64(float64(v.CallStats.Rx)/dur.Minutes()))))
204204
}
205205
if v.CallStats.Tx > 0 {
206-
s = append(s, fmt.Sprintf("↓ %s", humanize.IBytes(uint64(v.CallStats.Tx/v.CallStatsCount))))
207-
r = append(r, fmt.Sprintf("↓ %s", humanize.IBytes(uint64(float64(v.CallStats.Tx)/dur.Minutes()))))
206+
s = append(s, fmt.Sprintf("↓%s", ibytesShort(uint64(v.CallStats.Tx/v.CallStatsCount))))
207+
r = append(r, fmt.Sprintf("↓%s", ibytesShort(uint64(float64(v.CallStats.Tx)/dur.Minutes()))))
208208
}
209-
if len(s) > 0 {
209+
if len(s)+len(r) > 0 {
210210
sz = strings.Join(s, " ")
211211
}
212212
if len(r) > 0 {
213-
rate = strings.Join(r, " ") + "/m"
213+
rate = strings.Join(r, " ")
214214
}
215215
}
216216
if sz != "-" {
@@ -223,14 +223,18 @@ func (m *traceStatsUI) View() string {
223223
console.Colorize("metrics-number", fmt.Sprintf("%d ", v.Count)) +
224224
console.Colorize("metrics-number-secondary", fmt.Sprintf("(%0.1f%%)", float64(v.Count)/float64(totalCnt)*100)),
225225
console.Colorize("metrics-number", fmt.Sprintf("%0.1f", float64(v.Count)/dur.Minutes())),
226-
console.Colorize(avgColor, fmt.Sprintf("%v", avg.Round(time.Microsecond))),
227-
console.Colorize(minColor, v.MinDur),
228-
console.Colorize(maxColor, v.MaxDur),
226+
console.Colorize(avgColor, fmt.Sprintf("%v", roundDur(avg))),
227+
console.Colorize(minColor, roundDur(v.MinDur)),
228+
console.Colorize(maxColor, roundDur(v.MaxDur)),
229229
}
230230
if hasTTFB {
231-
t = append(t,
232-
console.Colorize(avgColor, fmt.Sprintf("%v", avgTTFB.Round(time.Microsecond))),
233-
console.Colorize(maxColor, v.MaxTTFB))
231+
if v.TTFB > 0 {
232+
t = append(t,
233+
console.Colorize(avgColor, fmt.Sprintf("%v", roundDur(avgTTFB))),
234+
console.Colorize(maxColor, roundDur(v.MaxTTFB)))
235+
} else {
236+
t = append(t, "-", "-")
237+
}
234238
}
235239
t = append(t, sz, rate, errs)
236240
table.Append(t)
@@ -250,10 +254,31 @@ func (m *traceStatsUI) View() string {
250254
return strings.Join(split, "\n")
251255
}
252256

257+
// ibytesShort returns a short un-padded version of the value from humanize.IBytes.
258+
func ibytesShort(v uint64) string {
259+
return strings.ReplaceAll(strings.TrimSuffix(humanize.IBytes(v), "iB"), " ", "")
260+
}
261+
262+
// roundDur will round the duration to a nice, printable number, with "reasonable" precision.
263+
func roundDur(d time.Duration) time.Duration {
264+
if d > time.Minute {
265+
return d.Round(time.Second)
266+
}
267+
if d > time.Second {
268+
return d.Round(time.Millisecond)
269+
}
270+
if d > time.Millisecond {
271+
return d.Round(time.Millisecond / 10)
272+
}
273+
return d.Round(time.Microsecond)
274+
}
275+
253276
func initTraceStatsUI(maxEntries int, traces <-chan madmin.ServiceTraceInfo) *traceStatsUI {
254277
meter := spinner.New()
255278
meter.Spinner = spinner.Meter
256279
meter.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
280+
// Use half the default fps to reduce flickering
281+
meter.Spinner.FPS = time.Second / 3
257282
console.SetColor("metrics-duration", color.New(color.FgWhite))
258283
console.SetColor("metrics-size", color.New(color.FgGreen))
259284
console.SetColor("metrics-dur", color.New(color.FgGreen))

0 commit comments

Comments
 (0)