paint-gate.sh 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. # --confirm-callgrind (round 190tz, item 108): each failing instruction cell is re-checked under callgrind for both builds
  15. # (scripts/paint-callgrind.sh: that view and frame kind; LYNX's own self cost and the allocation call counts). A NOISE verdict
  16. # (own code moved <= 0.05 %, allocation calls equal: glibc's heap state) is listed as "NOISE (callgrind)" and passes; REAL GROWTH
  17. # / REAL CHANGE, pixels and missing cells stay FAIL. Needs valgrind (VG) and ~2 min per build per failing cell.
  18. #
  19. # usage: scripts/paint-gate.sh [--confirm-callgrind] <LYNX before> <LYNX after> [results dir]
  20. # env:
  21. # PROJECTS="thief patience" which projects (also: exoplanet, or a path to an .flp / .als / .lynx)
  22. # RUNS=3 runs per build and project (alternating before / after; at least 3)
  23. # GATE=1 % allowed per cell (perf_gate.py holds main to 5 %; a single change gets 1 %)
  24. # PIXELS=same|any whole-frame pixel hashes must match (default) or may differ
  25. # FRAMES=20 frames per measurement (LYNX_PAINTBENCH_FRAMES)
  26. # VIEWS="channel rack,..." only these views (LYNX_PAINTBENCH_VIEWS)
  27. # FL_ROOT, LIVE_DEMO as scripts/perf-gate.sh
  28. # Needs a display for the app (DISPLAY, e.g. a private Xvfb); keep the results dir on a local disk.
  29. set -u
  30. CONFIRM_CG=0; [ "${1:-}" = --confirm-callgrind ] && { CONFIRM_CG=1; shift; }
  31. [ $# -ge 2 ] || { sed -n 2,30p "$0" >&2; exit 2; }
  32. BEFORE=$1; AFTER=$2
  33. OUT=${3:-$(cd "$(dirname "$0")/.." && pwd)/build-paintgate/$(date +%Y%m%d-%H%M%S)}
  34. mkdir -p "$OUT" || exit 2
  35. FL_ROOT=${FL_ROOT:-"/mnt/c/Program Files/Image-Line/FL Studio 2026"}
  36. 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"}
  37. PROJECTS=${PROJECTS:-"thief patience"}
  38. RUNS=${RUNS:-3}; GATE=${GATE:-1}; PIXELS=${PIXELS:-same}
  39. [ "$RUNS" -ge 3 ] || RUNS=3
  40. NOASLR=(); setarch "$(uname -m)" -R true 2> /dev/null && NOASLR=(setarch "$(uname -m)" -R)
  41. project_file () {
  42. case $1 in
  43. thief) echo "$FL_ROOT/Data/Demo projects/Demo songs/Ookay - Thief.flp" ;;
  44. exoplanet) echo "$FL_ROOT/Data/Demo projects/Demo songs/Eric Kauffmann & NrgMind - Exoplanet.flp" ;;
  45. patience) echo "$LIVE_DEMO" ;;
  46. *) echo "$1" ;;
  47. esac
  48. }
  49. for b in "$BEFORE" "$AFTER"; do [ -x "$b" ] || { echo "paint-gate: not an executable: $b" >&2; exit 2; }; done
  50. for p in $PROJECTS; do [ -f "$(project_file "$p")" ] || { echo "paint-gate: project $p not found: $(project_file "$p")" >&2; exit 2; }; done
  51. for run in $(seq 1 "$RUNS"); do
  52. for p in $PROJECTS; do
  53. sides="before after"; [ $((run % 2)) = 0 ] && sides="after before"
  54. for side in $sides; do
  55. app=$BEFORE; [ "$side" = after ] && app=$AFTER
  56. name=$(basename "$p" | tr -c 'A-Za-z0-9\n' '_')
  57. prof=$OUT/profile-$side-$name-$run; rm -rf "$prof" # (a fresh profile: no stream cache of an earlier open)
  58. views=(); [ -n "${VIEWS:-}" ] && views=(LYNX_PAINTBENCH_VIEWS="$VIEWS")
  59. env LYNX_TEST_MODE=1 LYNX_PROFILE_DIR="$prof" XDG_CONFIG_HOME="$OUT/xdg-$side" LYNX_PAINTBENCH_FRAMES="${FRAMES:-20}" \
  60. LYNX_PAINTBENCH_FRAMES_OUT=1 "${views[@]}" timeout 1500 "${NOASLR[@]}" "$app" --paintbench "$(project_file "$p")" "$OUT/paint-$side-$name-$run.txt" \
  61. > "$OUT/paint-$side-$name-$run.log" 2>&1
  62. 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
  63. rm -rf "$prof"
  64. done
  65. done
  66. done
  67. python3 - "$OUT" "$GATE" "$PIXELS" <<'EOF'
  68. import glob, os, re, sys
  69. out, gate, pixels = sys.argv[1], float(sys.argv[2]), sys.argv[3]
  70. def load(side):
  71. cells, means, hashes = {}, {}, {}
  72. for f in glob.glob(os.path.join(out, f"paint-{side}-*.txt")):
  73. project = re.sub(r"^paint-" + side + r"-(.*)-\d+\.txt$", r"\1", os.path.basename(f))
  74. for line in open(f, encoding="utf-8", errors="replace"):
  75. m = re.match(r"(.+?), (whole frame|cached frame|playhead column): .*instructions median (\d+)", line)
  76. if m:
  77. k = (project, m.group(1), m.group(2)); v = int(m.group(3))
  78. cells[k] = min(cells.get(k, v), v)
  79. fr = re.search(r", frames((?: \d+)+)", line) # (LYNX_PAINTBENCH_FRAMES_OUT=1: the mean of the frames)
  80. if fr:
  81. vals = [int(x) for x in fr.group(1).split()]
  82. mv = sum(vals) / len(vals)
  83. means[k] = min(means.get(k, mv), mv)
  84. m = re.match(r"(.+?), whole frame: .*pixels ([0-9a-f]+)", line)
  85. if m:
  86. hashes.setdefault((project, m.group(1)), set()).add(m.group(2))
  87. return cells, means, hashes
  88. b, bm, bh = load("before")
  89. a, am, ah = load("after")
  90. if not b or not a:
  91. print("paint-gate: no instruction counts (Linux only, and the runs must succeed)"); sys.exit(2)
  92. worst, failed, lines = -100.0, [], []
  93. lines.append(f"| project | view | frame | before | after | change | |\n|---|---|---|---|---|---|---|")
  94. for k in sorted(b):
  95. if k not in a:
  96. failed.append(f"{k} missing after"); continue
  97. mean = k in bm and k in am # (both sides have every frame: the mean; otherwise both sides' medians)
  98. bv, av = (bm[k], am[k]) if mean else (b[k], a[k])
  99. d = (av - bv) * 100.0 / bv; worst = max(worst, d)
  100. bad = d > gate
  101. if bad: failed.append(f"{' / '.join(k)} {d:+.2f}%")
  102. 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)'} |")
  103. for k in sorted(bh):
  104. same = bh[k] == ah.get(k)
  105. lines.append(f"pixels {k[0]} / {k[1]}: {'same' if same else 'CHANGED ' + ','.join(sorted(bh[k])) + ' -> ' + ','.join(sorted(ah.get(k, {'missing'})))}")
  106. if not same and pixels != "any": failed.append(f"pixels {' / '.join(k)}")
  107. lines.append(f"worst {worst:+.2f}% (gate +{gate:g} %); {'PASS' if not failed else 'FAIL: ' + '; '.join(failed)}")
  108. open(os.path.join(out, "summary-paint.md"), "w").write("\n".join(lines) + "\n")
  109. print("\n".join(lines))
  110. sys.exit(1 if failed else 0)
  111. EOF
  112. rc=$?
  113. [ $rc = 1 ] && [ $CONFIRM_CG = 1 ] || exit $rc
  114. # --confirm-callgrind: the failing cells again under callgrind; the summary's last line is rewritten
  115. last=$(tail -1 "$OUT/summary-paint.md"); left=(); noise=()
  116. cell_re='^([^ /]+) / (.+) / (whole frame|cached frame|playhead column) [+-][0-9.]+%$'
  117. while IFS= read -r item; do
  118. [ -n "$item" ] || continue
  119. if [[ $item =~ $cell_re ]]; then
  120. name=${BASH_REMATCH[1]}; view=${BASH_REMATCH[2]}; kind=${BASH_REMATCH[3]}; proj=
  121. for p in $PROJECTS; do [ "$(basename "$p" | tr -c 'A-Za-z0-9\n' '_')" = "$name" ] && proj=$p; done
  122. case $kind in "whole frame") k=whole ;; "cached frame") k=cached ;; *) k=column ;; esac
  123. dir=$OUT/callgrind-$name-$(echo "$view" | tr -c 'A-Za-z0-9\n' '_')-$k
  124. verdict=
  125. [ -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
  126. verdict=$(grep '^verdict: ' "$dir/diff.txt" 2> /dev/null | tail -1 | sed 's/^verdict: //')
  127. case $verdict in
  128. NOISE*) noise+=("NOISE (callgrind) $item: $verdict") ;;
  129. "") left+=("$item (callgrind run failed: $dir.log)") ;;
  130. *) left+=("$item: $verdict") ;;
  131. esac
  132. else left+=("$item"); fi
  133. done < <(echo "$last" | sed 's/.*FAIL: //; s/; /\n/g')
  134. worst=${last%%; FAIL: *}
  135. { for n in "${noise[@]}"; do echo "$n"; done
  136. if [ ${#left[@]} = 0 ]; then echo "$worst; PASS (callgrind: ${#noise[@]} failing cell(s) were allocator noise)"
  137. else echo "$worst; FAIL: $(IFS=';'; echo "${left[*]}" | sed 's/;/; /g')"; fi
  138. } | tee -a "$OUT/summary-paint.md"
  139. [ ${#left[@]} = 0 ]