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