#!/usr/bin/env bash # paint-gate.sh: the paint gate of a UI change (round 190pb, after the rollup 0.1.31 step-5 regression: a design round # gated on Thief only, and Live's Patience then drew its Channel rack +44 % and its Clip-launch arrangement +72 % # instructions a frame). Two LYNX builds, before and after, each `--paintbench` on FL Studio's Thief AND Live's Patience # (an .flp and an .als: the FL and the Live paths of every view), run alternately; per project, view and frame kind the # lowest instruction median of the runs is compared. Fails when a cell got more than GATE % dearer, or when a whole # frame's pixels changed (PIXELS=any accepts a change that was meant: a design change). Linux (the instruction counter). # Since rollup 0.1.33 step 15 (round 190sz's findings, the coordinator's decision): each run under `setarch -R` (no address-space # randomisation, which moved single columns by ~1 % between runs), every frame's count (LYNX_PAINTBENCH_FRAMES_OUT=1) and the MEAN # of a cell's frames instead of their median (the 20 playhead columns' mean spreads about half as much), the lowest of >= 3 runs # per build. A build without per-frame output (before 190sz: 0.1.32 ... step 14) gives medians only: such a cell is compared on # both sides' medians, and the table says so. Results before and after this change are not directly comparable. # # --confirm-callgrind (round 190tz, item 108): each failing instruction cell is re-checked under callgrind for both builds # (scripts/paint-callgrind.sh: that view and frame kind; LYNX's own self cost and the allocation call counts). A NOISE verdict # (own code moved <= 0.05 %, allocation calls equal: glibc's heap state) is listed as "NOISE (callgrind)" and passes; REAL GROWTH # / REAL CHANGE, pixels and missing cells stay FAIL. Needs valgrind (VG) and ~2 min per build per failing cell. # # usage: scripts/paint-gate.sh [--confirm-callgrind] [results dir] # env: # PROJECTS="thief patience" which projects (also: exoplanet, or a path to an .flp / .als / .lynx) # RUNS=3 runs per build and project (alternating before / after; at least 3) # GATE=1 % allowed per cell (perf_gate.py holds main to 5 %; a single change gets 1 %) # PIXELS=same|any whole-frame pixel hashes must match (default) or may differ # FRAMES=20 frames per measurement (LYNX_PAINTBENCH_FRAMES) # VIEWS="channel rack,..." only these views (LYNX_PAINTBENCH_VIEWS) # FL_ROOT, LIVE_DEMO as scripts/perf-gate.sh # Needs a display for the app (DISPLAY, e.g. a private Xvfb); keep the results dir on a local disk. set -u CONFIRM_CG=0; [ "${1:-}" = --confirm-callgrind ] && { CONFIRM_CG=1; shift; } [ $# -ge 2 ] || { sed -n 2,30p "$0" >&2; exit 2; } BEFORE=$1; AFTER=$2 OUT=${3:-$(cd "$(dirname "$0")/.." && pwd)/build-paintgate/$(date +%Y%m%d-%H%M%S)} mkdir -p "$OUT" || exit 2 FL_ROOT=${FL_ROOT:-"/mnt/c/Program Files/Image-Line/FL Studio 2026"} LIVE_DEMO=${LIVE_DEMO:-"/mnt/c/ProgramData/Ableton/Live 12 Trial/Resources/Core Library/Lessons/Demo Songs/Chuck Sutton - Patience (Live 12 Suite Demo).als"} PROJECTS=${PROJECTS:-"thief patience"} RUNS=${RUNS:-3}; GATE=${GATE:-1}; PIXELS=${PIXELS:-same} [ "$RUNS" -ge 3 ] || RUNS=3 NOASLR=(); setarch "$(uname -m)" -R true 2> /dev/null && NOASLR=(setarch "$(uname -m)" -R) project_file () { case $1 in thief) echo "$FL_ROOT/Data/Demo projects/Demo songs/Ookay - Thief.flp" ;; exoplanet) echo "$FL_ROOT/Data/Demo projects/Demo songs/Eric Kauffmann & NrgMind - Exoplanet.flp" ;; patience) echo "$LIVE_DEMO" ;; *) echo "$1" ;; esac } for b in "$BEFORE" "$AFTER"; do [ -x "$b" ] || { echo "paint-gate: not an executable: $b" >&2; exit 2; }; done for p in $PROJECTS; do [ -f "$(project_file "$p")" ] || { echo "paint-gate: project $p not found: $(project_file "$p")" >&2; exit 2; }; done for run in $(seq 1 "$RUNS"); do for p in $PROJECTS; do sides="before after"; [ $((run % 2)) = 0 ] && sides="after before" for side in $sides; do app=$BEFORE; [ "$side" = after ] && app=$AFTER name=$(basename "$p" | tr -c 'A-Za-z0-9\n' '_') prof=$OUT/profile-$side-$name-$run; rm -rf "$prof" # (a fresh profile: no stream cache of an earlier open) views=(); [ -n "${VIEWS:-}" ] && views=(LYNX_PAINTBENCH_VIEWS="$VIEWS") env LYNX_TEST_MODE=1 LYNX_PROFILE_DIR="$prof" XDG_CONFIG_HOME="$OUT/xdg-$side" LYNX_PAINTBENCH_FRAMES="${FRAMES:-20}" \ LYNX_PAINTBENCH_FRAMES_OUT=1 "${views[@]}" timeout 1500 "${NOASLR[@]}" "$app" --paintbench "$(project_file "$p")" "$OUT/paint-$side-$name-$run.txt" \ > "$OUT/paint-$side-$name-$run.log" 2>&1 grep -q '^result=OK' "$OUT/paint-$side-$name-$run.txt" 2> /dev/null || echo "paint-gate: $side $p run $run failed (see $OUT/paint-$side-$name-$run.log)" >&2 rm -rf "$prof" done done done python3 - "$OUT" "$GATE" "$PIXELS" <<'EOF' import glob, os, re, sys out, gate, pixels = sys.argv[1], float(sys.argv[2]), sys.argv[3] def load(side): cells, means, hashes = {}, {}, {} for f in glob.glob(os.path.join(out, f"paint-{side}-*.txt")): project = re.sub(r"^paint-" + side + r"-(.*)-\d+\.txt$", r"\1", os.path.basename(f)) for line in open(f, encoding="utf-8", errors="replace"): m = re.match(r"(.+?), (whole frame|cached frame|playhead column): .*instructions median (\d+)", line) if m: k = (project, m.group(1), m.group(2)); v = int(m.group(3)) cells[k] = min(cells.get(k, v), v) fr = re.search(r", frames((?: \d+)+)", line) # (LYNX_PAINTBENCH_FRAMES_OUT=1: the mean of the frames) if fr: vals = [int(x) for x in fr.group(1).split()] mv = sum(vals) / len(vals) means[k] = min(means.get(k, mv), mv) m = re.match(r"(.+?), whole frame: .*pixels ([0-9a-f]+)", line) if m: hashes.setdefault((project, m.group(1)), set()).add(m.group(2)) return cells, means, hashes b, bm, bh = load("before") a, am, ah = load("after") if not b or not a: print("paint-gate: no instruction counts (Linux only, and the runs must succeed)"); sys.exit(2) worst, failed, lines = -100.0, [], [] lines.append(f"| project | view | frame | before | after | change | |\n|---|---|---|---|---|---|---|") for k in sorted(b): if k not in a: failed.append(f"{k} missing after"); continue mean = k in bm and k in am # (both sides have every frame: the mean; otherwise both sides' medians) bv, av = (bm[k], am[k]) if mean else (b[k], a[k]) d = (av - bv) * 100.0 / bv; worst = max(worst, d) bad = d > gate if bad: failed.append(f"{' / '.join(k)} {d:+.2f}%") lines.append(f"| {k[0]} | {k[1]} | {k[2]} | {int(round(bv))} | {int(round(av))} | {d:+.2f}% | {'FAIL' if bad else ''}{'' if mean else ' (medians)'} |") for k in sorted(bh): same = bh[k] == ah.get(k) lines.append(f"pixels {k[0]} / {k[1]}: {'same' if same else 'CHANGED ' + ','.join(sorted(bh[k])) + ' -> ' + ','.join(sorted(ah.get(k, {'missing'})))}") if not same and pixels != "any": failed.append(f"pixels {' / '.join(k)}") lines.append(f"worst {worst:+.2f}% (gate +{gate:g} %); {'PASS' if not failed else 'FAIL: ' + '; '.join(failed)}") open(os.path.join(out, "summary-paint.md"), "w").write("\n".join(lines) + "\n") print("\n".join(lines)) sys.exit(1 if failed else 0) EOF rc=$? [ $rc = 1 ] && [ $CONFIRM_CG = 1 ] || exit $rc # --confirm-callgrind: the failing cells again under callgrind; the summary's last line is rewritten last=$(tail -1 "$OUT/summary-paint.md"); left=(); noise=() cell_re='^([^ /]+) / (.+) / (whole frame|cached frame|playhead column) [+-][0-9.]+%$' while IFS= read -r item; do [ -n "$item" ] || continue if [[ $item =~ $cell_re ]]; then name=${BASH_REMATCH[1]}; view=${BASH_REMATCH[2]}; kind=${BASH_REMATCH[3]}; proj= for p in $PROJECTS; do [ "$(basename "$p" | tr -c 'A-Za-z0-9\n' '_')" = "$name" ] && proj=$p; done case $kind in "whole frame") k=whole ;; "cached frame") k=cached ;; *) k=column ;; esac dir=$OUT/callgrind-$name-$(echo "$view" | tr -c 'A-Za-z0-9\n' '_')-$k verdict= [ -n "$proj" ] && FL_ROOT="$FL_ROOT" LIVE_DEMO="$LIVE_DEMO" "$(dirname "$0")/paint-callgrind.sh" "$BEFORE" "$AFTER" "$proj" "$view" "$k" "$dir" > "$dir.log" 2>&1 verdict=$(grep '^verdict: ' "$dir/diff.txt" 2> /dev/null | tail -1 | sed 's/^verdict: //') case $verdict in NOISE*) noise+=("NOISE (callgrind) $item: $verdict") ;; "") left+=("$item (callgrind run failed: $dir.log)") ;; *) left+=("$item: $verdict") ;; esac else left+=("$item"); fi done < <(echo "$last" | sed 's/.*FAIL: //; s/; /\n/g') worst=${last%%; FAIL: *} { for n in "${noise[@]}"; do echo "$n"; done if [ ${#left[@]} = 0 ]; then echo "$worst; PASS (callgrind: ${#noise[@]} failing cell(s) were allocator noise)" else echo "$worst; FAIL: $(IFS=';'; echo "${left[*]}" | sed 's/;/; /g')"; fi } | tee -a "$OUT/summary-paint.md" [ ${#left[@]} = 0 ]