🐛 The audio-pass count skips a named worker in the moment it still wears its parent's name; the webm mix waits as long as the other exports
Browse files at this commitac0c33388fb41f9118b178d7375327bf5176c662Parent: 262bf2f2 changed files +39 -15
crates/engine/tests/audio_mix_rates.rsmodified+1 -1
| @@ -228,7 +228,7 @@ fn a_webm_of_a_mono_voice_and_a_stereo_bed_keeps_the_voice_to_its_end() { | |||
| 228 | }, | 228 | }, |
| 229 | None, | 229 | None, |
| 230 | ); | 230 | ); |
| 231 | - wait(&handle, Duration::from_secs(120)).expect("webm export"); | 231 | + wait(&handle, Duration::from_secs(600)).expect("webm export"); |
| 232 | 232 | ||
| 233 | let (audio, chunks) = AudioSession::open(&*out) | 233 | let (audio, chunks) = AudioSession::open(&*out) |
| 234 | .expect("reopen the webm") | 234 | .expect("reopen the webm") |
crates/engine/tests/export.rsmodified+38 -14
| @@ -1809,41 +1809,65 @@ fn a_hardware_encoder_killed_mid_export_never_pulls_the_bar_backwards() { | |||
| 1809 | std::fs::remove_file(&out).unwrap(); | 1809 | std::fs::remove_file(&out).unwrap(); |
| 1810 | } | 1810 | } |
| 1811 | 1811 | ||
| 1812 | -/// Threads of this very process that belong to an audio pass. Every worker the | 1812 | +/// The live threads of this very process, by id and name. A thread that has |
| 1813 | -/// pass starts inherits its name from the thread that spawned it (Linux `comm` | 1813 | +/// exited is left out: a join returns once the thread's id is cleared, and its |
| 1814 | -/// is inherited), so this is the pass *and its own workers* -- which is what | 1814 | +/// `/proc` entry can outlast that by a moment (longer on a loaded machine). |
| 1815 | -/// makes it a measure of how many passes are running: two at once is twice the | 1815 | +fn live_threads() -> Vec<(String, String)> { |
| 1816 | -/// crowd of one. | ||
| 1817 | -fn audio_pass_threads() -> usize { | ||
| 1818 | std::fs::read_dir("/proc/self/task") | 1816 | std::fs::read_dir("/proc/self/task") |
| 1819 | .into_iter() | 1817 | .into_iter() |
| 1820 | .flatten() | 1818 | .flatten() |
| 1821 | .flatten() | 1819 | .flatten() |
| 1822 | - .filter(|thread| { | 1820 | + .filter_map(|thread| { |
| 1823 | - std::fs::read_to_string(thread.path().join("comm")) | 1821 | + let status = std::fs::read_to_string(thread.path().join("status")).ok()?; |
| 1824 | - .is_ok_and(|name| name.trim() == "export-audio") | 1822 | + let state = status.lines().find_map(|line| line.strip_prefix("State:"))?; |
| 1823 | + if matches!(state.trim().chars().next(), Some('Z' | 'X')) { | ||
| 1824 | + return None; | ||
| 1825 | + } | ||
| 1826 | + let name = std::fs::read_to_string(thread.path().join("comm")).ok()?; | ||
| 1827 | + Some((thread.file_name().to_string_lossy().into_owned(), name.trim().to_owned())) | ||
| 1825 | }) | 1828 | }) |
| 1826 | - .count() | 1829 | + .collect() |
| 1827 | } | 1830 | } |
| 1828 | 1831 | ||
| 1829 | -/// The busiest that crowd ever gets while `export` writes this project. | 1832 | +/// The busiest that crowd ever gets while `export` writes this project: the |
| 1833 | +/// most threads named `export-audio` at once. Every worker the pass starts | ||
| 1834 | +/// without a name inherits that one (Linux `comm` is inherited), so this is the | ||
| 1835 | +/// pass *and its own workers* -- which is what makes it a measure of how many | ||
| 1836 | +/// passes are running: two at once is twice the crowd of one. A *named* worker | ||
| 1837 | +/// carries the inherited name too, for the moment between its creation and its | ||
| 1838 | +/// renaming itself, so a thread seen under any other name during the export is | ||
| 1839 | +/// not counted in any sample: under load that moment is long enough to catch. | ||
| 1830 | fn busiest_audio_pass(project: Project, meta: engine::VideoMeta, out: &Path) -> usize { | 1840 | fn busiest_audio_pass(project: Project, meta: engine::VideoMeta, out: &Path) -> usize { |
| 1831 | let handle = engine::export::start(project, meta, out, &ExportSettings::default(), None); | 1841 | let handle = engine::export::start(project, meta, out, &ExportSettings::default(), None); |
| 1832 | let started = Instant::now(); | 1842 | let started = Instant::now(); |
| 1833 | - let mut most = 0; | 1843 | + let mut samples: Vec<Vec<String>> = Vec::new(); |
| 1844 | + let mut renamed = std::collections::HashSet::new(); | ||
| 1834 | while !handle.is_finished() { | 1845 | while !handle.is_finished() { |
| 1835 | assert!( | 1846 | assert!( |
| 1836 | started.elapsed() < Duration::from_secs(180), | 1847 | started.elapsed() < Duration::from_secs(180), |
| 1837 | "export did not finish" | 1848 | "export did not finish" |
| 1838 | ); | 1849 | ); |
| 1839 | - most = most.max(audio_pass_threads()); | 1850 | + let mut pass = Vec::new(); |
| 1851 | + for (tid, name) in live_threads() { | ||
| 1852 | + match name == "export-audio" { | ||
| 1853 | + true => pass.push(tid), | ||
| 1854 | + false => { | ||
| 1855 | + renamed.insert(tid); | ||
| 1856 | + } | ||
| 1857 | + } | ||
| 1858 | + } | ||
| 1859 | + samples.push(pass); | ||
| 1840 | std::thread::sleep(Duration::from_millis(1)); | 1860 | std::thread::sleep(Duration::from_millis(1)); |
| 1841 | } | 1861 | } |
| 1842 | handle | 1862 | handle |
| 1843 | .result() | 1863 | .result() |
| 1844 | .expect("a finished export has an outcome") | 1864 | .expect("a finished export has an outcome") |
| 1845 | .expect("the export was written"); | 1865 | .expect("the export was written"); |
| 1846 | - most | 1866 | + samples |
| 1867 | + .iter() | ||
| 1868 | + .map(|pass| pass.iter().filter(|tid| !renamed.contains(*tid)).count()) | ||
| 1869 | + .max() | ||
| 1870 | + .unwrap_or(0) | ||
| 1847 | } | 1871 | } |
| 1848 | 1872 | ||
| 1849 | /// One audio pass at a time, across that same death. An mp4 runs the sound | 1873 | /// One audio pass at a time, across that same death. An mp4 runs the sound |