diff --git a/crates/engine/tests/audio_mix_rates.rs b/crates/engine/tests/audio_mix_rates.rs index ffcf69d..eff4e18 100644 --- a/crates/engine/tests/audio_mix_rates.rs +++ b/crates/engine/tests/audio_mix_rates.rs @@ -228,7 +228,7 @@ fn a_webm_of_a_mono_voice_and_a_stereo_bed_keeps_the_voice_to_its_end() { }, None, ); - wait(&handle, Duration::from_secs(120)).expect("webm export"); + wait(&handle, Duration::from_secs(600)).expect("webm export"); let (audio, chunks) = AudioSession::open(&*out) .expect("reopen the webm") diff --git a/crates/engine/tests/export.rs b/crates/engine/tests/export.rs index 1a4c5eb..00a6875 100644 --- a/crates/engine/tests/export.rs +++ b/crates/engine/tests/export.rs @@ -1809,41 +1809,65 @@ fn a_hardware_encoder_killed_mid_export_never_pulls_the_bar_backwards() { std::fs::remove_file(&out).unwrap(); } -/// Threads of this very process that belong to an audio pass. Every worker the -/// pass starts inherits its name from the thread that spawned it (Linux `comm` -/// is inherited), so this is the pass *and its own workers* -- which is what -/// makes it a measure of how many passes are running: two at once is twice the -/// crowd of one. -fn audio_pass_threads() -> usize { +/// The live threads of this very process, by id and name. A thread that has +/// exited is left out: a join returns once the thread's id is cleared, and its +/// `/proc` entry can outlast that by a moment (longer on a loaded machine). +fn live_threads() -> Vec<(String, String)> { std::fs::read_dir("/proc/self/task") .into_iter() .flatten() .flatten() - .filter(|thread| { - std::fs::read_to_string(thread.path().join("comm")) - .is_ok_and(|name| name.trim() == "export-audio") + .filter_map(|thread| { + let status = std::fs::read_to_string(thread.path().join("status")).ok()?; + let state = status.lines().find_map(|line| line.strip_prefix("State:"))?; + if matches!(state.trim().chars().next(), Some('Z' | 'X')) { + return None; + } + let name = std::fs::read_to_string(thread.path().join("comm")).ok()?; + Some((thread.file_name().to_string_lossy().into_owned(), name.trim().to_owned())) }) - .count() + .collect() } -/// The busiest that crowd ever gets while `export` writes this project. +/// The busiest that crowd ever gets while `export` writes this project: the +/// most threads named `export-audio` at once. Every worker the pass starts +/// without a name inherits that one (Linux `comm` is inherited), so this is the +/// pass *and its own workers* -- which is what makes it a measure of how many +/// passes are running: two at once is twice the crowd of one. A *named* worker +/// carries the inherited name too, for the moment between its creation and its +/// renaming itself, so a thread seen under any other name during the export is +/// not counted in any sample: under load that moment is long enough to catch. fn busiest_audio_pass(project: Project, meta: engine::VideoMeta, out: &Path) -> usize { let handle = engine::export::start(project, meta, out, &ExportSettings::default(), None); let started = Instant::now(); - let mut most = 0; + let mut samples: Vec> = Vec::new(); + let mut renamed = std::collections::HashSet::new(); while !handle.is_finished() { assert!( started.elapsed() < Duration::from_secs(180), "export did not finish" ); - most = most.max(audio_pass_threads()); + let mut pass = Vec::new(); + for (tid, name) in live_threads() { + match name == "export-audio" { + true => pass.push(tid), + false => { + renamed.insert(tid); + } + } + } + samples.push(pass); std::thread::sleep(Duration::from_millis(1)); } handle .result() .expect("a finished export has an outcome") .expect("the export was written"); - most + samples + .iter() + .map(|pass| pass.iter().filter(|tid| !renamed.contains(*tid)).count()) + .max() + .unwrap_or(0) } /// One audio pass at a time, across that same death. An mp4 runs the sound