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 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-27 12:19:30 +03:00
1 parent 7cabc2c13d
commit 3f4dc700af
1 file changed
+27 -11
+27 -11
View File
@@ -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());
}
}