test: measure the cost of one boot frame
Release build, 200 units at 110x40: whole frame median 3.02 ms, of which the model projection (waiting forest + milestones) takes 2.64 ms.
This commit is contained in:
1 parent
3fbc2a7c78
commit
d3ac753fe2
3 files changed
+112
-6
No files matched your search
@@ -1,4 +1,6 @@
|
||||
#[cfg(test)]
|
||||
mod frame_cost_bench;
|
||||
#[cfg(test)]
|
||||
mod panel_render_tests;
|
||||
mod run_timeline;
|
||||
mod screen_chrome;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
use std::{
|
||||
hint::black_box,
|
||||
iter::once,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use ratatui::{Terminal, backend::TestBackend};
|
||||
|
||||
use super::{BootView, screen_render_fixtures::ryzen_origin};
|
||||
use crate::{
|
||||
boot_model::{BootState, JobResult, Phase, flatten_forest},
|
||||
demo_script::boot_test_fixtures::{MS, QueuedUnit, queued_boot, running, waiting},
|
||||
screen_settings::{color_scheme::Colors, config_file::Timing, font_glyphs::Glyphs},
|
||||
};
|
||||
|
||||
const SERVICE_COUNT: u32 = 200;
|
||||
const CHAIN_LENGTH: u32 = 5;
|
||||
const FINISHED_SERVICES: u32 = 40;
|
||||
const DRAW_COUNT: u32 = 200;
|
||||
const DRAW_SPACING: Duration = Duration::from_millis(16);
|
||||
|
||||
fn service_name(index: u32) -> String {
|
||||
format!("unit{index:03}.service")
|
||||
}
|
||||
|
||||
fn crowded_service(index: u32, names: &[String]) -> QueuedUnit {
|
||||
let earlier = (!index.is_multiple_of(CHAIN_LENGTH)).then(|| names[index as usize - 1].as_str());
|
||||
let after: Vec<&str> = earlier.into_iter().collect();
|
||||
let name = &names[index as usize];
|
||||
if index.is_multiple_of(3) {
|
||||
running(name, &after, MS * index)
|
||||
} else {
|
||||
waiting(name, &after)
|
||||
}
|
||||
}
|
||||
|
||||
fn crowded_boot() -> BootState {
|
||||
let names: Vec<String> = (0..SERVICE_COUNT).map(service_name).collect();
|
||||
let services: Vec<&str> = names.iter().map(String::as_str).collect();
|
||||
let mut state = queued_boot(
|
||||
Phase::Host,
|
||||
Duration::ZERO,
|
||||
once(waiting("crowded.target", &services))
|
||||
.chain((0..SERVICE_COUNT).map(|index| crowded_service(index, &names))),
|
||||
);
|
||||
(2..FINISHED_SERVICES + 2).for_each(|id| {
|
||||
state.finish_job(id, JobResult::Done, MS * 1500 * id);
|
||||
});
|
||||
state
|
||||
}
|
||||
|
||||
fn report_timed_draws(label: &str, mut work: impl FnMut(Duration)) {
|
||||
let mut timings: Vec<Duration> = (0..DRAW_COUNT)
|
||||
.map(|draw| {
|
||||
let started = Instant::now();
|
||||
work(Duration::from_secs(90) + DRAW_SPACING * draw);
|
||||
started.elapsed()
|
||||
})
|
||||
.collect();
|
||||
timings.sort_unstable();
|
||||
let median = timings[timings.len() / 2];
|
||||
let slowest_tenth = timings[timings.len() * 9 / 10];
|
||||
println!("{label} over {DRAW_COUNT} draws: median {median:?}, p90 {slowest_tenth:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "benchmark: cargo test --release frame_cost -- --ignored --nocapture"]
|
||||
fn frame_cost_of_a_crowded_boot() {
|
||||
let state = crowded_boot();
|
||||
let origin = ryzen_origin();
|
||||
let mut terminal = Terminal::new(TestBackend::new(110, 40)).expect("test backend");
|
||||
report_timed_draws("whole frame", |now| {
|
||||
terminal
|
||||
.draw(|frame| {
|
||||
frame.render_widget(
|
||||
BootView {
|
||||
state: &state,
|
||||
colors: &Colors::default(),
|
||||
timing: &Timing::default(),
|
||||
glyphs: &Glyphs::default(),
|
||||
now,
|
||||
origin: &origin,
|
||||
password_prompt: None,
|
||||
},
|
||||
frame.area(),
|
||||
);
|
||||
})
|
||||
.expect("draw");
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "benchmark: cargo test --release frame_cost -- --ignored --nocapture"]
|
||||
fn frame_cost_of_the_model_projection() {
|
||||
let state = crowded_boot();
|
||||
report_timed_draws("model projection", |now| {
|
||||
black_box(flatten_forest(state.waiting_forest(now)));
|
||||
black_box(state.milestones());
|
||||
});
|
||||
}
|
||||
@@ -30,12 +30,7 @@ pub fn render_prompted(
|
||||
timing: &Timing::default(),
|
||||
glyphs: &Glyphs::default(),
|
||||
now,
|
||||
origin: &BootOrigin {
|
||||
host: "ryzen".to_owned(),
|
||||
system: "NixOS 26.11".to_owned(),
|
||||
generation: "2771".to_owned(),
|
||||
kernel: "Linux 7.2.9".to_owned(),
|
||||
},
|
||||
origin: &ryzen_origin(),
|
||||
password_prompt,
|
||||
},
|
||||
frame.area(),
|
||||
@@ -45,6 +40,15 @@ pub fn render_prompted(
|
||||
terminal.backend().buffer().clone()
|
||||
}
|
||||
|
||||
pub fn ryzen_origin() -> BootOrigin {
|
||||
BootOrigin {
|
||||
host: "ryzen".to_owned(),
|
||||
system: "NixOS 26.11".to_owned(),
|
||||
generation: "2771".to_owned(),
|
||||
kernel: "Linux 7.2.9".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn screen_lines(buffer: &Buffer) -> Vec<String> {
|
||||
let area = buffer.area;
|
||||
(0..area.height)
|
||||
|
||||
Reference in new issue
Block a user