mirror of
https://github.com/storytold/filmcraft.git
synced 2026-10-24 01:58:19 -06:00
* Tests: one integration-test binary per crate Each crate with several tests/*.rs files keeps them as modules of tests/it/, so cargo links one test executable per crate instead of one per file. Files that change process-wide state or time a workload stay binaries of their own. * Profiles: line tables for workspace crates, no debug info for dependencies * Windows ARM64: nightly and on release pushes instead of every push to main * xtask ci: clippy and tests in the dev profile The release profile's thin LTO and single codegen unit made linking the test binaries take most of the gate. The codec and audio crates stay at opt-level 3 in the dev profile, so their tests run at release speed. * xtask ci: nextest, doctests, no examples, one wasm check Tests run with cargo nextest when it is installed (cargo test otherwise) and build with --lib --bins --tests, so examples aren't linked; doctests run separately. The wasm check keeps going past the first failing crate. VP8 fixture generation locks across processes, since nextest runs each test in its own. * VP9 synthetic fixtures: write aside and rename A test in another process could read a fixture ffmpeg was still writing. * Fuzz tests: a third of each sweep by default, all of it with FILMCRAFT_FUZZ_ITERS Every seed, mutation kind and thread count still runs. Header bytes each get one overwrite value and two bit flips in rotation, so every value and bit index still occurs across the region. FILMCRAFT_FUZZ_ITERS=N runs the whole sweep plus N random rounds per seed, as before. * Platform fallback tests: one failure point per hybrid path The failure-anywhere test injected a failure at four points around every restart point; the hybrid's paths differ only in the first GOP, around the second and last restart points, at the end and never. The replay test needs the first two GOPs. * Export tests: shorter ranges with the same checks The bitrate test measures 0.5–1.5 s, where each preset reaches its own target (on 0–3 s the simple demo left two presets at the same rate). The every-preset test exports three frames per preset. * Audio tests: effects in parallel, a table-driven FFT for the Opus quality metric The extreme-settings test keeps both settings and the 40 s tail for every effect, one thread each. The Opus quality metric's FFT builds its twiddles once and allocates nothing per transform (same algorithm and summation order). * CI: dev-profile gate with nextest xtask ci no longer builds with --release, so the release-profile overrides go; nextest is installed for the test step. * CI: apt packages through the cached install-apt-packages action * Review fixes: fuzz tests with a panic hook in their own binaries, loud fixture lock The fuzz tests of av1, h264, hevc, mpeg2v, vp8 and vp9 count panics through a process-wide hook, so a panic in another test of the same process would fail them; they are binaries of their own again. The VP8 fixture lock fails the test instead of skipping it silently, and the full-sweep doc comments say how many truncation points the full run samples. * Fuzz tests: rotate the default subset per run (FILMCRAFT_FUZZ_SEED replays one) * platform tests: decode-switch tests in their own binaries, one NVENC lock
129 lines
5.2 KiB
Rust
129 lines
5.2 KiB
Rust
//! Decode throughput and per-stage breakdown (ignored; run with
|
|
//! `cargo test --release -p filmcraft-av1 --test it perf:: -- --ignored --nocapture`).
|
|
//!
|
|
//! The machine may be busy (other builds), so single-threaded work is also measured with the
|
|
//! thread CPU clock, which is robust to load; wall-clock figures are printed next to the load
|
|
//! average.
|
|
|
|
use crate::common;
|
|
use common::*;
|
|
use filmcraft_av1::{DecodeStats, Decoder, Stage};
|
|
use std::time::Instant;
|
|
|
|
fn thread_cpu_secs() -> Option<f64> {
|
|
#[cfg(unix)]
|
|
{
|
|
let t = rustix::time::clock_gettime(rustix::time::ClockId::ThreadCPUTime);
|
|
Some(t.tv_sec as f64 + t.tv_nsec as f64 * 1e-9)
|
|
}
|
|
#[cfg(not(unix))]
|
|
{
|
|
None
|
|
}
|
|
}
|
|
|
|
fn load_average() -> String {
|
|
let out = std::process::Command::new("sysctl").args(["-n", "vm.loadavg"]).output().ok();
|
|
if let Some(o) = out.filter(|o| o.status.success()) {
|
|
return String::from_utf8_lossy(&o.stdout).trim().trim_matches(|c| c == '{' || c == '}').trim().to_string();
|
|
}
|
|
std::fs::read_to_string("/proc/loadavg").map(|s| s.split_whitespace().take(3).collect::<Vec<_>>().join(" ")).unwrap_or_else(|_| "?".into())
|
|
}
|
|
|
|
struct Run {
|
|
wall: f64,
|
|
cpu: Option<f64>,
|
|
shown: usize,
|
|
stats: DecodeStats,
|
|
}
|
|
|
|
fn run(frames: &[Vec<u8>], threads: usize) -> Run {
|
|
let mut dec = Decoder::with_threads(threads);
|
|
let t = Instant::now();
|
|
let c0 = thread_cpu_secs();
|
|
let mut shown = 0;
|
|
for f in frames {
|
|
shown += dec.decode(f).unwrap().len();
|
|
}
|
|
shown += dec.flush().len();
|
|
let cpu = c0.and_then(|c0| thread_cpu_secs().map(|c1| c1 - c0));
|
|
Run { wall: t.elapsed().as_secs_f64(), cpu, shown, stats: dec.stats() }
|
|
}
|
|
|
|
fn bench(spec: &Spec) {
|
|
// AV1_PERF_ONLY=<substring>[,<substring>...] limits the run to matching fixtures.
|
|
if std::env::var("AV1_PERF_ONLY").is_ok_and(|f| !f.split(',').any(|f| spec.name.contains(f))) {
|
|
return;
|
|
}
|
|
let Some(ff) = ffmpeg() else { return };
|
|
let path = make(&ff, spec);
|
|
let frames = ivf_frames(&path);
|
|
// Single-threaded: best of 3 by thread CPU time (falls back to wall time).
|
|
let mut best: Option<Run> = None;
|
|
for _ in 0..3 {
|
|
let r = run(&frames, 1);
|
|
let key = |r: &Run| r.cpu.unwrap_or(r.wall);
|
|
if best.as_ref().is_none_or(|b| key(&r) < key(b)) {
|
|
best = Some(r);
|
|
}
|
|
}
|
|
let b = best.unwrap();
|
|
let cpu_fps = b.cpu.map(|c| format!("{:6.1}", b.shown as f64 / c)).unwrap_or_else(|| " ?".into());
|
|
println!(
|
|
"{:<26} {:>3} shown {:>3} decoded {:>3} tiles/frame | 1 thread: {} fps (thread CPU) {:6.1} fps (wall)",
|
|
spec.name,
|
|
b.shown,
|
|
b.stats.frames,
|
|
b.stats.tiles / b.stats.frames.max(1),
|
|
cpu_fps,
|
|
b.shown as f64 / b.wall
|
|
);
|
|
println!("{}", stage_line(" ms/frame:", &b.stats));
|
|
// All cores: best of 3 by wall time.
|
|
let threads = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
|
|
let mut best: Option<Run> = None;
|
|
for _ in 0..3 {
|
|
let r = run(&frames, threads);
|
|
assert_eq!(r.shown, b.shown);
|
|
if best.as_ref().is_none_or(|b| r.wall < b.wall) {
|
|
best = Some(r);
|
|
}
|
|
}
|
|
let m = best.unwrap();
|
|
println!(" {threads} threads: {:6.1} fps (wall, load average {})", b.shown as f64 / m.wall, load_average());
|
|
// Per-stage wall time on the frame workers (stages of different frames overlap).
|
|
println!("{}", stage_line(&format!(" {threads} threads, ms/frame:"), &m.stats));
|
|
}
|
|
|
|
/// Per-stage milliseconds per frame and share of the total.
|
|
fn stage_line(label: &str, stats: &DecodeStats) -> String {
|
|
let n = stats.frames.max(1) as f64;
|
|
let total = stats.total_secs();
|
|
let mut line = String::from(label);
|
|
for s in Stage::ALL {
|
|
let v = stats.secs(s);
|
|
if v > 0.0005 {
|
|
line += &format!(" {} {:.2} ({:.0}%)", s.name(), 1e3 * v / n, 100.0 * v / total);
|
|
}
|
|
}
|
|
line
|
|
}
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn decode_throughput() {
|
|
let p = |crf: &'static str, params: &'static str| -> Vec<&'static str> { vec!["-preset", "8", "-crf", crf, "-svtav1-params", params] };
|
|
let src = "testsrc2=s=1920x1080:r=25,noise=alls=6:allf=t";
|
|
bench(&Spec::new("perf_1080p_intra", src, 10, "yuv420p", &p("30", "keyint=1")));
|
|
bench(&Spec::new("perf_1080p_gop", src, 60, "yuv420p", &p("30", "keyint=60")));
|
|
bench(&Spec::new("perf_1080p_gop_10bit", src, 60, "yuv420p10le", &p("30", "keyint=60")));
|
|
// Higher quality (more coefficients, finer partitions) and a multi-tile stream (4x2 tiles).
|
|
bench(&Spec::new("perf_1080p_gop_hq", src, 60, "yuv420p", &p("18", "keyint=60")));
|
|
bench(&Spec::new("perf_1080p_gop_tiles", src, 60, "yuv420p", &p("30", "keyint=60:tile-columns=2:tile-rows=1")));
|
|
// Low delay (each frame references the previous one, as screen and camera recorders encode):
|
|
// frames cannot overlap, so a frame's own parallelism decides the speed.
|
|
bench(&Spec::new("perf_1080p_lowdelay", src, 60, "yuv420p", &p("30", "keyint=60:pred-struct=1")));
|
|
// One tile at 2160p: the post-filters' row bands are most of the parallelism there.
|
|
bench(&Spec::new("perf_2160p_gop", "testsrc2=s=3840x2160:r=25,noise=alls=6:allf=t", 30, "yuv420p", &p("30", "keyint=30")));
|
|
}
|