Repository Public License
1#!/bin/bash2# ORIX Convert — Packages/EngineMedia/Scripts/benchmark.sh3# Description: Runs the opt-in media benchmark, then replays each ffmpeg command the engine issued under4# /usr/bin/time -l to record wall time, CPU time and peak resident memory. Prints a Markdown table.5# Author: Simon-Pierre Boucher — contact@spboucher.ai6set -euo pipefail7export LC_ALL=C8HERE="$(cd "$(dirname "$0")/.." && pwd)"9DIR="${ORIX_MEDIA_BENCH_DIR:-/tmp/orix-media-bench}"10FFMPEG="$HERE/../../EmbeddedEngines/tools/ffmpeg"11echo "Load average before: $(/usr/sbin/sysctl -n vm.loadavg)"12(cd "$HERE" && ORIX_MEDIA_BENCH=1 ORIX_MEDIA_BENCH_DIR="$DIR" swift test --filter Benchmarks 2>&1 | tail -3)13/usr/bin/python3 -I - "$DIR" "$FFMPEG" <<'PY'14import json, subprocess, sys, re, os15d, ffmpeg = sys.argv[1], sys.argv[2]16records = json.load(open(os.path.join(d, "records.json")))17print("| Case | Encoder | Engine wall (s) | ffmpeg wall (s) | Speed (× real time) | CPU (user+sys s) | CPU % | Peak RSS (MB) | Output (MB) |")18print("|---|---|---:|---:|---:|---:|---:|---:|---:|")19for r in records:20 wall = cpu = 0.0; rss = 021 for args in r["commands"]:22 p = subprocess.run(["/usr/bin/time", "-l", ffmpeg] + args, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True, env={"SVT_LOG": "1", "PATH": "/usr/bin:/bin"})23 if p.returncode != 0:24 sys.stderr.write("replay failed for %s\n%s\n" % (r["name"], p.stderr[-600:])); sys.exit(1)25 m = re.search(r"([\d.]+) real\s+([\d.]+) user\s+([\d.]+) sys", p.stderr)26 wall += float(m.group(1)); cpu += float(m.group(2)) + float(m.group(3))27 rss = max(rss, int(re.search(r"(\d+)\s+maximum resident set size", p.stderr).group(1)))28 print("| %s | %s | %.2f | %.2f | %.1f | %.2f | %.0f | %.0f | %.1f |" % (29 r["name"], r["encoder"], r["engineWallSeconds"], wall, r["mediaSeconds"] / r["engineWallSeconds"], cpu, 100 * cpu / wall if wall else 0, rss / 1048576, r["outputBytes"] / 1048576))30PY31echo "Load average after: $(/usr/sbin/sysctl -n vm.loadavg)"32