forge
Explore
Log in

Don't you dare go Hollow

A seek storm and a play loop, and the underruns they cost

Browse files at this commit

8271b5dee66c5b08815958be19b576499d92eaa4Ahmet Kaan GümüşParent: f6f8156
  • feat
    • a seek storm and a play loop, and the underruns they cost
Show full message
✨ feat(bench): a seek storm and a play loop, and the underruns they cost

The complaint is a long film jumped around in: the sound runs dry and the
picture jumps. Neither was measurable. The audio plugin counted its starved
callbacks and only whispered them on the way out, so a session could be asked
nothing while it ran; `ao_underruns` reads the same counter -- two relaxed
atomic loads, nothing added to the RT path but one store on the starved branch
-- and `PlaybackSession::audio_underruns` hands it over in device seconds. The
picture's half is `restarts`, counted where a worker is replaced, so a seek, a
clip boundary and a late-picture resync all land in one number.

Two metrics use them. `seekstorm` plays the file and seeks fifty seeded random
places, cold then warm, and reports first-frame p50/p95/max beside the
underruns each pass cost -- playing, because a paused device runs no callbacks
and can never starve. `playloop` runs the app's own pump for N seconds with a
jump every five, and reports the gap between frames (p50/p99), the underruns
and the restarts, with its own count of late-picture resyncs beside them.

Both name the decode backend in the note, as seek and scrub already do: a row
that does not say `backend HW` was measured in software.

And it would have been. `cargo build -p engine-hw --example bench` selects
example targets in every package it is given, and a cdylib is not one, so the
line that exists to build the plugin built nothing and the LD_LIBRARY_PATH
below it pointed at an empty directory. The plugins are their own build now.
crates/engine-audio/src/lib.rsmodified+40 -0
@@ -157,6 +157,11 @@ struct Shared {
157157 /// per callback on the RT thread, so it is an atomic rather than a lock.
158158 gain: AtomicU32,
159159 underruns: AtomicU64,
160+ /// Device position (samples per channel) read at the most recent underrun,
161+ /// `-1` until one happens: what says whether the count in hand is old news
162+ /// or is still growing. Written on the RT thread, and only on the starved
163+ /// path, so the ordinary callback pays nothing for it.
164+ last_underrun: AtomicI64,
160165 }
161166
162167 enum Ctl {
@@ -251,6 +256,12 @@ fn run(
251256 // that silence, so it really is elapsed time.
252257 slice[got * 4..want * 4].fill(0);
253258 shared.underruns.fetch_add(1, Ordering::Relaxed);
259+ // The position this callback is about to compute is
260+ // not known yet; the previous one is a quantum
261+ // (~23 ms) behind and needs no clock call here.
262+ shared
263+ .last_underrun
264+ .store(shared.position.load(Ordering::Relaxed), Ordering::Relaxed);
254265 }
255266 // After the fill, so the silence stays silent whatever
256267 // the gain is, and the underrun count keeps meaning
@@ -410,6 +421,7 @@ pub extern "C" fn ao_open(sample_rate: u32, channels: u32) -> *mut c_void {
410421 resumed: AtomicBool::new(false),
411422 gain: AtomicU32::new(1.0f32.to_bits()),
412423 underruns: AtomicU64::new(0),
424+ last_underrun: AtomicI64::new(-1),
413425 });
414426 let (ready_tx, ready_rx) = mpsc::channel();
415427 let (ctl_tx, ctl_rx) = mpsc::channel();
@@ -479,6 +491,34 @@ pub unsafe extern "C" fn ao_position(session: *mut c_void) -> i64 {
479491 .unwrap_or(-1)
480492 }
481493
494+/// Starved callbacks since the stream opened -- one per quantum the decoder was
495+/// late for -- and, through `last_at`, the device position the newest of them
496+/// was seen at (`-1` if there has been none). The same number the drop print
497+/// reports, asked for while the session is still running: a caller measuring a
498+/// seek reads it before and after and the difference is that seek's cost.
499+///
500+/// Two relaxed atomic loads, nothing else: the RT thread writes both and must
501+/// never wait on a reader.
502+///
503+/// # Safety
504+/// `session` must come from [`ao_open`]; `last_at` is either null or writable.
505+#[unsafe(no_mangle)]
506+pub unsafe extern "C" fn ao_underruns(session: *mut c_void, last_at: *mut i64) -> i64 {
507+ catch_unwind(AssertUnwindSafe(|| {
508+ if session.is_null() {
509+ return -1;
510+ }
511+ // SAFETY: caller-guaranteed live session.
512+ let session = unsafe { &*(session as *const Session) };
513+ if !last_at.is_null() {
514+ // SAFETY: caller-guaranteed writable, and it is a plain i64.
515+ unsafe { *last_at = session.shared.last_underrun.load(Ordering::Relaxed) };
516+ }
517+ session.shared.underruns.load(Ordering::Relaxed) as i64
518+ }))
519+ .unwrap_or(-1)
520+}
521+
482522 /// Pauses (0) or resumes (non-zero) playback. Paused freezes the position.
483523 /// 0 on success, negative on failure.
484524 ///
crates/engine/examples/bench.rsmodified+258 -2
@@ -1,5 +1,6 @@
11 //! The baseline every later decode/encode change is measured against: open,
2-//! seek, scrub and export, timed on the real library rather than on a fixture.
2+//! seek, seek storm, play loop, scrub and export, timed on the real library
3+//! rather than on a fixture.
34 //!
45 //! `cargo run --release -p engine --example bench -- <metric> <file> [args]`
56 //!
@@ -9,7 +10,10 @@
910 //! failure down as data.
1011 //!
1112 //! Every row is one TSV line -- `file, metric, unit, n, median, min, max, note`
12-//! -- so the whole baseline is `cat`ted together and diffed later.
13+//! -- so the whole baseline is `cat`ted together and diffed later. The note is
14+//! where the tail percentile and the **decode backend** live: a row that does
15+//! not say `backend hw` was measured in software, and a baseline that does not
16+//! say which is not a baseline (see `scripts/bench.sh` on `LD_LIBRARY_PATH`).
1317 //!
1418 //! **Cold and warm.** Cold means the file's pages are dropped from the page
1519 //! cache immediately before the measurement, with `posix_fadvise(DONTNEED)` on
@@ -49,6 +53,8 @@ fn main() {
4953 match metric.as_str() {
5054 "open" => open_bench(&path),
5155 "seek" => seek_bench(&path, arg_f64(args.next(), "seconds")),
56+ "seekstorm" => seekstorm_bench(&path, arg_seed(args.next())),
57+ "playloop" => playloop_bench(&path, arg_f64(args.next(), "seconds"), arg_seed(args.next())),
5258 "scrub" => scrub_bench(&path),
5359 "waveform" => waveform_bench(&path),
5460 "export" => {
@@ -63,6 +69,8 @@ fn main() {
6369 fn usage() -> ! {
6470 eprintln!(
6571 "usage: bench open <file>\n bench seek <file> <secs>\n \
72+ bench seekstorm <file> [seed]\n \
73+ bench playloop <file> <secs> [seed]\n \
6674 bench scrub <file>\n bench waveform <file>\n \
6775 bench export <file> <h264sw|h264hw|av1|hevc|hevchw> <out_dir>"
6876 );
@@ -74,6 +82,12 @@ fn arg_f64(arg: Option<String>, what: &str) -> f64 {
7482 .unwrap_or_else(|| panic!("missing {what}"))
7583 }
7684
85+/// The seed the random metrics draw their positions from: same seed, same
86+/// seeks, so a before and an after are the same measurement.
87+fn arg_seed(arg: Option<String>) -> u64 {
88+ arg.and_then(|s| s.parse().ok()).unwrap_or(1)
89+}
90+
7791 // ---------------------------------------------------------------- reporting
7892
7993 /// One TSV row: the median is what a comparison uses, the min and max are what
@@ -125,6 +139,34 @@ fn ttff_timeout() -> Duration {
125139 Duration::from_secs_f64(env_f64("BENCH_TTFF_TIMEOUT", 180.0))
126140 }
127141
142+/// The p'th percentile of `samples`, nearest rank on the sorted copy. The
143+/// median is [`row`]'s business; this is for the tail, which is the number a
144+/// dropped frame and a starved ring both live in.
145+fn pct(samples: &[f64], p: f64) -> f64 {
146+ if samples.is_empty() {
147+ return 0.0;
148+ }
149+ let mut sorted = samples.to_vec();
150+ sorted.sort_by(f64::total_cmp);
151+ sorted[((sorted.len() - 1) as f64 * p).round() as usize]
152+}
153+
154+/// A seeded LCG, so "random" seeks are the same random seeks tomorrow. Sixteen
155+/// lines of a crate would do the same thing and none of the quality a real
156+/// generator has matters to a list of positions in a film.
157+struct Lcg(u64);
158+
159+impl Lcg {
160+ /// The next position, in `0.0..1.0`.
161+ fn next(&mut self) -> f64 {
162+ self.0 = self
163+ .0
164+ .wrapping_mul(6_364_136_223_846_793_005)
165+ .wrapping_add(1_442_695_040_888_963_407);
166+ (self.0 >> 11) as f64 / (1u64 << 53) as f64
167+ }
168+}
169+
128170 fn env_f64(key: &str, default: f64) -> f64 {
129171 std::env::var(key)
130172 .ok()
@@ -250,6 +292,220 @@ fn seek_bench(path: &Path, secs: f64) {
250292 row(path, &format!("seek_ttff_{secs:.0}s"), "ms", &samples, &note);
251293 }
252294
295+// -------------------------------------------------------------- seek storm
296+
297+/// Seeks a film opens with none of: fifty positions nobody chose, drawn from a
298+/// seed so the same fifty come back tomorrow. `seek` measures one point five
299+/// times over; this measures the spread across the whole file, which is where
300+/// an index lookup, a keyframe distance and a decoder reopen all vary.
301+///
302+/// Cold is the first pass over a freshly evicted file, warm the same fifty
303+/// again straight after -- the same two questions the other metrics ask, and
304+/// the audio underruns each pass cost are counted with it
305+/// ([`engine::PlaybackSession::audio_underruns`]), because a seek that lands
306+/// fast and starves the ring is not a seek that worked.
307+const STORM_SEEKS: usize = 50;
308+
309+fn seekstorm_bench(path: &Path, seed: u64) {
310+ evict(path);
311+ let mut session = match engine::PlaybackSession::open(path) {
312+ Ok(session) => session,
313+ Err(e) => {
314+ row(path, "seekstorm_ttff_cold", "ms", &[], &format!("FAIL({e})"));
315+ return;
316+ }
317+ };
318+ // Playing throughout, because the underruns are the point: a paused device
319+ // runs no callbacks and can never starve, so a storm measured paused would
320+ // report zero however badly the seeks fed it. This is the complaint's own
321+ // shape -- a film that is playing, jumped around in.
322+ session.play();
323+ let duration = session.timeline_duration();
324+ let mut rng = Lcg(seed);
325+ // Short of the very end: a landing with no picture after it is a different
326+ // measurement (end of stream), and every seek here is meant to be one.
327+ let targets: Vec<f64> = (0..STORM_SEEKS)
328+ .map(|_| rng.next() * duration * 0.95)
329+ .collect();
330+
331+ for pass in ["cold", "warm"] {
332+ let before = session.audio_underruns().map_or(0, |(n, _)| n);
333+ let mut samples = Vec::new();
334+ let mut missed = Vec::new();
335+ let mut peak = threads();
336+ for &secs in &targets {
337+ match seek_ttff(&mut session, secs, &mut peak) {
338+ Ok(ms) => samples.push(ms),
339+ Err(why) => missed.push(why),
340+ }
341+ }
342+ let audio = session.audio_underruns();
343+ let backend = session.decode_backend().label();
344+ let mut note = format!(
345+ "backend {backend}, p95 {:.2}ms, peak {peak} threads, seed {seed}",
346+ pct(&samples, 0.95)
347+ );
348+ if !missed.is_empty() {
349+ note += &format!(", {}/{STORM_SEEKS} NO-FRAME({})", missed.len(), missed[0]);
350+ }
351+ row(path, &format!("seekstorm_ttff_{pass}"), "ms", &samples, &note);
352+ row(
353+ path,
354+ &format!("seekstorm_underruns_{pass}"),
355+ "count",
356+ &[audio.map_or(0, |(n, _)| n).saturating_sub(before) as f64],
357+ &match audio {
358+ None => "no audio device".into(),
359+ Some((total, last)) => format!(
360+ "backend {backend}, {total} since open, {}",
361+ last.map_or_else(|| "none yet".into(), |t| format!("last at {t:.1}s device"))
362+ ),
363+ },
364+ );
365+ }
366+}
367+
368+// --------------------------------------------------------------- play loop
369+
370+/// How long a picture waits between frames while the sound runs: the app's own
371+/// pump (`crates/app/src/player/transport.rs`), driven here for `secs` with a
372+/// seek to a random point every five seconds -- the shape of the complaint,
373+/// which is a film played and jumped around in rather than a seek measured on
374+/// its own.
375+///
376+/// Three numbers come out: the gap between frames (p50 and p99, the tail being
377+/// the jump a person sees), the audio underruns over the whole run, and how
378+/// many times the picture worker was restarted -- by a seek, by a clip
379+/// boundary, or by the late-picture resync, which is counted separately in the
380+/// note.
381+///
382+/// The resync rule is the app's, repeated here (`LATE_RESYNC`, `RESYNC_GAP` in
383+/// `crates/app/src/transport.rs`) because an engine example cannot depend on
384+/// the binary. Repeated only: nothing in this file changes how playback runs.
385+const PLAYLOOP_SEEK_GAP: Duration = Duration::from_secs(5);
386+const LATE_RESYNC: f64 = 0.4;
387+const RESYNC_GAP: Duration = Duration::from_secs(2);
388+
389+fn playloop_bench(path: &Path, secs: f64, seed: u64) {
390+ evict(path);
391+ let mut session = match engine::PlaybackSession::open(path) {
392+ Ok(session) => session,
393+ Err(e) => {
394+ row(path, "playloop_frame_gap", "ms", &[], &format!("FAIL({e})"));
395+ return;
396+ }
397+ };
398+ let fps = session.meta().frame_rate;
399+ let duration = session.timeline_duration();
400+ let mut rng = Lcg(seed);
401+
402+ let mut gaps = Vec::new();
403+ let mut held: Option<engine::Frame> = None;
404+ let (mut shown, mut dropped, mut seeks, mut resyncs) = (0u64, 0u64, 0u64, 0u64);
405+ let mut last_resync: Option<Instant> = None;
406+ // The first frame of the run is owed exactly as a seek's landing is.
407+ let mut owed = true;
408+
409+ session.play();
410+ let start = Instant::now();
411+ let deadline = start + Duration::from_secs_f64(secs);
412+ let mut last_frame = start;
413+ let mut next_seek = start + PLAYLOOP_SEEK_GAP;
414+ while Instant::now() < deadline {
415+ session.tick();
416+ let target = session.now() * fps;
417+ let mut newest = None;
418+ while session.is_playing() || owed {
419+ let frame = match held.take() {
420+ Some(frame) => frame,
421+ None => match session.try_frame() {
422+ // Timed here and only here: a frame taken back out of
423+ // `held` cost no decode, and counting it would report a
424+ // zero gap for a frame nobody waited for.
425+ Some(frame) => {
426+ let now = Instant::now();
427+ gaps.push((now - last_frame).as_secs_f64() * 1000.0);
428+ last_frame = now;
429+ frame
430+ }
431+ None => break,
432+ },
433+ };
434+ if f64::from(frame.index) <= target {
435+ dropped += u64::from(newest.is_some());
436+ newest = Some(frame);
437+ } else {
438+ held = Some(frame);
439+ break;
440+ }
441+ }
442+ let late = newest
443+ .as_ref()
444+ .map_or(0.0, |f| (target - f64::from(f.index)) / fps);
445+ if newest.is_some() {
446+ shown += 1;
447+ owed = false;
448+ }
449+ if !owed
450+ && session.is_playing()
451+ && late > LATE_RESYNC
452+ && last_resync.is_none_or(|t| t.elapsed() >= RESYNC_GAP)
453+ {
454+ session.resync_picture();
455+ held = None;
456+ last_resync = Some(Instant::now());
457+ resyncs += 1;
458+ }
459+ // End of stream inside a five-second stretch is the same jump early:
460+ // the loop is here to keep playing, not to stop at whatever it landed
461+ // near.
462+ if Instant::now() >= next_seek || session.is_eos() {
463+ session.seek(rng.next() * duration * 0.95);
464+ held = None;
465+ owed = true;
466+ seeks += 1;
467+ next_seek = Instant::now() + PLAYLOOP_SEEK_GAP;
468+ }
469+ std::thread::sleep(Duration::from_millis(1));
470+ }
471+ session.pause();
472+
473+ let elapsed = start.elapsed().as_secs_f64();
474+ let backend = session.decode_backend().label();
475+ let audio = session.audio_underruns();
476+ row(
477+ path,
478+ "playloop_frame_gap",
479+ "ms",
480+ &gaps,
481+ &format!(
482+ "backend {backend}, p99 {:.2}ms, {shown} shown, {dropped} dropped, \
483+ {seeks} seeks in {elapsed:.0}s, seed {seed}",
484+ pct(&gaps, 0.99)
485+ ),
486+ );
487+ row(
488+ path,
489+ "playloop_underruns",
490+ "count",
491+ &[audio.map_or(0, |(n, _)| n) as f64],
492+ &match audio {
493+ None => "no audio device".into(),
494+ Some((_, last)) => format!(
495+ "backend {backend}, {}",
496+ last.map_or_else(|| "none".into(), |t| format!("last at {t:.1}s device"))
497+ ),
498+ },
499+ );
500+ row(
501+ path,
502+ "playloop_restarts",
503+ "count",
504+ &[session.restarts() as f64],
505+ &format!("backend {backend}, {resyncs} late-picture resyncs, {seeks} seeks"),
506+ );
507+}
508+
253509 // ---------------------------------------------------------------- waveform
254510
255511 /// What a lane waits for before it has an envelope: one whole
crates/engine/src/ao.rsmodified+17 -0
@@ -20,6 +20,7 @@ struct Plugin {
2020 set_active: unsafe extern "C" fn(*mut c_void, u32) -> i32,
2121 set_volume: unsafe extern "C" fn(*mut c_void, f32) -> i32,
2222 flush: unsafe extern "C" fn(*mut c_void) -> i32,
23+ underruns: unsafe extern "C" fn(*mut c_void, *mut i64) -> i64,
2324 close: unsafe extern "C" fn(*mut c_void),
2425 // Never dropped (lives in a static), so the fn pointers above stay valid.
2526 _lib: Library,
@@ -63,6 +64,11 @@ fn load() -> Option<Plugin> {
6364 // with no sound at all, which at least says so.
6465 set_volume: *lib.get(b"ao_set_volume\0").ok()?,
6566 flush: *lib.get(b"ao_flush\0").ok()?,
67+ // Required on the same terms as the two above: the plugin
68+ // ships from this build, and a measurement that silently
69+ // reads zero underruns is worse than a run that says the
70+ // plugin is the wrong one.
71+ underruns: *lib.get(b"ao_underruns\0").ok()?,
6672 close: *lib.get(b"ao_close\0").ok()?,
6773 _lib: lib,
6874 })
@@ -143,6 +149,17 @@ impl AoSession {
143149 // SAFETY: `handle` came from `ao_open` and is still open.
144150 unsafe { (self.plugin.flush)(self.handle) == 0 }
145151 }
152+
153+ /// Starved callbacks so far, and the device position (samples per channel)
154+ /// the last of them was seen at -- `None` for a stream that has never run
155+ /// dry. Two atomic loads inside the plugin, so it is cheap enough to poll
156+ /// and it never touches the RT thread's path.
157+ pub fn underruns(&self) -> (u64, Option<i64>) {
158+ let mut last = -1i64;
159+ // SAFETY: `handle` came from `ao_open`, and `last` is a live i64 of ours.
160+ let count = unsafe { (self.plugin.underruns)(self.handle, &raw mut last) };
161+ (count.max(0) as u64, (last >= 0).then_some(last))
162+ }
146163 }
147164
148165 impl Drop for AoSession {
crates/engine/src/playback.rsmodified+31 -0
@@ -250,6 +250,12 @@ pub struct PlaybackSession {
250250 ///
251251 /// [`retire`]: PlaybackSession::retire
252252 retired: Vec<Worker>,
253+ /// Picture workers that replaced another one, i.e. every restart the
254+ /// session's first worker did not cost: a seek, a resync, a clip boundary.
255+ /// Each carries a demuxer reopen and a VA-API init, so this is what a
256+ /// playback measurement counts to say how often the picture was thrown away
257+ /// ([`restarts`](Self::restarts)).
258+ restarts: u64,
253259 clock: PlaybackClock,
254260 audio: Option<Audio>,
255261 /// Why this timeline is silent, when the file itself is not: an audio track
@@ -411,6 +417,7 @@ impl PlaybackSession {
411417 worker: stream.worker,
412418 backend: stream.backend,
413419 retired: Vec::new(),
420+ restarts: 0,
414421 clock: PlaybackClock::new(source),
415422 audio,
416423 audio_disabled,
@@ -515,6 +522,7 @@ impl PlaybackSession {
515522 worker: stream.worker,
516523 backend: stream.backend,
517524 retired: Vec::new(),
525+ restarts: 0,
518526 // The song keeps the clock, as a video's own sound does -- and wall
519527 // time keeps it on a machine with no device, where the picture
520528 // (black) still has to move at some rate.
@@ -595,6 +603,7 @@ impl PlaybackSession {
595603 worker: stream.worker,
596604 backend: stream.backend,
597605 retired: Vec::new(),
606+ restarts: 0,
598607 clock: PlaybackClock::new(ClockSource::Wall),
599608 audio: None,
600609 audio_disabled: None,
@@ -884,6 +893,7 @@ impl PlaybackSession {
884893 worker: stream.worker,
885894 backend: stream.backend,
886895 retired: Vec::new(),
896+ restarts: 0,
887897 clock: PlaybackClock::new(match audio {
888898 Some(_) => ClockSource::Audio,
889899 None => ClockSource::Wall,
@@ -1230,11 +1240,32 @@ impl PlaybackSession {
12301240 /// (plus whatever VA-API init it was inside), so a scrub reaps last seek's
12311241 /// worker on this seek and the list stays a handful long. Nothing waits.
12321242 fn retire(&mut self, replacement: Worker) {
1243+ self.restarts += 1;
12331244 self.retired
12341245 .push(std::mem::replace(&mut self.worker, replacement));
12351246 self.retired.retain(|w| !w.is_finished());
12361247 }
12371248
1249+ /// Picture restarts so far; see [`restarts`](Self::restarts). The one place
1250+ /// a worker is ever replaced counts them, so a seek, a resync and a clip
1251+ /// boundary all land here and a measurement need not guess which it saw.
1252+ #[doc(hidden)]
1253+ pub fn restarts(&self) -> u64 {
1254+ self.restarts
1255+ }
1256+
1257+ /// Starved audio callbacks since the device opened, and how far into the
1258+ /// device's own playback (seconds) the last of them was -- `None` for a
1259+ /// session with no device at all. The counter the plugin prints on drop,
1260+ /// readable while the session runs: read it either side of a seek and the
1261+ /// difference is what that seek cost the ear.
1262+ #[doc(hidden)]
1263+ pub fn audio_underruns(&self) -> Option<(u64, Option<f64>)> {
1264+ let audio = self.audio.as_ref()?;
1265+ let (count, last) = audio.ao.lock().unwrap().underruns();
1266+ Some((count, last.map(|p| p as f64 / f64::from(audio.sample_rate))))
1267+ }
1268+
12381269 /// How many threads this session still has running of its own: the decode
12391270 /// worker, every retired one that has not returned yet, and the audio
12401271 /// feeders still in the air. One for a session playing along quietly.
scripts/bench.shmodified+15 -2
@@ -19,7 +19,10 @@
1919 # before the measurement -- no root, nothing else on the machine evicted,
2020 # and advisory, so it is the optimistic end of cold.
2121 # * warm = the same call repeated straight after, cache as the cold run left it.
22-# * medians of 5 for open and seek, 20 steps for a scrub, and for export as
22+# * medians of 5 for open and seek, 50 seeded random seeks for a seek storm,
23+# $BENCH_PLAYLOOP_SECS (30) of playing with a jump every 5 s for a play
24+# loop -- both drawn from $BENCH_SEED (1), so a rerun seeks the same
25+# places -- 20 steps for a scrub, and for export as
2326 # many reps as $BENCH_EXPORT_CAP seconds leave room for (at least one,
2427 # which is then marked CAPPED if it did not finish).
2528 # * every metric runs as its own process: a decoder that panics costs one
@@ -41,7 +44,13 @@ LOG="$OUT_DIR/bench.log"
4144 # Absolute, because $CARGO_TARGET_DIR may already be one and the plugin path
4245 # below must not become "$PWD/$HOME/...".
4346 TARGET=$(realpath -m "${CARGO_TARGET_DIR:-target}")
44-cargo build --release -p engine -p engine-hw --example bench || exit 1
47+# The plugins are their own build: `--example` selects example targets in every
48+# package it is given, and a cdylib is not one, so `-p engine-hw --example
49+# bench` built no plugin at all and every run measured software while the line
50+# below said otherwise. engine-audio is here for the same reason -- the play
51+# loop's underruns come from the device, and with no plugin there is no device.
52+cargo build --release -p engine-hw -p engine-audio || exit 1
53+cargo build --release -p engine --example bench || exit 1
4554 BENCH="$TARGET/release/examples/bench"
4655 # The plugin is looked for beside the running executable, and an example binary
4756 # lives one directory below the plugin: without this, hardware decode and
@@ -98,6 +107,10 @@ for file in "${files[@]}"; do
98107 run 1800 "seek_ttff_${t}s" "$file" seek "$t"
99108 done
100109 run 3600 scrub "$file" scrub
110+ # The two random metrics: same seed both sides of a change, or the "before"
111+ # and the "after" are different seeks and the comparison means nothing.
112+ run 3600 seekstorm "$file" seekstorm "${BENCH_SEED:-1}"
113+ run 1800 playloop "$file" playloop "${BENCH_PLAYLOOP_SECS:-30}" "${BENCH_SEED:-1}"
101114 for seat in h264sw h264hw av1 hevc hevchw; do
102115 run "$export_limit" "export_fps_$seat" "$file" export "$seat" "$OUT_DIR"
103116 done