Cotton code
47 lines · 2.1 KB · ShellRaw
#!/usr/bin/env bash# Record a time profile of the speedgate app on its own simulator and print# where the main thread spends the cold start and each record-page open.#   scripts/speedgate/profile.sh <CottonSpeed.app> <out folder> [launches]# The app comes from a speed run (which builds it under the# derived-data root, speedgate/Build/Products/Debug-iphonesimulator). Each# launch is one trace; profile.py reads them all.set -euo pipefailHERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"APP="${1:?profile.sh <CottonSpeed.app> <out> [launches]}"OUT="${2:?profile.sh <CottonSpeed.app> <out> [launches]}"LAUNCHES="${3:-3}"mkdir -p "$OUT"OUT="$(cd "$OUT" && pwd -P)"# shellcheck source=../lib/owned-root.sh. "$HERE/../lib/owned-root.sh"refuse_wide_root 'speed profile output' "$OUT"read -r TYPE RUNTIME _ < <(python3 "$HERE/runtime.py")[ -n "$RUNTIME" ] || exit 1SIM="$(xcrun simctl create "Cotton speed profile $$" "$TYPE" "$RUNTIME")"cleanup() {  local status=$?  trap - EXIT  xcrun simctl shutdown "$SIM" >/dev/null 2>&1 || true  xcrun simctl delete "$SIM" || status=1  exit "$status"}trap cleanup EXITtrap 'exit 1' INT TERMxcrun simctl boot "$SIM"xcrun simctl bootstatus "$SIM" -b >/dev/nullxcrun simctl install "$SIM" "$APP"# One launch outside the traces: the first after install pays for the# simulator's own caches, which no person's launch does.xcrun simctl launch "$SIM" com.cottondb.speedgate >/dev/nullsleep 25xcrun simctl terminate "$SIM" com.cottondb.speedgate || truefor n in $(seq 1 "$LAUNCHES"); do  rm -rf "$OUT/launch-$n.trace"  xcrun xctrace record --quiet --template 'Time Profiler' --device "$SIM" --time-limit 40s \    --output "$OUT/launch-$n.trace" --launch -- "$APP" >/dev/null  xcrun xctrace export --input "$OUT/launch-$n.trace" \    --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]' >"$OUT/launch-$n.profile.xml"  xcrun xctrace export --input "$OUT/launch-$n.trace" \    --xpath '/trace-toc/run[@number="1"]/data/table[@schema="os-signpost"]' >"$OUT/launch-$n.signposts.xml"donepython3 "$HERE/profile.py" "$OUT"