paint-gate.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env bash
  2. # paint-gate.sh: the paint gate of a UI change (round 190pb, after the rollup 0.1.31 step-5 regression: a design round
  3. # gated on Thief only, and Live's Patience then drew its Channel rack +44 % and its Clip-launch arrangement +72 %
  4. # instructions a frame). Two LYNX builds, before and after, each `--paintbench` on FL Studio's Thief AND Live's Patience
  5. # (an .flp and an .als: the FL and the Live paths of every view), run alternately; per project, view and frame kind the
  6. # lowest instruction median of the runs is compared. Fails when a cell got more than GATE % dearer, or when a whole
  7. # frame's pixels changed (PIXELS=any accepts a change that was meant: a design change). Linux (the instruction counter).
  8. # Since rollup 0.1.33 step 15 (round 190sz's findings, the coordinator's decision): each run under `setarch -R` (no address-space
  9. # randomisation, which moved single columns by ~1 % between runs), every frame's count (LYNX_PAINTBENCH_FRAMES_OUT=1) and the MEAN
  10. # of a cell's frames instead of their median (the 20 playhead columns' mean spreads about half as much), the lowest of >= 3 runs
  11. # per build. A build without per-frame output (before 190sz: 0.1.32 ... step 14) gives medians only: such a cell is compared on
  12. # both sides' medians, and the table says so. Results before and after this change are not directly comparable.
  13. #
  14. # usage: scripts/paint-gate.sh <LYNX before> <LYNX after> [results dir]
  15. # env:
  16. # PROJECTS="thief patience" which projects (also: exoplanet, or a path to an .flp / .als / .lynx)
  17. # RUNS=3 runs per build and project (alternating before / after; at least 3)
  18. # GATE=1 % allowed per cell (perf_gate.py holds main to 5 %; a single change gets 1 %)
  19. # PIXELS=same|any whole-frame pixel hashes must match (default) or may differ
  20. # FRAMES=20 frames per measurement (LYNX_PAINTBENCH_FRAMES)
  21. # VIEWS="channel rack,..." only these views (LYNX_PAINTBENCH_VIEWS)
  22. # FL_ROOT, LIVE_DEMO as scripts/perf-gate.sh
  23. # Needs a display for the app (DISPLAY, e.g. a private Xvfb); keep the results dir on a local disk.
  24. set -u
  25. [ $# -ge 2 ] || { sed -n 2,20p "$0" >&2; exit 2; }
  26. BEFORE=$1; AFTER=$2
  27. OUT=${3:-$(cd "$(dirname "$0")/.." && pwd)/build-paintgate/$(date +%Y%m%d-%H%M%S)}
  28. mkdir -p "$OUT" || exit 2
  29. FL_ROOT=${FL_ROOT:-"/mnt/c/Program Files/Image-Line/FL Studio 2026"}
  30. 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"}
  31. PROJECTS=${PROJECTS:-"thief patience"}
  32. RUNS=${RUNS:-3}; GATE=${GATE:-1}; PIXELS=${PIXELS:-same}
  33. [ "$RUNS" -ge 3 ] || RUNS=3
  34. NOASLR=(); setarch "$(uname -m)" -R true 2> /dev/null && NOASLR=(setarch "$(uname -m)" -R)
  35. project_file () {
  36. case $1 in
  37. thief) echo "$FL_ROOT/Data/Demo projects/Demo songs/Ookay - Thief.flp" ;;
  38. exoplanet) echo "$FL_ROOT/Data/Demo projects/Demo songs/Eric Kauffmann & NrgMind - Exoplanet.flp" ;;
  39. patience) echo "$LIVE_DEMO" ;;
  40. *) echo "$1" ;;
  41. esac
  42. }
  43. for b in "$BEFORE" "$AFTER"; do [ -x "$b" ] || { echo "paint-gate: not an executable: $b" >&2; exit 2; }; done
  44. for p in $PROJECTS; do [ -f "$(project_file "$p")" ] || { echo "paint-gate: project $p not found: $(project_file "$p")" >&2; exit 2; }; done
  45. for run in $(seq 1 "$RUNS"); do
  46. for p in $PROJECTS; do
  47. sides="before after"; [ $((run % 2)) = 0 ] && sides="after before"
  48. for side in $sides; do
  49. app=$BEFORE; [ "$side" = after ] && app=$AFTER
  50. name=$(basename "$p" | tr -c 'A-Za-z0-9\n' '_')
  51. prof=$OUT/profile-$side-$name-$run; rm -rf "$prof" # (a fresh profile: no stream cache of an earlier open)
  52. views=(); [ -n "${VIEWS:-}" ] && views=(LYNX_PAINTBENCH_VIEWS="$VIEWS")
  53. env LYNX_TEST_MODE=1 LYNX_PROFILE_DIR="$prof" XDG_CONFIG_HOME="$OUT/xdg-$side" LYNX_PAINTBENCH_FRAMES="${FRAMES:-20}" \
  54. LYNX_PAINTBENCH_FRAMES_OUT=1 "${views[@]}" timeout 1500 "${NOASLR[@]}" "$app" --paintbench "$(project_file "$p")" "$OUT/paint-$side-$name-$run.txt" \
  55. > "$OUT/paint-$side-$name-$run.log" 2>&1
  56. 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
  57. rm -rf "$prof"
  58. done
  59. done
  60. done
  61. python3 - "$OUT" "$GATE" "$PIXELS" <<'EOF'
  62. import glob, os, re, sys
  63. out, gate, pixels = sys.argv[1], float(sys.argv[2]), sys.argv[3]
  64. def load(side):
  65. cells, means, hashes = {}, {}, {}
  66. for f in glob.glob(os.path.join(out, f"paint-{side}-*.txt")):
  67. project = re.sub(r"^paint-" + side + r"-(.*)-\d+\.txt$", r"\1", os.path.basename(f))
  68. for line in open(f, encoding="utf-8", errors="replace"):
  69. m = re.match(r"(.+?), (whole frame|cached frame|playhead column): .*instructions median (\d+)", line)
  70. if m:
  71. k = (project, m.group(1), m.group(2)); v = int(m.group(3))
  72. cells[k] = min(cells.get(k, v), v)
  73. fr = re.search(r", frames((?: \d+)+)", line) # (LYNX_PAINTBENCH_FRAMES_OUT=1: the mean of the frames)
  74. if fr:
  75. vals = [int(x) for x in fr.group(1).split()]
  76. mv = sum(vals) / len(vals)
  77. means[k] = min(means.get(k, mv), mv)
  78. m = re.match(r"(.+?), whole frame: .*pixels ([0-9a-f]+)", line)
  79. if m:
  80. hashes.setdefault((project, m.group(1)), set()).add(m.group(2))
  81. return cells, means, hashes
  82. b, bm, bh = load("before")
  83. a, am, ah = load("after")
  84. if not b or not a:
  85. print("paint-gate: no instruction counts (Linux only, and the runs must succeed)"); sys.exit(2)
  86. worst, failed, lines = -100.0, [], []
  87. lines.append(f"| project | view | frame | before | after | change | |\n|---|---|---|---|---|---|---|")
  88. for k in sorted(b):
  89. if k not in a:
  90. failed.append(f"{k} missing after"); continue
  91. mean = k in bm and k in am # (both sides have every frame: the mean; otherwise both sides' medians)
  92. bv, av = (bm[k], am[k]) if mean else (b[k], a[k])
  93. d = (av - bv) * 100.0 / bv; worst = max(worst, d)
  94. bad = d > gate
  95. if bad: failed.append(f"{' / '.join(k)} {d:+.2f}%")
  96. 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)'} |")
  97. for k in sorted(bh):
  98. same = bh[k] == ah.get(k)
  99. lines.append(f"pixels {k[0]} / {k[1]}: {'same' if same else 'CHANGED ' + ','.join(sorted(bh[k])) + ' -> ' + ','.join(sorted(ah.get(k, {'missing'})))}")
  100. if not same and pixels != "any": failed.append(f"pixels {' / '.join(k)}")
  101. lines.append(f"worst {worst:+.2f}% (gate +{gate:g} %); {'PASS' if not failed else 'FAIL: ' + '; '.join(failed)}")
  102. open(os.path.join(out, "summary-paint.md"), "w").write("\n".join(lines) + "\n")
  103. print("\n".join(lines))
  104. sys.exit(1 if failed else 0)
  105. EOF