Redraw at 60Hz with adaptive rate smoothing, console output at 1Hz
This commit is contained in:
@@ -106,6 +106,17 @@ func (d *display) center(f *textFace, y int, s string, col rgb) {
|
||||
f.draw(d.fb, (d.fb.w-len([]rune(s))*f.cellW)/2, y, s, col)
|
||||
}
|
||||
|
||||
// Rendered rates are quantised so the text only changes when the value moves
|
||||
// meaningfully. Without this the low digits churn every frame no matter how
|
||||
// long the averaging window is.
|
||||
func roundPPS(v float64) uint64 {
|
||||
const unit = 1000
|
||||
if v < 0 {
|
||||
return 0
|
||||
}
|
||||
return uint64((v+unit/2)/unit) * unit
|
||||
}
|
||||
|
||||
func errColor(n uint64) rgb {
|
||||
if n == 0 {
|
||||
return uiGreen
|
||||
@@ -156,7 +167,7 @@ func (d *display) render(dirs []*direction, views []view, elapsed time.Duration,
|
||||
avail := fb.h - (bandY + bandH) - 16
|
||||
y := bandY + bandH + 8 + (avail-2*sectionH-gap)/2
|
||||
|
||||
y = d.section(y, "INSTANT", "this interval")
|
||||
y = d.section(y, "RATE")
|
||||
d.rightAt(colTxGbEnd, y, "TX Gb/s", uiDim)
|
||||
d.rightAt(colTxPPSEnd, y, "TX pps", uiDim)
|
||||
d.rightAt(colRxGbEnd, y, "RX Gb/s", uiDim)
|
||||
@@ -166,14 +177,14 @@ func (d *display) render(dirs []*direction, views []view, elapsed time.Duration,
|
||||
d.dirTag(dir, y)
|
||||
v := views[i]
|
||||
d.rightAt(colTxGbEnd, y, fmt.Sprintf("%.2f", v.txGbps), rateColor(v.txGbps, target))
|
||||
d.rightAt(colTxPPSEnd, y, commas(uint64(v.txPPS)), uiFg)
|
||||
d.rightAt(colTxPPSEnd, y, commas(roundPPS(v.txPPS)), uiFg)
|
||||
d.rightAt(colRxGbEnd, y, fmt.Sprintf("%.2f", v.rxGbps), rateColor(v.rxGbps, target))
|
||||
d.rightAt(colRxPPSEnd, y, commas(uint64(v.rxPPS)), uiFg)
|
||||
d.rightAt(colRxPPSEnd, y, commas(roundPPS(v.rxPPS)), uiFg)
|
||||
y += lineH
|
||||
}
|
||||
|
||||
y += gap
|
||||
y = d.section(y, "CUMULATIVE", "since reset")
|
||||
y = d.section(y, "OVERALL")
|
||||
d.rightAt(colFramesEnd, y, "frames", uiDim)
|
||||
d.rightAt(colDataEnd, y, "data", uiDim)
|
||||
d.rightAt(colLostEnd, y, "lost", uiDim)
|
||||
@@ -196,9 +207,8 @@ func (d *display) render(dirs []*direction, views []view, elapsed time.Duration,
|
||||
fb.flush()
|
||||
}
|
||||
|
||||
func (d *display) section(y int, title, sub string) int {
|
||||
func (d *display) section(y int, title string) int {
|
||||
d.small.draw(d.fb, uiMargin, y, title, uiFg)
|
||||
d.small.draw(d.fb, uiMargin+(len(title)+2)*d.small.cellW, y, sub, uiDim)
|
||||
ruleY := y + d.small.cellH + 3
|
||||
d.fb.rect(uiMargin, ruleY, d.fb.w-2*uiMargin, 1, uiRule)
|
||||
return ruleY + 7
|
||||
|
||||
Reference in New Issue
Block a user