use ponko::*;
fn perf_keys(ctx: &mut Ctx) {
if ctx.key_pressed(Key::F3) {
let on = !ctx.perf_hud();
ctx.set_perf_hud(on);
}
if ctx.key_pressed(Key::F4) {
ctx.record_trace("trace.json", 300);
}
let stats = ctx.frame_stats();
if stats.frames > 0 && stats.p99_ms > 20.0 && ctx.frame().is_multiple_of(600) {
let gpu_bound = stats.display_wait_ms > stats.systems_ms;
println!(
"slow: p99 {:.1} ms, gpu {:?} ms, gpu bound: {gpu_bound}",
stats.p99_ms, stats.gpu_ms
);
for pass in ctx.gpu_passes() {
println!(" {}: {:.2} ms", pass.name, pass.ms);
}
}
}
#[test]
fn headless_runs_have_no_frame_stats() {
Game::new("t", 1, 1).system(perf_keys).run_headless(10, |ctx| {
assert_eq!(ctx.frame_stats().frames, 0);
assert!(ctx.gpu_passes().is_empty());
ctx.set_perf_hud(true);
assert!(ctx.perf_hud());
ctx.record_trace("never-written.json", 10); });
assert!(!std::path::Path::new("never-written.json").exists());
}