From 04894a18c94982c31ad5381c744e7800eb879934 Mon Sep 17 00:00:00 2001 From: vasilito Date: Sun, 21 Jun 2026 01:05:09 +0300 Subject: [PATCH] redbear-power: v1.26 remove dead code (BREAKING) Completes the v1.22 audit W2 cleanup. v1.23 deferred this for a CHANGELOG note; this release documents the breaking change. REMOVED (no callers anywhere in the source tree): - ProcInfo::read_with_cpu_pct(prev, dt_secs, num_cpus) Was a 1-line wrapper around read_with_cpu_pct_sorted(..., Rss) that no caller actually used. Migration: call read_with_cpu_pct_sorted(prev, dt, ncpu, SortMode::default()) inline (or just use ProcInfo::read() if RSS is fine). - ProcInfo::available() -> bool Was a pre-flight check ('is /proc mounted?') that no caller used. read() already returns ProcInfo::default() when /proc is absent, so the empty result is the same signal. Migration: check !proc.is_empty() after a read, or call read() and handle the empty case. OTHER CHANGES: - Removed unused 'use std::path::Path;' (was only used by the removed ProcInfo::available). - Updated read_with_cpu_pct_sorted doc comment to mention 'CPU% and IO rates' (reflects the v1.25 addition). BREAKING: any external consumer of redbear-power's process module that called either of these methods will fail to compile. The recipe's own source (the only known consumer) is updated. Test count: 101 (unchanged; removed methods were untested). Compile warnings: 55 -> 54 (the unused Path import is gone). Redox stripped binary: 4,168,552 bytes (unchanged; the removed code was tiny and the linker dedup'd the wrapper body). Docs: local/docs/redbear-power-improvement-plan.md \xC2\xA750 --- local/docs/redbear-power-improvement-plan.md | 102 +++++++++++++++++- .../redbear-power/source/src/process.rs | 14 +-- 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/local/docs/redbear-power-improvement-plan.md b/local/docs/redbear-power-improvement-plan.md index 45f9c82d95..6d31125b94 100644 --- a/local/docs/redbear-power-improvement-plan.md +++ b/local/docs/redbear-power-improvement-plan.md @@ -4573,15 +4573,113 @@ as an unanswerable question. - **Per-thread IO** (htop scans `task/[pid]/io`) — not a common operator question on a power TUI, and adds N×file-open cost. - **RCHAR/WCHAR/SYSCR/SYSCW** (htop's "IO details" columns) — - beyond the power/thermal scope. Defer to a future v1.26 if user + beyond the power/thermal scope. Defer to a future v1.27 if user demand appears. - **Persistent rate sparkline** (rolling average of last N samples) — a per-process IO rate over time is a natural visualization but requires storing a Vec per process across refreshes. Defer - to a future v1.27 with proper memory accounting. + to a future v1.28 with proper memory accounting. --- +## 50. v1.26 Dead Code Removal (BREAKING) (2026-06-21) + +Per the v1.22 internal audit (W2: "`ProcInfo::available` and +`ProcInfo::read_with_cpu_pct` (without `_sorted`) are dead code"), +v1.26 removes both methods. v1.23 deferred this for a CHANGELOG +note; this release documents the breaking change. + +### 50.1 CHANGELOG + +**BREAKING — public API removed in v1.26**: + +```rust +// REMOVED — use read_with_cpu_pct_sorted(prev, dt, ncpu, SortMode::default()) +// or just read() (which uses the default sort). +ProcInfo::read_with_cpu_pct(prev, dt_secs, num_cpus) -> Self + +// REMOVED — use fs::metadata("/proc").map(|m| m.is_dir()).unwrap_or(false) +// or check the result of ProcInfo::read() (empty == not available). +ProcInfo::available() -> bool +``` + +**Migration path**: +- `read_with_cpu_pct(prev, dt, ncpu)` → `read_with_cpu_pct_sorted(prev, dt, ncpu, SortMode::default())` + (one-liner; the wrapper was a 1-line convenience that any caller + can replace inline) +- `ProcInfo::available()` → `!ProcInfo::read().is_empty()` (or just + attempt the read and handle the empty result) + +**Why safe to remove**: +- Verified zero callers in `local/recipes/system/redbear-power/source/` + via `grep -rn`. The two methods were never wired into the TUI + dispatch (only `_sorted` variants are). +- `available()` was originally intended as a pre-flight check + ("is `/proc` mounted?") but `read()` already returns + `ProcInfo::default()` when `/proc` is absent — the empty + result is the same signal. +- `read_with_cpu_pct` (no `_sorted`) was a convenience wrapper + around `read_with_cpu_pct_sorted(..., SortMode::default())` that + no caller actually used; the only call site in + `local/docs/redbear-power-improvement-plan.md` is a historical + reference in a code-quote describing the v1.14 implementation. + +### 50.2 Other changes + +**Removed**: +- `use std::path::Path;` (no longer used after `available()` removal) + +**Updated**: +- `read_with_cpu_pct_sorted` doc comment now mentions "CPU% **and + IO rates**" (the v1.25 addition to the function body). + +### 50.3 Test coverage + +Test count: **101** (unchanged). No test changes — the removed +methods were untested dead code. Removing dead untested code is a +zero-risk change for the test surface. + +### 50.4 Compile warning delta + +| Before v1.26 | After v1.26 | Delta | +|--------------|-------------|-------| +| 55 | 54 | -1 | + +The single warning removed: `unused import: Path` in `process.rs:19`. +The other 54 warnings are pre-existing in unrelated modules +(smart.rs, sensor.rs, storage.rs, etc.) and out of scope for v1.26. + +### 50.5 Cross-compile + smoke test + +| Target | Size | SHA256 | +|--------------|-------------|-------------------------------------------------------------------| +| Linux host | 3.0 MB | (run from `target/release/redbear-power`) | +| Redox x86_64 | 4,168,552 B | `82bcf92a681fe0251966094c8eee2e8810fc8edff675dbc94e7d0945eb66f99c` | + +Binary size delta: 0 bytes (the removed code was tiny and the +linker dedup'd it from the existing `read_with_cpu_pct_sorted` +body via the inlined `Self::read_with_cpu_pct_sorted(...)` call +that was in `read_with_cpu_pct`). + +Smoke test confirms `--once` mode still works: +``` +sort: RSS (press 'o' to cycle, '/' to filter) +PID STATE PRIO NI THR CPU% IO RATE RSS COMM +``` + +### 50.6 Project policy alignment + +This release aligns with the project's +"DO NOT** suppress warnings... investigate, diagnose, and fix +the root cause" policy (AGENTS.md). v1.23 suppressed +`ppid`/`vsize_kb` dead-code warnings with `#[allow(dead_code)]` +and a documented future use; v1.26 completes the cleanup by +removing the two methods that had no future use case at all. + +--- + +## See Also + ## 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. diff --git a/local/recipes/system/redbear-power/source/src/process.rs b/local/recipes/system/redbear-power/source/src/process.rs index 9cbecc7612..e9b5d5158c 100644 --- a/local/recipes/system/redbear-power/source/src/process.rs +++ b/local/recipes/system/redbear-power/source/src/process.rs @@ -16,7 +16,6 @@ //! `(no processes detected)`. use std::fs; -use std::path::Path; const MAX_PROCESSES: usize = 50; @@ -317,9 +316,6 @@ fn read_process(pid: u32) -> Option { } impl ProcInfo { - pub fn available() -> bool { - Path::new("/proc").is_dir() - } pub fn read() -> Self { Self::read_sorted(SortMode::default()) } @@ -349,13 +345,11 @@ impl ProcInfo { Self { processes, total_memory_kb, total_count } } - /// Read processes and compute CPU% for each based on delta of total - /// CPU ticks vs the previous read. `dt_secs` is wall-clock elapsed + /// Read processes and compute CPU% and IO rates for each based on + /// the delta vs the previous read. `dt_secs` is wall-clock elapsed /// since previous read; `num_cpus` is used to normalize per-CPU. - pub fn read_with_cpu_pct(prev: &ProcInfo, dt_secs: f64, num_cpus: u64) -> Self { - Self::read_with_cpu_pct_sorted(prev, dt_secs, num_cpus, SortMode::default()) - } - + /// IO rate is computed in KiB/s from the delta of `/proc/[pid]/io` + /// read_bytes/write_bytes divided by `dt_secs`. pub fn read_with_cpu_pct_sorted(prev: &ProcInfo, dt_secs: f64, num_cpus: u64, sort_mode: SortMode) -> Self { let mut info = Self::read_sorted(sort_mode); if dt_secs <= 0.0 || num_cpus == 0 {