Fold the leftover formatters into the SI ones and stop reallocating the draw scratch

This commit is contained in:
flamingcow
2026-08-04 13:37:19 -07:00
parent f5a6420cfa
commit 2035d42734
7 changed files with 42 additions and 60 deletions
+14 -14
View File
@@ -57,7 +57,7 @@ type direction struct {
base counterSet
heldFrames heldValue
heldSent heldValue
heldBytes heldValue
nic atomic.Uint64
poller *nicPoller
}
@@ -253,7 +253,7 @@ func (d *direction) reset() {
d.mu.Unlock()
d.heldFrames = heldValue{}
d.heldSent = heldValue{}
d.heldBytes = heldValue{}
d.cable.reset()
}
@@ -297,12 +297,12 @@ var intervalCols = []colSpec{
// Shared by the console table and the framebuffer so both show the same
// figures.
type view struct {
txPPS, rxPPS float64
txGbps, rxGbps float64
rxFrames, rxGot uint64
since errs
window errs
cable cableView
txPPS, rxPPS float64
txGbps, rxGbps float64
rxFrames, rxBytes uint64
since errs
window errs
cable cableView
}
func errsBetween(b, n counterSet) errs {
@@ -326,7 +326,7 @@ func errsBetween(b, n counterSet) errs {
func (d *direction) counters(now counterSet) view {
return view{
rxFrames: now.s.rxFrames - d.base.s.rxFrames,
rxGot: now.s.rxBytes - d.base.s.rxBytes,
rxBytes: now.s.rxBytes - d.base.s.rxBytes,
cable: d.cable.view(),
since: errsBetween(d.base, now),
}
@@ -340,7 +340,7 @@ func totalView(views []view) view {
t.txGbps += v.txGbps
t.rxGbps += v.rxGbps
t.rxFrames += v.rxFrames
t.rxGot += v.rxGot
t.rxBytes += v.rxBytes
t.since = t.since.add(v.since)
t.window = t.window.add(v.window)
}
@@ -393,7 +393,7 @@ func (d *direction) displayView(t time.Time) view {
d.mu.Unlock()
v.rxFrames = d.heldFrames.get(t, v.rxFrames)
v.rxGot = d.heldSent.get(t, v.rxGot)
v.rxBytes = d.heldBytes.get(t, v.rxBytes)
return v
}
@@ -678,9 +678,9 @@ func run(aName, bName string, nsPerM float64) error {
{"probe", fmt.Sprintf("ethertype 0x%04x every %s", probeEther, probeInterval)},
{"batch", fmt.Sprintf("%d frames per syscall", batchSize)},
{"calibration", fmt.Sprintf("%g ns/m, zero taken from the shortest delay seen so far", nsPerM)},
{"buffers", fmt.Sprintf("sndbuf %s, rcvbuf %s",
humanBytes(uint64(sockBufSize(dirs[0].txFDs[0], unix.SO_SNDBUF))),
humanBytes(uint64(sockBufSize(dirs[0].rxFDs[0], unix.SO_RCVBUF))))},
{"buffers", fmt.Sprintf("sndbuf %sB, rcvbuf %sB",
scaleCount(uint64(sockBufSize(dirs[0].txFDs[0], unix.SO_SNDBUF))),
scaleCount(uint64(sockBufSize(dirs[0].rxFDs[0], unix.SO_RCVBUF))))},
}))
fmt.Println()