#!/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 [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 pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" APP="${1:?profile.sh [launches]}" OUT="${2:?profile.sh [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 1 SIM="$(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 EXIT trap 'exit 1' INT TERM xcrun simctl boot "$SIM" xcrun simctl bootstatus "$SIM" -b >/dev/null xcrun 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/null sleep 25 xcrun simctl terminate "$SIM" com.cottondb.speedgate || true for 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" done python3 "$HERE/profile.py" "$OUT"