paint-gate.sh 5.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #
  9. # usage: scripts/paint-gate.sh <LYNX before> <LYNX after> [results dir]
  10. # env:
  11. # PROJECTS="thief patience" which projects (also: exoplanet, or a path to an .flp / .als / .lynx)
  12. # RUNS=2 runs per build and project (alternating before / after)
  13. # GATE=1 % allowed per cell (perf_gate.py holds main to 5 %; a single change gets 1 %)
  14. # PIXELS=same|any whole-frame pixel hashes must match (default) or may differ
  15. # FRAMES=20 frames per measurement (LYNX_PAINTBENCH_FRAMES)
  16. # VIEWS="channel rack,..." only these views (LYNX_PAINTBENCH_VIEWS)
  17. # FL_ROOT, LIVE_DEMO as scripts/perf-gate.sh
  18. # Needs a display for the app (DISPLAY, e.g. a private Xvfb); keep the results dir on a local disk.
  19. set -u
  20. [ $# -ge 2 ] || { sed -n 2,20p "$0" >&2; exit 2; }
  21. BEFORE=$1; AFTER=$2
  22. OUT=${3:-$(cd "$(dirname "$0")/.." && pwd)/build-paintgate/$(date +%Y%m%d-%H%M%S)}
  23. mkdir -p "$OUT" || exit 2
  24. FL_ROOT=${FL_ROOT:-"/mnt/c/Program Files/Image-Line/FL Studio 2026"}
  25. 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"}
  26. PROJECTS=${PROJECTS:-"thief patience"}
  27. RUNS=${RUNS:-2}; GATE=${GATE:-1}; PIXELS=${PIXELS:-same}
  28. project_file () {
  29. case $1 in
  30. thief) echo "$FL_ROOT/Data/Demo projects/Demo songs/Ookay - Thief.flp" ;;
  31. exoplanet) echo "$FL_ROOT/Data/Demo projects/Demo songs/Eric Kauffmann & NrgMind - Exoplanet.flp" ;;
  32. patience) echo "$LIVE_DEMO" ;;
  33. *) echo "$1" ;;
  34. esac
  35. }
  36. for b in "$BEFORE" "$AFTER"; do [ -x "$b" ] || { echo "paint-gate: not an executable: $b" >&2; exit 2; }; done
  37. for p in $PROJECTS; do [ -f "$(project_file "$p")" ] || { echo "paint-gate: project $p not found: $(project_file "$p")" >&2; exit 2; }; done
  38. for run in $(seq 1 "$RUNS"); do
  39. for p in $PROJECTS; do
  40. sides="before after"; [ $((run % 2)) = 0 ] && sides="after before"
  41. for side in $sides; do
  42. app=$BEFORE; [ "$side" = after ] && app=$AFTER
  43. name=$(basename "$p" | tr -c 'A-Za-z0-9\n' '_')
  44. prof=$OUT/profile-$side-$name-$run; rm -rf "$prof" # (a fresh profile: no stream cache of an earlier open)
  45. views=(); [ -n "${VIEWS:-}" ] && views=(LYNX_PAINTBENCH_VIEWS="$VIEWS")
  46. env LYNX_TEST_MODE=1 LYNX_PROFILE_DIR="$prof" XDG_CONFIG_HOME="$OUT/xdg-$side" LYNX_PAINTBENCH_FRAMES="${FRAMES:-20}" \
  47. "${views[@]}" timeout 1500 "$app" --paintbench "$(project_file "$p")" "$OUT/paint-$side-$name-$run.txt" \
  48. > "$OUT/paint-$side-$name-$run.log" 2>&1
  49. 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
  50. rm -rf "$prof"
  51. done
  52. done
  53. done
  54. python3 - "$OUT" "$GATE" "$PIXELS" <<'EOF'
  55. import glob, os, re, sys
  56. out, gate, pixels = sys.argv[1], float(sys.argv[2]), sys.argv[3]
  57. def load(side):
  58. cells, hashes = {}, {}
  59. for f in glob.glob(os.path.join(out, f"paint-{side}-*.txt")):
  60. project = re.sub(r"^paint-" + side + r"-(.*)-\d+\.txt$", r"\1", os.path.basename(f))
  61. for line in open(f, encoding="utf-8", errors="replace"):
  62. m = re.match(r"(.+?), (whole frame|cached frame|playhead column): .*instructions median (\d+)", line)
  63. if m:
  64. k = (project, m.group(1), m.group(2)); v = int(m.group(3))
  65. cells[k] = min(cells.get(k, v), v)
  66. m = re.match(r"(.+?), whole frame: .*pixels ([0-9a-f]+)", line)
  67. if m:
  68. hashes.setdefault((project, m.group(1)), set()).add(m.group(2))
  69. return cells, hashes
  70. b, bh = load("before")
  71. a, ah = load("after")
  72. if not b or not a:
  73. print("paint-gate: no instruction counts (Linux only, and the runs must succeed)"); sys.exit(2)
  74. worst, failed, lines = -100.0, [], []
  75. lines.append(f"| project | view | frame | before | after | change | |\n|---|---|---|---|---|---|---|")
  76. for k in sorted(b):
  77. if k not in a:
  78. failed.append(f"{k} missing after"); continue
  79. d = (a[k] - b[k]) * 100.0 / b[k]; worst = max(worst, d)
  80. bad = d > gate
  81. if bad: failed.append(f"{' / '.join(k)} {d:+.2f}%")
  82. lines.append(f"| {k[0]} | {k[1]} | {k[2]} | {b[k]} | {a[k]} | {d:+.2f}% | {'FAIL' if bad else ''} |")
  83. for k in sorted(bh):
  84. same = bh[k] == ah.get(k)
  85. lines.append(f"pixels {k[0]} / {k[1]}: {'same' if same else 'CHANGED ' + ','.join(sorted(bh[k])) + ' -> ' + ','.join(sorted(ah.get(k, {'missing'})))}")
  86. if not same and pixels != "any": failed.append(f"pixels {' / '.join(k)}")
  87. lines.append(f"worst {worst:+.2f}% (gate +{gate:g} %); {'PASS' if not failed else 'FAIL: ' + '; '.join(failed)}")
  88. open(os.path.join(out, "summary-paint.md"), "w").write("\n".join(lines) + "\n")
  89. print("\n".join(lines))
  90. sys.exit(1 if failed else 0)
  91. EOF