forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBdd2001cTahinli3 months ago405 commits

bench.sh120 lines, 5.3 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. 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.
52cargo build --release -p engine-hw -p engine-audio || exit 1
53cargo build --release -p engine --example bench || exit 1
54BENCH="$TARGET/release/examples/bench"
55# The plugin is looked for beside the running executable, and an example binary
56# lives one directory below the plugin: without this, hardware decode and
57# hardware encode silently fall back to software and the baseline is a lie.
58# Measured on the control file: seek to 600 s is 23 ms on the plugin and
59# 1359 ms without it, and every export seat reads "SW".
60export LD_LIBRARY_PATH="$TARGET/release${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
61
62files=("$@")
63if [ ${#files[@]} -eq 0 ] && [ -n "${BENCH_LIST:-}" ]; then
64 while IFS= read -r line; do
65 [ -z "$line" ] && continue
66 case "$line" in \#*) continue ;; esac
67 files+=("$line")
68 done <"$BENCH_LIST"
69fi
70[ ${#files[@]} -eq 0 ] && files=(assets/test_av.mp4)
71
72{
73 echo "# bench run $(date -Is)"
74 echo "# rev $(git rev-parse --short HEAD 2>/dev/null || echo '?')"
75 echo "# $(uname -sr), $(nproc) cpus, $(free -g | awk '/^Mem:/ {print $2 " GiB ram"}')"
76 echo "# caps: export ${BENCH_EXPORT_CAP:-300}s/${BENCH_EXPORT_REPS:-5} reps, ttff ${BENCH_TTFF_TIMEOUT:-180}s"
77} | tee -a "$LOG"
78printf 'file\tmetric\tunit\tn\tmedian\tmin\tmax\tnote\n' >"$TSV"
79
80# One metric, one process, one row -- even when the process dies.
81run() { # <timeout_s> <label> <file> <metric> [args...]
82 local limit=$1 label=$2 file=$3 metric=$4
83 shift 4
84 local name=${file##*/} out rc
85 echo "== $(date +%T) $metric ${*:-} $name" | tee -a "$LOG" >&2
86 out=$(timeout -k 30 "$limit" "$BENCH" "$metric" "$file" "$@" 2>>"$LOG")
87 rc=$?
88 [ -n "$out" ] && printf '%s\n' "$out" >>"$TSV"
89 if [ $rc -ne 0 ] && [ -z "$out" ]; then
90 local why="exit $rc"
91 [ $rc -eq 124 ] && why="timeout after ${limit}s"
92 [ $rc -ge 128 ] && why="signal $((rc - 128)) (panic/abort — see bench.log)"
93 printf '%s\t%s\t\t0\t\t\t\tFAIL(%s)\n' "$name" "$label" "$why" >>"$TSV"
94 fi
95}
96
97export_cap=${BENCH_EXPORT_CAP:-300}
98export_limit=$((export_cap * ${BENCH_EXPORT_REPS:-5} + 600))
99
100for file in "${files[@]}"; do
101 if [ ! -f "$file" ]; then
102 printf '%s\tMISSING\t\t0\t\t\t\tFAIL(no such file)\n' "${file##*/}" >>"$TSV"
103 continue
104 fi
105 run 3600 open "$file" open
106 for t in 30 600 5400; do
107 run 1800 "seek_ttff_${t}s" "$file" seek "$t"
108 done
109 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}"
114 for seat in h264sw h264hw av1 hevc hevchw; do
115 run "$export_limit" "export_fps_$seat" "$file" export "$seat" "$OUT_DIR"
116 done
117done
118
119echo "# done $(date -Is)" | tee -a "$LOG"
120column -t -s $'\t' "$TSV"