oxedyne/fe2o3/fe2o3_austenite/tools/bench/wasm_bench_runner.sh
3.2 KiB, 1 run, executable
created by r1870400018:60957, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | #!/usr/bin/env bash |
| 2 | # Runs wasm_bench.mjs for both wasm engines on each doc, interleaved (Austenite |
| 3 | # then typst.ts per doc, round for round -- there is only one round per doc here |
| 4 | # since wasm_bench.mjs itself runs the warm-ups and measured runs in one long- |
| 5 | # lived process), each capped and timed exactly as the native runs are. |
| 6 | set -uo pipefail |
| 7 | |
| 8 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | # shellcheck source=lib/host.sh |
| 10 | source "$HERE/lib/host.sh" |
| 11 | |
| 12 | AUST_VENDOR="${AUST_VENDOR:?set AUST_VENDOR to the daimond austenite vendor dir}" |
| 13 | TYPST_VENDOR="${TYPST_VENDOR:?set TYPST_VENDOR to the daimond typst.ts vendor dir}" |
| 14 | WARMUPS="${WARMUPS:-1}" |
| 15 | RUNS="${RUNS:-3}" |
| 16 | FMT="${FMT:-pdf}" |
| 17 | OUT_DIR="${OUT_DIR:?set OUT_DIR}" |
| 18 | DOCS=("$@") |
| 19 | |
| 20 | if [[ ${#DOCS[@]} -eq 0 ]]; then |
| 21 | echo "usage: OUT_DIR=... AUST_VENDOR=... TYPST_VENDOR=... wasm_bench_runner.sh <doc.typ>..." >&2 |
| 22 | exit 2 |
| 23 | fi |
| 24 | |
| 25 | mkdir -p "$OUT_DIR" |
| 26 | JSONL="$OUT_DIR/wasm_runs.jsonl" |
| 27 | : > "$JSONL" |
| 28 | |
| 29 | run_engine() { |
| 30 | local doc="$1" engine="$2" vendor="$3" |
| 31 | local docname; docname="$(basename "$doc" .typ)" |
| 32 | local stdout_f time_f |
| 33 | stdout_f="$(mktemp)"; time_f="$(mktemp)" |
| 34 | |
| 35 | local load_before psi_cpu_before psi_mem_before |
| 36 | load_before="$(loadavg1)"; psi_cpu_before="$(psi_avg10 cpu)"; psi_mem_before="$(psi_avg10 memory)" |
| 37 | |
| 38 | local t0 t1 |
| 39 | t0=$(date +%s.%N) |
| 40 | systemd-run --user --scope --quiet -p MemoryMax=3G --slice=claude-rc.slice -- \ |
| 41 | /usr/bin/time -v -o "$time_f" -- \ |
| 42 | node "$HERE/wasm_bench.mjs" "--engine=$engine" "--vendor=$vendor" "--doc=$doc" \ |
| 43 | "--warmups=$WARMUPS" "--runs=$RUNS" "--fmt=$FMT" \ |
| 44 | > "$stdout_f" 2> /dev/null |
| 45 | local exit_code=$? |
| 46 | t1=$(date +%s.%N) |
| 47 | |
| 48 | local load_after psi_cpu_after psi_mem_after |
| 49 | load_after="$(loadavg1)"; psi_cpu_after="$(psi_avg10 cpu)"; psi_mem_after="$(psi_avg10 memory)" |
| 50 | |
| 51 | local rss_kb=0 |
| 52 | [[ -f "$time_f" ]] && rss_kb="$(awk -F': ' '/Maximum resident set size/{print $2}' "$time_f")" |
| 53 | [[ -z "$rss_kb" ]] && rss_kb=0 |
| 54 | |
| 55 | local inner; inner="$(tail -n1 "$stdout_f" 2>/dev/null)" |
| 56 | [[ -z "$inner" ]] && inner='{"ok":false,"error":"no stdout from wasm_bench.mjs"}' |
| 57 | |
| 58 | local flagged=false |
| 59 | if awk -v a="$load_before" -v b="$load_after" -v t="$BENCH_LOAD_THRESHOLD" \ |
| 60 | 'BEGIN{exit !(a>t || b>t)}'; then |
| 61 | flagged=true |
| 62 | fi |
| 63 | |
| 64 | jq -nc \ |
| 65 | --arg doc "$docname" --arg engine "$engine" --argjson rss_kb "${rss_kb:-0}" \ |
| 66 | --argjson exit_code "$exit_code" \ |
| 67 | --argjson load_before "$load_before" --argjson load_after "$load_after" \ |
| 68 | --argjson psi_cpu_before "$psi_cpu_before" --argjson psi_cpu_after "$psi_cpu_after" \ |
| 69 | --argjson psi_mem_before "$psi_mem_before" --argjson psi_mem_after "$psi_mem_after" \ |
| 70 | --argjson flagged_under_load "$flagged" --arg ts "$(date -u +%FT%TZ)" \ |
| 71 | --argjson inner "$inner" \ |
| 72 | '$inner * {ts:$ts, doc:$doc, engine:("wasm-"+$engine), rss_kb:$rss_kb, exit_code:$exit_code, |
| 73 | load_before:$load_before, load_after:$load_after, |
| 74 | psi_cpu_before:$psi_cpu_before, psi_cpu_after:$psi_cpu_after, |
| 75 | psi_mem_before:$psi_mem_before, psi_mem_after:$psi_mem_after, |
| 76 | flagged_under_load:$flagged_under_load}' \ |
| 77 | >> "$JSONL" |
| 78 | |
| 79 | rm -f "$stdout_f" "$time_f" |
| 80 | } |
| 81 | |
| 82 | for doc in "${DOCS[@]}"; do |
| 83 | run_engine "$doc" austenite "$AUST_VENDOR" |
| 84 | run_engine "$doc" typstts "$TYPST_VENDOR" |
| 85 | echo "[wasm_bench] $(basename "$doc" .typ): austenite + typstts done" >&2 |
| 86 | done |
| 87 | |
| 88 | echo "$JSONL" |