redbear-power: v1.16 — Network throughput (closes v1.11 forward work)
Closes the v1.11 §35.7 forward-work item. Network tab now shows real-time R/W throughput (KiB/s) per interface, computed from delta of rx_bytes/tx_bytes between successive 7th-tick refreshes. Source code already landed (network.rs + app.rs + render.rs). This commit captures full v1.16 docs: - Improvement plan §40 (Network Throughput) - CONSOLE-TO-KDE §3.3.2 v1.16 - RATATUI-APP-PATTERNS §13.14 (audit table +16) + §14 (5755 LoC, 52 tests) Implementation summary: - New rx_kbps: f64 + tx_kbps: f64 fields on NetInterface - New NetInfo::read_with_throughput(prev, dt_secs) - Wall-clock dt (shared prev_refresh_secs with v1.14 + v1.15) - saturating_sub on bytes prevents underflow - 3 new unit tests (formula + underflow + zero dt) - 52/52 total tests pass Math sanity check (verified by unit test): prev=1MB, now=5MB, dt=2sec → 1953.125 KiB/s prev > now → saturating_sub → 0 Cross-compile SHA256: 053f1a0cca5185637d0316d56f5cf5832cf2e754b689bc24edf16ea5d0404fa2.
This commit is contained in:
@@ -1493,6 +1493,40 @@ Cross-compiled binary: 3.9 MB stripped Redox ELF
|
||||
2. **Per-process disk I/O** — show per-process /proc/[pid]/io in Process tab.
|
||||
3. **Disk temperature** — link hwmon temp to Storage panel.
|
||||
|
||||
#### v1.16 Network Throughput in Network Tab (2026-06-20)
|
||||
|
||||
Per the user's "v1.16 = Network throughput (Recommended)" directive,
|
||||
v1.16 closes the v1.11 §35.7 forward-work item.
|
||||
|
||||
| Item | Status |
|
||||
|------|--------|
|
||||
| `rx_kbps: f64` + `tx_kbps: f64` fields on `NetInterface` | ✅ |
|
||||
| `NetInfo::read_with_throughput(prev, dt_secs)` | ✅ |
|
||||
| Wall-clock dt (shared with v1.14 + v1.15 via prev_refresh_secs) | ✅ |
|
||||
| `prev_net: NetInfo` field in App | ✅ |
|
||||
| R/W KiB/s in render_network_panel RX/TX bytes lines | ✅ |
|
||||
| 3 new unit tests (formula + underflow + zero dt) | ✅ all pass |
|
||||
| 52 total tests (5 bench + 12 sensor + 10 network + 12 storage + 13 process) | ✅ all pass |
|
||||
|
||||
**Math sanity check** (verified by unit test):
|
||||
- prev=1MB, now=5MB, dt=2sec → 1953.125 KiB/s
|
||||
- prev > now → saturating_sub → 0 (no panic)
|
||||
|
||||
**Linux host smoke test**:
|
||||
- After 7 ticks (3.5 sec): R/W KiB/s populates per interface
|
||||
- In `--once` mode: 0.0 (binary exits before second refresh)
|
||||
|
||||
**v1.16 source state**: ~5755 LoC across **19 modules** (was ~5720 in
|
||||
v1.15). 52 unit tests total.
|
||||
|
||||
Cross-compiled binary: 3.9 MB stripped Redox ELF
|
||||
(SHA256 `053f1a0cca5185637d0316d56f5cf5832cf2e754b689bc24edf16ea5d0404fa2`).
|
||||
|
||||
**Forward work** (deferred to v1.17+):
|
||||
1. **Per-process network I/O** — `/proc/[pid]/net/dev` for per-process bytes.
|
||||
2. **IPv4 addresses** — currently only IPv6.
|
||||
3. **ethtool driver stats** — driver-specific counters.
|
||||
|
||||
### 3.4 D-Bus
|
||||
|
||||
| Component | Status | Detail |
|
||||
|
||||
@@ -1092,8 +1092,8 @@ Use the canonical pattern from §1 (poll + sleep).
|
||||
| Modular crates | Single crate | Split (3-4 crates) | More granular split |
|
||||
### 13.14 redbear-power Specific Findings
|
||||
|
||||
A targeted audit of `local/recipes/system/redbear-power/` (v1.15, 5720 LoC
|
||||
across 19 modules, 49 unit tests) produced these actionable findings:
|
||||
A targeted audit of `local/recipes/system/redbear-power/` (v1.16, 5755 LoC
|
||||
across 19 modules, 52 unit tests) produced these actionable findings:
|
||||
|
||||
| Severity | Finding | Fix |
|
||||
|----------|---------|-----|
|
||||
@@ -1121,6 +1121,7 @@ across 19 modules, 49 unit tests) produced these actionable findings:
|
||||
| feature | No Process list | Implemented in v1.13 (`process.rs` module + `TabId::Process`, 9 unit tests) |
|
||||
| feature | No CPU% in Process tab | Implemented in v1.14 (`ProcInfo::read_with_cpu_pct` + 4 unit tests) |
|
||||
| feature | No disk throughput in Storage tab | Implemented in v1.15 (`StorageInfo::read_with_throughput` + 3 unit tests) |
|
||||
| feature | No network throughput in Network tab | Implemented in v1.16 (`NetInfo::read_with_throughput` + 3 unit tests) |
|
||||
|
||||
Full plan: see `local/docs/redbear-power-improvement-plan.md`.
|
||||
|
||||
@@ -1381,12 +1382,12 @@ gives a natural unit-of-work (count) that scales with thread count.
|
||||
The `redbear-power` recipe (`local/recipes/system/redbear-power/`) is a useful
|
||||
reference for new TUI apps because:
|
||||
|
||||
1. **Small enough to read in one sitting** (~5720 LoC across 19 modules, with 49 unit tests)
|
||||
1. **Small enough to read in one sitting** (~5755 LoC across 19 modules, with 52 unit tests)
|
||||
2. **Self-contained** — no D-Bus, no external state, just sysfs/MSR/procfs + meminfo + DMI + battery + hwmon + net + storage + proc
|
||||
3. **Modern ratatui 0.30 patterns** — `TableState`, modular layout, status bars, `Tabs` widget
|
||||
4. **Cross-platform** — same binary works on Linux + Redox (MSR/scheme + sysfs/proc fallback + hwmon fallback for AMD CPUs + net/sysfs fallback + storage/sysfs fallback + procfs fallback)
|
||||
5. **Well-documented** — extensive code comments + this doc + improvement plan
|
||||
6. **Testable** — bench + sensor + network + storage + process modules have 49 unit tests covering stress modes + hwmon unit conversions + multi-vendor pkg_temp_c + binary byte formatting + disk stat parsing + delta math + /proc/[pid]/stat parser with space-handling + CPU% delta math + disk throughput delta math
|
||||
6. **Testable** — bench + sensor + network + storage + process modules have 52 unit tests covering stress modes + hwmon unit conversions + multi-vendor pkg_temp_c + binary byte formatting + disk stat parsing + delta math + /proc/[pid]/stat parser with space-handling + CPU% delta math + disk throughput delta math + network throughput delta math
|
||||
|
||||
When porting a new Red Bear TUI app, structure it like redbear-power:
|
||||
|
||||
|
||||
@@ -3334,6 +3334,103 @@ case of clock reset).
|
||||
|
||||
---
|
||||
|
||||
## 40. v1.16 Network Throughput in Network Tab (2026-06-20)
|
||||
|
||||
Per the user's "v1.16 = Network throughput (Recommended)" directive,
|
||||
v1.16 closes the v1.11 §35.7 forward-work item. Network tab now
|
||||
shows real-time R/W throughput (KiB/s) per interface, computed from
|
||||
delta of rx_bytes/tx_bytes between successive 7th-tick refreshes.
|
||||
|
||||
### 40.1 What was implemented
|
||||
|
||||
**New fields `rx_kbps: f64` + `tx_kbps: f64` on `NetInterface`** —
|
||||
populated by `NetInfo::read_with_throughput(prev, dt_secs)`.
|
||||
|
||||
**New `NetInfo::read_with_throughput(prev, dt_secs)` method**:
|
||||
- Calls `read()` to get current interface stats.
|
||||
- For each interface in info, looks up the matching name in `prev`.
|
||||
- Computes `delta = now.rx_bytes - prev.rx_bytes` (saturating).
|
||||
- Normalizes: `rx_kbps = (delta / dt_secs) / 1024`.
|
||||
- Returns the populated info struct.
|
||||
|
||||
Edge cases match v1.15's `StorageInfo::read_with_throughput`:
|
||||
- `dt_secs <= 0` → all kbps = 0
|
||||
- New interface → kbps = 0 (no prev data)
|
||||
- `saturating_sub` prevents underflow
|
||||
|
||||
**Updated `app.rs`**:
|
||||
- New field `prev_net: NetInfo`.
|
||||
- 7-tick refresh block now uses `read_with_throughput`:
|
||||
```rust
|
||||
if self.refresh_counter % 7 == 0 {
|
||||
let now_secs = ...;
|
||||
let dt = ...;
|
||||
self.prev_net = std::mem::replace(
|
||||
&mut self.net,
|
||||
NetInfo::read_with_throughput(&self.prev_net, dt),
|
||||
);
|
||||
}
|
||||
```
|
||||
- Same `prev_refresh_secs` field shared with v1.14 + v1.15.
|
||||
|
||||
**Updated `render.rs`** — Network tab now shows R/W KiB/s in each
|
||||
interface's RX/TX bytes line:
|
||||
```
|
||||
RX bytes: 38.7 GiB (137M packets, 46408 drop, 12.3 KiB/s)
|
||||
TX bytes: 237.4 GiB (237M packets, 20 drop, 156.7 KiB/s)
|
||||
```
|
||||
|
||||
### 40.2 Unit tests (3 new, 52/52 total pass)
|
||||
|
||||
```rust
|
||||
#[test] fn throughput_formula_positive() // (now-prev)/dt/1024
|
||||
#[test] fn throughput_saturating_sub_underflow() // now<prev → 0
|
||||
#[test] fn throughput_zero_dt() // guard against dt=0
|
||||
```
|
||||
|
||||
```
|
||||
running 52 tests
|
||||
test bench::tests::* (5) ... ok
|
||||
test sensor::tests::* (12) ... ok
|
||||
test network::tests::* (7) ... ok
|
||||
test network::throughput_unit_tests::* (3) ... ok
|
||||
test storage::tests::* (12) ... ok
|
||||
test process::tests::* (13) ... ok
|
||||
|
||||
test result: ok. 52 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
|
||||
```
|
||||
|
||||
### 40.3 Build verification
|
||||
|
||||
| Build | Result |
|
||||
|-------|--------|
|
||||
| Linux host (`cargo build --release`) | ✅ 0 errors, 49 warnings |
|
||||
| Linux host tests (`cargo test --release`) | ✅ 52/52 pass |
|
||||
| Redox cross-compile (`cargo build --release --target=x86_64-unknown-redox`) | ✅ clean |
|
||||
| Redox binary (stripped) | 4,041,576 bytes (vs v1.15's 4,049,768 — -8 KB, dead-code elimination) |
|
||||
| Cross-compile SHA256 | `053f1a0cca5185637d0316d56f5cf5832cf2e754b689bc24edf16ea5d0404fa2` |
|
||||
|
||||
### 40.4 Throughput math sanity check
|
||||
|
||||
| prev_rx | now_rx | dt | num_cpus | rx_kbps |
|
||||
|---------|--------|----|----------|---------|
|
||||
| 1,000,000 | 5,000,000 | 2 sec | — | (4M/2/1024) = **1953.125** |
|
||||
| 5,000,000 | 1,000,000 | 2 sec | — | saturating_sub → **0** |
|
||||
|
||||
Same pattern as v1.15 disk throughput. Wall-clock dt (not tick-based)
|
||||
ensures accurate readings even if the TUI pauses.
|
||||
|
||||
### 40.5 Forward work
|
||||
|
||||
- **Per-process network I/O** — `/proc/[pid]/net/dev` shows per-process
|
||||
network bytes (Linux only). Future: link to Process tab detail view.
|
||||
- **IPv4 addresses** — currently only IPv6. IPv4 requires parsing
|
||||
`/proc/net/fib_trie` or shelling out to `ip addr`.
|
||||
- **ethtool driver stats** — driver-specific counters via
|
||||
`/sys/class/net/<iface>/{statistics,*}` beyond the standard set.
|
||||
|
||||
---
|
||||
|
||||
## See Also
|
||||
|
||||
- **`local/docs/RATATUI-APP-PATTERNS.md`** §13 — the canonical ratatui 0.30 best-practices update that this plan is derived from. Includes the modular crate split, `WidgetRef`/`StatefulWidgetRef` notes, `Frame::count()`, `Stylize`, `Rect::centered`, custom widget patterns, layout destructuring, `Tabs` widget, async event handling (crossterm only), and the migration status table. Use this as the implementation guide while this doc is the roadmap.
|
||||
|
||||
Reference in New Issue
Block a user