From 3f4dc700affc726b43e228ed5bf9b847796280a5 Mon Sep 17 00:00:00 2001 From: faumaray Date: Tue, 27 Oct 2026 12:19:30 +0300 Subject: [PATCH] voelin-gpui: the meter's /proc test waits for a CPU tick instead of burning 60 ms this_process_can_be_read_on_linux burned CPU for 60 ms of wall time and asserted that some thread group used a tick (10 ms) of it. On a busy machine this thread gets less than a tick in 60 ms: with 5 busy loops on the test's core, 39 of 40 runs failed at `!threads.is_empty()`. The test now burns CPU until a second reading shows the process's tick count above the first and a thread group above its own (a 30 s deadline only ends a hang, as docs/testing/load.md asks), then asserts; 40 of 40 pass under the same recipe (taskset to one core, 5 busy loops, 40 runs). Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-gpui/src/meter.rs | 38 +++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/crates/voelin-gpui/src/meter.rs b/crates/voelin-gpui/src/meter.rs index 1fe6596..10c1775 100644 --- a/crates/voelin-gpui/src/meter.rs +++ b/crates/voelin-gpui/src/meter.rs @@ -272,16 +272,32 @@ mod tests { return; } let a = Snapshot::now().expect("/proc/self"); - // Burn a little CPU on this thread so that the process has some to show. - let started = Instant::now(); - let mut x = 0u64; - while started.elapsed() < Duration::from_millis(60) { - x = x.wrapping_mul(31).wrapping_add(7); - } - std::hint::black_box(x); - let b = Snapshot::now().expect("/proc/self"); - let (cpu, threads) = cpu_between(&a, &b); - assert!(cpu >= 0.0 && b.rss_mib() > 1.0, "{cpu} {}", b.rss_mib()); - assert!(!threads.is_empty()); + // The kernel counts a process's CPU in ticks of 10 ms, and on a busy + // machine this thread gets a tick's worth of CPU only after a long wall + // time: burn CPU until a second reading shows the process's ticks above + // the first, and in a thread group (the process's total and a thread's + // own are rounded separately). The deadline only ends a hang + // (docs/testing/load.md); it never decides the result. + let deadline = Instant::now() + Duration::from_secs(30); + let (b, cpu) = loop { + let burn = Instant::now(); + let mut x = 0u64; + while burn.elapsed() < Duration::from_millis(2) { + x = x.wrapping_mul(31).wrapping_add(7); + } + std::hint::black_box(x); + let b = Snapshot::now().expect("/proc/self"); + let (cpu, threads) = cpu_between(&a, &b); + if b.process > a.process && !threads.is_empty() { + break (b, cpu); + } + assert!( + Instant::now() < deadline, + "no CPU tick showed in 30 s: {} -> {}", + a.process, + b.process + ); + }; + assert!(cpu > 0.0 && b.rss_mib() > 1.0, "{cpu} {}", b.rss_mib()); } }