forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBcb2833fTahinli3 months ago342 commits

bench.sh107 lines, 4.4 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, 20 steps for a scrub, and for export as
23# many reps as $BENCH_EXPORT_CAP seconds leave room for (at least one,
24# which is then marked CAPPED if it did not finish).
25# * every metric runs as its own process: a decoder that panics costs one
26# row, not the run.
27# * the media files are opened read only; only <out_dir> is written to.
28set -uo pipefail
29cd "$(dirname "$0")/.."
30
31OUT_DIR=${1:-}
32if [ -z "$OUT_DIR" ]; then
33 echo "usage: scripts/bench.sh <out_dir> [file ...]" >&2
34 exit 2
35fi
36shift
37mkdir -p "$OUT_DIR"
38TSV="$OUT_DIR/baseline.tsv"
39LOG="$OUT_DIR/bench.log"
40
41# Absolute, because $CARGO_TARGET_DIR may already be one and the plugin path
42# below must not become "$PWD/$HOME/...".
43TARGET=$(realpath -m "${CARGO_TARGET_DIR:-target}")
44cargo build --release -p engine -p engine-hw --example bench || exit 1
45BENCH="$TARGET/release/examples/bench"
46# The plugin is looked for beside the running executable, and an example binary
47# lives one directory below the plugin: without this, hardware decode and
48# hardware encode silently fall back to software and the baseline is a lie.
49# Measured on the control file: seek to 600 s is 23 ms on the plugin and
50# 1359 ms without it, and every export seat reads "SW".
51export LD_LIBRARY_PATH="$TARGET/release${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
52
53files=("$@")
54if [ ${#files[@]} -eq 0 ] && [ -n "${BENCH_LIST:-}" ]; then
55 while IFS= read -r line; do
56 [ -z "$line" ] && continue
57 case "$line" in \#*) continue ;; esac
58 files+=("$line")
59 done <"$BENCH_LIST"
60fi
61[ ${#files[@]} -eq 0 ] && files=(assets/test_av.mp4)
62
63{
64 echo "# bench run $(date -Is)"
65 echo "# rev $(git rev-parse --short HEAD 2>/dev/null || echo '?')"
66 echo "# $(uname -sr), $(nproc) cpus, $(free -g | awk '/^Mem:/ {print $2 " GiB ram"}')"
67 echo "# caps: export ${BENCH_EXPORT_CAP:-300}s/${BENCH_EXPORT_REPS:-5} reps, ttff ${BENCH_TTFF_TIMEOUT:-180}s"
68} | tee -a "$LOG"
69printf 'file\tmetric\tunit\tn\tmedian\tmin\tmax\tnote\n' >"$TSV"
70
71# One metric, one process, one row -- even when the process dies.
72run() { # <timeout_s> <label> <file> <metric> [args...]
73 local limit=$1 label=$2 file=$3 metric=$4
74 shift 4
75 local name=${file##*/} out rc
76 echo "== $(date +%T) $metric ${*:-} $name" | tee -a "$LOG" >&2
77 out=$(timeout -k 30 "$limit" "$BENCH" "$metric" "$file" "$@" 2>>"$LOG")
78 rc=$?
79 [ -n "$out" ] && printf '%s\n' "$out" >>"$TSV"
80 if [ $rc -ne 0 ] && [ -z "$out" ]; then
81 local why="exit $rc"
82 [ $rc -eq 124 ] && why="timeout after ${limit}s"
83 [ $rc -ge 128 ] && why="signal $((rc - 128)) (panic/abort — see bench.log)"
84 printf '%s\t%s\t\t0\t\t\t\tFAIL(%s)\n' "$name" "$label" "$why" >>"$TSV"
85 fi
86}
87
88export_cap=${BENCH_EXPORT_CAP:-300}
89export_limit=$((export_cap * ${BENCH_EXPORT_REPS:-5} + 600))
90
91for file in "${files[@]}"; do
92 if [ ! -f "$file" ]; then
93 printf '%s\tMISSING\t\t0\t\t\t\tFAIL(no such file)\n' "${file##*/}" >>"$TSV"
94 continue
95 fi
96 run 3600 open "$file" open
97 for t in 30 600 5400; do
98 run 1800 "seek_ttff_${t}s" "$file" seek "$t"
99 done
100 run 3600 scrub "$file" scrub
101 for seat in h264sw h264hw av1 hevc; do
102 run "$export_limit" "export_fps_$seat" "$file" export "$seat" "$OUT_DIR"
103 done
104done
105
106echo "# done $(date -Is)" | tee -a "$LOG"
107column -t -s $'\t' "$TSV"