paint-callgrind.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. # paint-callgrind.sh (round 190tz, queue item 108): tells a paint-gate cell's growth from allocator noise. Runs one view of one
  3. # project under callgrind for two LYNX builds (the gate's own --paintbench, every frame kind in the gate's order, so the caches are
  4. # in the same state), keeps the asked frame kind alone (a dump after each measure's sort), and compares the self cost per object
  5. # and per function plus the allocation call counts. LYNX's own code (with JUCE and HarfBuzz, linked into the binary) is
  6. # deterministic under callgrind to a few hundred instructions; glibc's malloc internals are not (heap state: the same binary
  7. # against itself moved a playhead column by +0.96 %). scripts/paint-gate.sh --confirm-callgrind runs this for each failing cell.
  8. # usage: scripts/paint-callgrind.sh <LYNX before> <LYNX after> <thief|patience|exoplanet|file> <view> <whole|cached|column> <out dir>
  9. # env: DISPLAY (a private Xvfb), VG (valgrind, default `valgrind`), OWN_LIMIT=0.05 (% of own self cost),
  10. # QUIETWAIT (a command run before each build's run, e.g. a wait for another job's quiet window), FL_ROOT, LIVE_DEMO
  11. # verdict: NOISE when the binary's own self cost moved <= OWN_LIMIT % and malloc/realloc/calloc/new counts are equal; else
  12. # REAL GROWTH (own code dearer by more than OWN_LIMIT %) or REAL CHANGE (the code path changed, not dearer).
  13. set -u
  14. [ $# -ge 6 ] || { sed -n 2,12p "$0" >&2; exit 2; }
  15. B=$1; A=$2; P=$3; V=$4; K=$5; O=$6; mkdir -p "$O" || exit 2
  16. VG=${VG:-valgrind}; HERE=$(cd "$(dirname "$0")" && pwd)
  17. FL_ROOT=${FL_ROOT:-"/mnt/c/Program Files/Image-Line/FL Studio 2026"}
  18. 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"}
  19. case $P in
  20. thief) P="$FL_ROOT/Data/Demo projects/Demo songs/Ookay - Thief.flp" ;;
  21. exoplanet) P="$FL_ROOT/Data/Demo projects/Demo songs/Eric Kauffmann & NrgMind - Exoplanet.flp" ;;
  22. patience) P="$LIVE_DEMO" ;;
  23. esac
  24. case $K in whole) d=1 ;; cached) d=3 ;; column) d=5 ;; *) echo "frame kind: whole|cached|column" >&2; exit 2 ;; esac
  25. for side in before after; do
  26. app=$B; [ $side = after ] && app=$A
  27. [ -n "${QUIETWAIT:-}" ] && $QUIETWAIT
  28. rm -rf "$O/prof-$side"
  29. env LYNX_TEST_MODE=1 LYNX_PROFILE_DIR="$O/prof-$side" XDG_CONFIG_HOME="$O/xdg-$side" LYNX_PAINTBENCH_FRAMES=20 LYNX_PAINTBENCH_FRAMES_OUT=1 LYNX_PAINTBENCH_VIEWS="$V" \
  30. timeout 1800 nice -n 10 "$VG" --tool=callgrind --collect-atstart=no \
  31. --toggle-collect='*runPaintBench*lambda(juce::String const&, int)*' \
  32. --dump-after='void std::__sort<__gnu_cxx::__normal_iterator<double*,*' \
  33. --callgrind-out-file="$O/cg-$side.out" "$app" --paintbench "$P" "$O/paint-$side.txt" > "$O/cg-$side.log" 2>&1
  34. [ -f "$O/cg-$side.out.$d" ] || { echo "paint-callgrind: $side gave no dump $d (see $O/cg-$side.log)" >&2; exit 2; }
  35. done
  36. python3 "$HERE/paint_cgself.py" "$O/cg-before.out.$d" "$O/cg-after.out.$d" 15 | tee "$O/diff.txt"
  37. python3 - "$HERE" "$O/cg-before.out.$d" "$O/cg-after.out.$d" "${OWN_LIMIT:-0.05}" <<'PY' | tee -a "$O/diff.txt"
  38. import sys; sys.path.insert(0, sys.argv[1]); import paint_cgself as cgself
  39. a, ca, oa = cgself.parse(sys.argv[2]); b, cb, ob = cgself.parse(sys.argv[3]); lim = float(sys.argv[4])
  40. own = lambda s, o: sum(v for f, v in s.items() if cgself.short(o.get(f)) == 'LYNX')
  41. oa_, ob_ = own(a, oa), own(b, ob); d = 100.0 * (ob_ - oa_) / max(1, oa_)
  42. same = all(ca[k] == cb[k] for k in ('malloc', 'realloc', 'calloc', 'operator new(unsigned long)', 'operator new[](unsigned long)'))
  43. ta, tb = sum(a.values()), sum(b.values())
  44. print(f"verdict: {'NOISE' if abs(d) <= lim and same else ('REAL GROWTH' if d > lim else 'REAL CHANGE')} (own code {d:+.4f} %, allocation calls {'equal' if same else 'DIFFERENT'}, all {100.0*(tb-ta)/max(1,ta):+.3f} %)")
  45. PY