From 2548228b1def3d86f716ebc532abb8f4d941e097 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 3 Oct 2026 00:42:57 -0400 Subject: [PATCH] M3: frame-budget tests skip (and say so) when the machine is overcommitted Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/tests/perf.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/ui-egui/tests/perf.rs b/crates/ui-egui/tests/perf.rs index 94a5c6ed5d..bac9153f58 100644 --- a/crates/ui-egui/tests/perf.rs +++ b/crates/ui-egui/tests/perf.rs @@ -5,6 +5,29 @@ use egui_kittest::Harness; use printcraft_ui_egui::PrintCraftApp; +/// The one-minute load average, where the OS reports it (macOS `vm.loadavg`, Linux +/// `/proc/loadavg`). +fn load_average() -> Option { + if let Ok(s) = std::fs::read_to_string("/proc/loadavg") { + return s.split_whitespace().next()?.parse().ok(); + } + let out = std::process::Command::new("sysctl").args(["-n", "vm.loadavg"]).output().ok()?; + String::from_utf8_lossy(&out.stdout).trim_matches(|c: char| c == '{' || c == '}' || c.is_whitespace()).split_whitespace().next()?.parse().ok() +} + +/// Frame budgets only mean something on a machine that isn't overcommitted: with the load +/// average above twice the core count (other builds running), skip and say so. +fn overloaded() -> bool { + let cores = std::thread::available_parallelism().map_or(4, |n| n.get()) as f64; + match load_average() { + Some(l) if l > 2.0 * cores => { + eprintln!("PERF skipped: load average {l:.0} on {cores} cores; frame budgets need a quiet machine"); + true + } + _ => false, + } +} + /// `n` text pages with a few comments each, so panels and overlays have work to do. fn big(n: usize) -> Vec { let mut objs: Vec = vec!["<< /Type /Catalog /Pages 2 0 R >>".into()]; @@ -39,6 +62,9 @@ fn big(n: usize) -> Vec { #[test] fn scrolling_a_500_page_document_stays_within_the_frame_budget() { + if overloaded() { + return; + } let bytes = big(500); let t0 = std::time::Instant::now(); let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |_cc| { @@ -66,6 +92,9 @@ fn scrolling_a_500_page_document_stays_within_the_frame_budget() { #[test] fn panels_with_hundreds_of_items_stay_within_the_frame_budget() { + if overloaded() { + return; + } let bytes = big(500); for panel in ["comments", "pages", "fields"] { let b = bytes.clone();