forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB8a81f1fTahinli3 months ago767 commits

bench.sh126 lines, 5.6 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# The decode/encode baseline: runs `examples/bench` over a list of real files
3# and writes one TSV of medians. Every later codec change is compared against
4# the file this produces, so it is meant to be run twice -- before and after --
5# on an otherwise idle machine.
6#
7# scripts/bench.sh <out_dir> [file ...]
8#
9# With no files it reads them from $BENCH_LIST (one path per line, `#` comments
10# allowed), and failing that from assets/test_av.mp4. The list lives *outside*
11# this repo on purpose: what is measured here is a personal media library and
12# its file names are not this project's to record.
13#
14# Output in <out_dir>: baseline.tsv (the data) and bench.log (every run's
15# stderr, decoder panics included).
16#
17# Methodology, so a rerun means the same thing:
18# * cold = the file's pages dropped with posix_fadvise(DONTNEED) immediately
19# before the measurement -- no root, nothing else on the machine evicted,
20# and advisory, so it is the optimistic end of cold.
21# * warm = the same call repeated straight after, cache as the cold run left it.
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
26# many reps as $BENCH_EXPORT_CAP seconds leave room for (at least one,
27# which is then marked CAPPED if it did not finish).
28# * every metric runs as its own process: a decoder that panics costs one
29# row, not the run.
30# * the media files are opened read only; only <out_dir> is written to.
31set -uo pipefail
32cd "$(dirname "$0")/.."
33
34OUT_DIR=${1:-}
35if [ -z "$OUT_DIR" ]; then
36 echo "usage: scripts/bench.sh <out_dir> [file ...]" >&2
37 exit 2
38fi
39shift
40mkdir -p "$OUT_DIR"
41TSV="$OUT_DIR/baseline.tsv"
42LOG="$OUT_DIR/bench.log"
43
44# Absolute, because $CARGO_TARGET_DIR may already be one and the plugin path
45# below must not become "$PWD/$HOME/...".
46TARGET=$(realpath -m "${CARGO_TARGET_DIR:-target}")
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 (measured 2026-08-13: the film's hardware export read
51# 11.55 fps as silent software, 94.58 fps once the plugin was there).
52# engine-audio is here for the same reason -- the play loop's underruns come
53# from the device, and with no plugin there is no device.
54cargo build --release -p engine-hw -p engine-audio || exit 1
55cargo build --release -p engine --example bench || exit 1
56BENCH="$TARGET/release/examples/bench"
57[ -f "$TARGET/release/libengine_hw.so" ] || {
58 echo "no libengine_hw.so in $TARGET/release: every hardware row would be software" >&2
59 exit 1
60}
61# The plugin is looked for beside the running executable, and an example binary
62# lives one directory below the plugin: without this, hardware decode and
63# hardware encode silently fall back to software and the baseline is a lie.
64# Measured on the control file: seek to 600 s is 23 ms on the plugin and
65# 1359 ms without it, and every export seat reads "SW".
66export LD_LIBRARY_PATH="$TARGET/release${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
67
68files=("$@")
69if [ ${#files[@]} -eq 0 ] && [ -n "${BENCH_LIST:-}" ]; then
70 while IFS= read -r line; do
71 [ -z "$line" ] && continue
72 case "$line" in \#*) continue ;; esac
73 files+=("$line")
74 done <"$BENCH_LIST"
75fi
76[ ${#files[@]} -eq 0 ] && files=(assets/test_av.mp4)
77
78{
79 echo "# bench run $(date -Is)"
80 echo "# rev $(git rev-parse --short HEAD 2>/dev/null || echo '?')"
81 echo "# $(uname -sr), $(nproc) cpus, $(free -g | awk '/^Mem:/ {print $2 " GiB ram"}')"
82 echo "# caps: export ${BENCH_EXPORT_CAP:-300}s/${BENCH_EXPORT_REPS:-5} reps, ttff ${BENCH_TTFF_TIMEOUT:-180}s"
83} | tee -a "$LOG"
84printf 'file\tmetric\tunit\tn\tmedian\tmin\tmax\tnote\n' >"$TSV"
85
86# One metric, one process, one row -- even when the process dies.
87run() { # <timeout_s> <label> <file> <metric> [args...]
88 local limit=$1 label=$2 file=$3 metric=$4
89 shift 4
90 local name=${file##*/} out rc
91 echo "== $(date +%T) $metric ${*:-} $name" | tee -a "$LOG" >&2
92 out=$(timeout -k 30 "$limit" "$BENCH" "$metric" "$file" "$@" 2>>"$LOG")
93 rc=$?
94 [ -n "$out" ] && printf '%s\n' "$out" >>"$TSV"
95 if [ $rc -ne 0 ] && [ -z "$out" ]; then
96 local why="exit $rc"
97 [ $rc -eq 124 ] && why="timeout after ${limit}s"
98 [ $rc -ge 128 ] && why="signal $((rc - 128)) (panic/abort — see bench.log)"
99 printf '%s\t%s\t\t0\t\t\t\tFAIL(%s)\n' "$name" "$label" "$why" >>"$TSV"
100 fi
101}
102
103export_cap=${BENCH_EXPORT_CAP:-300}
104export_limit=$((export_cap * ${BENCH_EXPORT_REPS:-5} + 600))
105
106for file in "${files[@]}"; do
107 if [ ! -f "$file" ]; then
108 printf '%s\tMISSING\t\t0\t\t\t\tFAIL(no such file)\n' "${file##*/}" >>"$TSV"
109 continue
110 fi
111 run 3600 open "$file" open
112 for t in 30 600 5400; do
113 run 1800 "seek_ttff_${t}s" "$file" seek "$t"
114 done
115 run 3600 scrub "$file" scrub
116 # The two random metrics: same seed both sides of a change, or the "before"
117 # and the "after" are different seeks and the comparison means nothing.
118 run 3600 seekstorm "$file" seekstorm "${BENCH_SEED:-1}"
119 run 1800 playloop "$file" playloop "${BENCH_PLAYLOOP_SECS:-30}" "${BENCH_SEED:-1}"
120 for seat in h264sw h264hw av1 hevc hevchw; do
121 run "$export_limit" "export_fps_$seat" "$file" export "$seat" "$OUT_DIR"
122 done
123done
124
125echo "# done $(date -Is)" | tee -a "$LOG"
126column -t -s $'\t' "$TSV"