#!/usr/bin/env bash
# The fan's budgets, traced on a ProMotion simulator (fanperf, owner 15 Oct
# 2026: "the animations must never make the app heavy; prove it, keep it
# proven"). Builds the synthetic Home with 30 tiles, drives the fan with real
# swipes (XCUITest), records it with xctrace, and prints one table: frame
# times while turning, CPU and Core Animation commits at rest, page-picture
# memory and growth over 100 turns, energy over a minute of swiping, cold
# start to the fan's first frame. Exits 1 when a figure is over its budget.
#
# scripts/perf/fan.sh # build, measure, report
# scripts/perf/fan.sh --out
# where the trace and samples go
# # (default ~/cotton-captures/fan-perf/)
# scripts/perf/fan.sh --sim # measure on this booted simulator
# scripts/perf/fan.sh --report # report a finished run again, no build
# scripts/perf/fan.sh --turns 300 # the growth phase's turns (default 100)
#
# Growth is not one run's figure: scripts/perf/growth.py reads a set of runs
# (five at 100 turns and one at 300, per runtime and value set) and is the
# growth budget (architect, 15 Oct 2026).
#
# Synthetic data only: the preview app runs over bundled fixture records and a
# scripted core, never a household or the owner's data.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT=""; SIM=""; REPORT_ONLY=""
while [ $# -gt 0 ]; do
case "$1" in
--out) OUT="${2:?--out needs a folder}"; shift 2 ;;
--sim) SIM="${2:?--sim needs a simulator udid}"; shift 2 ;;
--report) REPORT_ONLY="${2:?--report needs a run folder}"; shift 2 ;;
--turns) export FAN_TURNS="${2:?--turns needs a count}"; shift 2 ;;
*) echo "usage: fan.sh [--out ] [--sim ] [--report ] [--turns ]" >&2; exit 2 ;;
esac
done
if [ -n "$REPORT_ONLY" ]; then
exec python3 "$HERE/report.py" "$REPORT_ONLY"
fi
OUT="${OUT:-$HOME/cotton-captures/fan-perf/$(date -u +%Y%m%dT%H%M%SZ)}"
python3 "$HERE/../lib/evidence.py" begin "$OUT" >/dev/null
OUT="$(cd "$OUT" && pwd -P)"
bash "$HERE/../ui-tests-stub.sh" --fan-perf "$OUT" ${SIM:+--fan-sim "$SIM"}
exec python3 "$HERE/report.py" "$OUT"