oxedyne/fe2o3/fe2o3_austenite/tools/bench/phase_runs.sh
4.0 KiB, 1 run, executable
created by r1870400018:66248, 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 | # The native phase table's runs: RUNS runs of `austenite --eval --timings` on each document, one |
| 3 | # process a run, each under both Austenite build-slot locks (lib/quiet_host.sh) and released, with a |
| 4 | # pause, before the next. cpu PSI avg10 and the 1-minute load are read at the start and end of |
| 5 | # each run. A run with PSI above PSI_LIMIT at either end is run once more, and a second flagged |
| 6 | # run is kept flagged. Every attempt is one JSONL line carrying the engine's own timings record, |
| 7 | # the CPU and peak resident set from /usr/bin/time -v, and the host readings; phase_table.mjs |
| 8 | # takes each run's last attempt. |
| 9 | # |
| 10 | # SCRATCH is where each run's PDF and record go: a RAM disk keeps the write phase from timing the disk |
| 11 | # (a busy disk made a 1 MB write take a second); the files are a megabyte at most. |
| 12 | # |
| 13 | # Usage: BIN=PATH/austenite OUT=FILE.jsonl [SCRATCH=DIR] [RUNS=3] phase_runs.sh <doc.typ>... |
| 14 | set -uo pipefail |
| 15 | |
| 16 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 17 | # shellcheck source=lib/host.sh |
| 18 | source "$HERE/lib/host.sh" |
| 19 | # shellcheck source=lib/quiet_host.sh |
| 20 | source "$HERE/lib/quiet_host.sh" |
| 21 | |
| 22 | BIN="${BIN:?set BIN to the austenite binary}" |
| 23 | OUT="${OUT:?set OUT to the JSONL file}" |
| 24 | RUNS="${RUNS:-3}" |
| 25 | PSI_LIMIT="${PSI_LIMIT:-20}" |
| 26 | GAP_S="${GAP_S:-12}" # longer than the slot helper's poll, so a waiting build gets in |
| 27 | SCRATCH="${SCRATCH:-$(mktemp -d)}" |
| 28 | mkdir -p "$(dirname "$OUT")" "$SCRATCH" |
| 29 | |
| 30 | # One attempt, inside the lock-holding subshell. Globals: S_DOC, S_RUN, S_ATTEMPT. |
| 31 | body() { |
| 32 | local name time_f rec_f out_d |
| 33 | name="$(basename "$S_DOC" .typ)" |
| 34 | time_f="$SCRATCH/$name.time"; rec_f="$SCRATCH/$name.json"; out_d="$SCRATCH/$name.out" |
| 35 | local load_before psi_before load_after psi_after io_before io_after |
| 36 | load_before="$(loadavg1)"; psi_before="$(psi_avg10 cpu)"; io_before="$(psi_avg10 io)" |
| 37 | systemd-run --user --scope --quiet -p MemoryMax=3G --slice=claude-rc.slice -- \ |
| 38 | /usr/bin/time -v -o "$time_f" -- \ |
| 39 | "$BIN" --eval --timings "$rec_f" "$S_DOC" "$out_d" > /dev/null 2> "$SCRATCH/$name.err" |
| 40 | local exit_code=$? |
| 41 | load_after="$(loadavg1)"; psi_after="$(psi_avg10 cpu)"; io_after="$(psi_avg10 io)" |
| 42 | local user_s sys_s rss_kb wall_s |
| 43 | user_s="$(awk -F': ' '/User time/{print $2}' "$time_f")" |
| 44 | sys_s="$(awk -F': ' '/System time/{print $2}' "$time_f")" |
| 45 | rss_kb="$(awk -F': ' '/Maximum resident set size/{print $2}' "$time_f")" |
| 46 | wall_s="$(awk -F': ' '/Elapsed/{n=split($2,a,":"); s=0; for(i=1;i<=n;i++) s=s*60+a[i]; print s}' "$time_f")" |
| 47 | local rec='null' |
| 48 | [[ -s "$rec_f" ]] && rec="$(cat "$rec_f")" |
| 49 | local flagged=false |
| 50 | if awk -v a="$psi_before" -v b="$psi_after" -v t="$PSI_LIMIT" 'BEGIN{exit !(a>t || b>t)}'; then |
| 51 | flagged=true |
| 52 | fi |
| 53 | jq -nc \ |
| 54 | --arg doc "$name" --arg sha "$(sha256sum "$S_DOC" | awk '{print $1}')" \ |
| 55 | --argjson run "$S_RUN" --argjson attempt "$S_ATTEMPT" --argjson exit_code "$exit_code" \ |
| 56 | --argjson user_s "${user_s:-0}" --argjson sys_s "${sys_s:-0}" --argjson rss_kb "${rss_kb:-0}" \ |
| 57 | --argjson wall_s "${wall_s:-0}" \ |
| 58 | --argjson load_before "$load_before" --argjson load_after "$load_after" \ |
| 59 | --argjson psi_before "$psi_before" --argjson psi_after "$psi_after" \ |
| 60 | --argjson io_before "$io_before" --argjson io_after "$io_after" \ |
| 61 | --argjson flagged "$flagged" --argjson timings "$rec" --arg ts "$(date -u +%FT%TZ)" \ |
| 62 | '{ts:$ts, doc:$doc, doc_sha256:$sha, run:$run, attempt:$attempt, exit_code:$exit_code, |
| 63 | user_s:$user_s, sys_s:$sys_s, wall_s:$wall_s, rss_kb:$rss_kb, |
| 64 | load_before:$load_before, load_after:$load_after, psi_before:$psi_before, |
| 65 | psi_after:$psi_after, io_before:$io_before, io_after:$io_after, flagged:$flagged, timings:$timings}' >> "$OUT" |
| 66 | [[ "$flagged" == true ]] && return 3 |
| 67 | return 0 |
| 68 | } |
| 69 | |
| 70 | for S_DOC in "$@"; do |
| 71 | for ((S_RUN = 1; S_RUN <= RUNS; S_RUN++)); do |
| 72 | S_ATTEMPT=1 |
| 73 | while :; do |
| 74 | with_quiet_host body |
| 75 | rc=$? |
| 76 | echo "[phases] $(basename "$S_DOC") run $S_RUN attempt $S_ATTEMPT: $(tail -n1 "$OUT" | jq -c '{exit_code,wall_s,psi_before,psi_after,flagged}')" >&2 |
| 77 | if [[ $rc -eq 3 && $S_ATTEMPT -lt 2 ]]; then |
| 78 | S_ATTEMPT=$((S_ATTEMPT + 1)); sleep "$GAP_S"; continue |
| 79 | fi |
| 80 | break |
| 81 | done |
| 82 | sleep "$GAP_S" |
| 83 | done |
| 84 | done |
| 85 | echo "$OUT" |