#!/usr/bin/env bash # Called only by ui-tests-stub.sh --scroll-perf, inside its private workspace # and build lock (scripts/perf/scroll.sh is the entry). Builds the synthetic # Home preview with a UI-test runner (ScrollSweepUITests.swift), then on a # ProMotion simulator runs the sweep while xctrace records the app (Core # Animation commits and CPU Profiler, as run-simulator.sh does: Hitches and # Core Animation FPS do not run on the simulator) and the fan's own log is # kept. The app's frame meter (`DevFrames`, `-dev.frames.on YES`) writes one # line a second into its container; that file is copied out before the # simulator goes. None of the fan sweep's rest, turn, energy or cold-start # phases run here: this is the lists alone, so a run takes about two # minutes after the build. Everything lands in ; scroll-report.py reads it. set -euo pipefail DIR="$1"; OUT="$2"; REPO="$3"; SIM="${4:-}" W="$DIR/scroll-perf" mkdir -p "$W" python3 "$REPO/scripts/lib/evidence.py" begin "$OUT" >/dev/null cp "$REPO/scripts/home-preview/HomePreviewApp.swift" "$W/HomePreviewApp.swift" cp "$REPO/scripts/perf/ScrollSweepUITests.swift" "$W/ScrollSweepUITests.swift" # The app target is the fan sweep's (run-simulator.sh): the same build # settings, so a figure here and one there are of the same app. cat > "$W/project.yml" <<'YAML' name: CottonScrollPerf options: bundleIdPrefix: com.cottondb packages: cotton: path: ../apps/cotton targets: CottonHomePreview: type: application platform: iOS deploymentTarget: '26.0' sources: [HomePreviewApp.swift] dependencies: - package: cotton product: CottonUI info: path: Info.plist properties: CFBundleURLTypes: - CFBundleURLName: com.cottondb.homepreview CFBundleURLSchemes: [cottonhomepreview] settings: base: PRODUCT_BUNDLE_IDENTIFIER: com.cottondb.homepreview GENERATE_INFOPLIST_FILE: YES INFOPLIST_KEY_UILaunchScreen_Generation: YES INFOPLIST_KEY_UIApplicationSceneManifest_Generation: YES INFOPLIST_KEY_NSMicrophoneUsageDescription: The record button listens to what you say. INFOPLIST_KEY_NSSpeechRecognitionUsageDescription: What you say becomes words on the device. INFOPLIST_KEY_CADisableMinimumFrameDurationOnPhone: YES SWIFT_VERSION: '6.0' SWIFT_OPTIMIZATION_LEVEL: '-O' ENABLE_TESTABILITY: YES CODE_SIGN_IDENTITY: '-' ScrollSweep: type: bundle.ui-testing platform: iOS deploymentTarget: '26.0' sources: [ScrollSweepUITests.swift] dependencies: - target: CottonHomePreview settings: base: GENERATE_INFOPLIST_FILE: YES PRODUCT_BUNDLE_IDENTIFIER: com.cottondb.scrollsweep TEST_TARGET_NAME: CottonHomePreview SWIFT_VERSION: '6.0' CODE_SIGN_IDENTITY: '-' schemes: ScrollPerf: build: targets: CottonHomePreview: all ScrollSweep: [test] test: targets: [ScrollSweep] YAML (cd "$W" && xcodegen generate >/dev/null) OWN_SIM="" if [ -z "$SIM" ]; then read -r TYPE RUNTIME < <(python3 "$REPO/scripts/perf/simulator.py") SIM="$(xcrun simctl create "Cotton scrollperf $$" "$TYPE" "$RUNTIME")" OWN_SIM="$SIM" fi PIDS=() cleanup() { local status=$? trap - EXIT for pid in ${PIDS[@]+"${PIDS[@]}"}; do kill "$pid" >/dev/null 2>&1 || true; done if [ -n "$OWN_SIM" ]; then xcrun simctl shutdown "$OWN_SIM" >/dev/null 2>&1 || true xcrun simctl delete "$OWN_SIM" >/dev/null 2>&1 || true fi exit "$status" } trap cleanup EXIT xcrun simctl boot "$SIM" >/dev/null 2>&1 || true xcrun simctl bootstatus "$SIM" -b >/dev/null # shellcheck source=../lib/derived-data.sh . "$REPO/scripts/lib/derived-data.sh" DERIVED="$(cotton_derived_data)/scroll-perf" xcodebuild build-for-testing -project "$W/CottonScrollPerf.xcodeproj" -scheme ScrollPerf \ -destination "platform=iOS Simulator,id=$SIM" -derivedDataPath "$DERIVED" -quiet XCTESTRUN="$(ls "$DERIVED"/Build/Products/ScrollPerf_*.xctestrun | head -n 1)" APP_PATTERN="Devices/$SIM/.*/CottonHomePreview.app/CottonHomePreview" xcrun simctl terminate "$SIM" com.cottondb.homepreview >/dev/null 2>&1 || true STAMP="$(date -u +%Y%m%dT%H%M%SZ)" TRACE="$OUT/scroll-$STAMP.trace" printf '%s\n' "$TRACE" > "$OUT/trace-name.txt" # The fan's own lines, its folds and blooms among them (`FanCollapse`), with # the time each was said. xcrun simctl spawn "$SIM" log stream --style compact --level info \ --predicate 'subsystem == "com.cottondb.fan"' > "$OUT/fan.log" 2>&1 & PIDS+=("$!") # scroll.sh's settings reach the test as TEST_RUNNER_ variables (xcodebuild # hands them to the runner without the prefix). printf 'seconds %s rows %s tools %s\n' "${SCROLL_S:-10}" "${SCROLL_ROWS:-200}" \ "${SCROLL_TOOLS:-meetings|mood|people|email}" > "$OUT/settings.txt" TEST_RUNNER_SCROLL_S="${SCROLL_S:-10}" TEST_RUNNER_SCROLL_ROWS="${SCROLL_ROWS:-200}" \ TEST_RUNNER_SCROLL_TOOLS="${SCROLL_TOOLS:-meetings|mood|people|email}" \ xcodebuild test-without-building -xctestrun "$XCTESTRUN" \ -destination "platform=iOS Simulator,id=$SIM" -only-testing:ScrollSweep/ScrollSweep/testScroll > "$OUT/sweep.log" 2>&1 & SWEEP="$!" APP_PID="" for _ in $(seq 1 240); do APP_PID="$(pgrep -f "$APP_PATTERN" | head -n 1 || true)" [ -n "$APP_PID" ] && break kill -0 "$SWEEP" 2>/dev/null || break sleep 0.5 done [ -n "$APP_PID" ] || { echo "scroll-perf: the app never started (see $OUT/sweep.log)" >&2; exit 1; } echo "$APP_PID" > "$OUT/app-pid.txt" xcrun xctrace record --device "$SIM" --attach "$APP_PID" --no-prompt \ --instrument 'Core Animation Commits' --instrument 'CPU Profiler' \ --output "$TRACE" > "$OUT/xctrace.log" 2>&1 & XCTRACE="$!" STATUS=0 wait "$SWEEP" || STATUS=$? kill -INT "$XCTRACE" >/dev/null 2>&1 || true wait "$XCTRACE" || true # The frame meter's lines, read before the simulator (and its container) goes. DATA="$(xcrun simctl get_app_container "$SIM" com.cottondb.homepreview data 2>/dev/null || true)" [ -n "$DATA" ] && cp "$DATA/tmp/dev-frames.log" "$OUT/dev-frames.log" 2>/dev/null || true [ "$STATUS" = 0 ] || { echo "scroll-perf: the sweep failed (see $OUT/sweep.log)" >&2; exit "$STATUS"; } xcrun xctrace export --input "$TRACE" --toc > "$OUT/toc.xml" xcrun xctrace export --input "$TRACE" \ --xpath '/trace-toc/run[@number="1"]/data/table[@schema="coreanimation-commit-interval"]' > "$OUT/commits.xml" xcrun xctrace export --input "$TRACE" \ --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]' > "$OUT/cpu-profile.xml" xcrun simctl getenv "$SIM" SIMULATOR_RUNTIME_VERSION > "$OUT/runtime.txt" 2>/dev/null || true xcrun simctl list devices | grep "$SIM" | sed 's/^ *//' > "$OUT/device.txt" || true