100 lines · 4.4 KB · ShellRaw
#!/usr/bin/env bash# Called only by ui-tests-stub.sh, inside its private workspace and build lock.set -euo pipefailDIR="$1"; OUT="$2"; REPO="$3"mkdir -p "$DIR/speedgate" "$OUT"cp "$REPO/scripts/speedgate/SpeedApp.swift" "$DIR/speedgate/SpeedApp.swift"cat > "$DIR/speedgate/project.yml" <<'YAML'name: CottonSpeedoptions: bundleIdPrefix: com.cottondbpackages: cotton: path: ../apps/cottontargets: CottonSpeed: type: application platform: iOS deploymentTarget: '26.0' sources: [SpeedApp.swift] dependencies: - package: cotton product: CottonUI settings: base: PRODUCT_BUNDLE_IDENTIFIER: com.cottondb.speedgate GENERATE_INFOPLIST_FILE: YES INFOPLIST_KEY_UILaunchScreen_Generation: YES INFOPLIST_KEY_UIApplicationSceneManifest_Generation: YES SWIFT_VERSION: '6.0' SWIFT_OPTIMIZATION_LEVEL: '-O' ENABLE_TESTABILITY: YES CODE_SIGNING_ALLOWED: NOYAML(cd "$DIR/speedgate" && xcodegen generate >/dev/null)read -r TYPE RUNTIME RUNTIME_NAME < <(python3 "$REPO/scripts/speedgate/runtime.py")[ -n "$RUNTIME" ] || exit 1SIM="$(xcrun simctl create "Cotton speedgate $$" "$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 TERMbash "$REPO/scripts/lane-claim.sh" "$HOME/Library/Developer/CoreSimulator/Devices/$SIM" --kind simulator --lane speedgate >&2# One derived-data root for the project (scripts/lib/derived-data.sh), swept with# the others; never Xcode's default hash folder and never a tree nothing sweeps.# shellcheck source=../lib/derived-data.sh. "$REPO/scripts/lib/derived-data.sh"DERIVED="$(cotton_derived_data)/speedgate"xcrun simctl boot "$SIM"xcrun simctl bootstatus "$SIM" -b >/dev/nullxcodebuild build -project "$DIR/speedgate/CottonSpeed.xcodeproj" -scheme CottonSpeed \ -destination "platform=iOS Simulator,id=$SIM" -derivedDataPath "$DERIVED" \ SWIFT_OPTIMIZATION_LEVEL=-O ENABLE_TESTABILITY=YES CODE_SIGNING_ALLOWED=NO -quietAPP="$DERIVED/Build/Products/Debug-iphonesimulator/CottonSpeed.app"xcrun simctl install "$SIM" "$APP"DATA="$(xcrun simctl get_app_container "$SIM" com.cottondb.speedgate data)"# Five launches as the app runs (with the record page's warm-up), then five# without it, so the first open is reported both ways (architect, 14 Oct 2026).for run in 1 2 3 4 5 unwarmed-1 unwarmed-2 unwarmed-3 unwarmed-4 unwarmed-5; do rm -f "$DATA/Documents/speed.json" case "$run" in unwarmed-*) xcrun simctl launch "$SIM" com.cottondb.speedgate -speedgate-no-warmup >/dev/null ;; *) xcrun simctl launch "$SIM" com.cottondb.speedgate >/dev/null ;; esac for ((tick=0; tick<120; tick++)); do [ ! -f "$DATA/Documents/speed.json" ] || break sleep 0.5 done [ -s "$DATA/Documents/speed.json" ] || { echo '[speed] FAILED: simulator produced no figures' >&2; exit 1; } cp "$DATA/Documents/speed.json" "$OUT/run-$run.json" xcrun simctl terminate "$SIM" com.cottondb.speedgatedonepython3 - "$OUT" "$TYPE" "$RUNTIME" "$REPO" "$RUNTIME_NAME" <<'PY'import jsonfrom pathlib import Pathimport sysout = Path(sys.argv[1])runs = [json.loads((out / f'run-{n}.json').read_text()) for n in range(1, 6)]unwarmed = [json.loads((out / f'run-unwarmed-{n}.json').read_text()) for n in range(1, 6)]for run in runs + unwarmed: if 'error' in run: sys.exit('[speed] FAILED: ' + run['error'])# Each launch opens every kind twice; its first is the process's first open.def first_opens(launches): return {kind: [r['record_page_ms'][kind][0] for r in launches] for kind in ('todo', 'note', 'person')}raw = {'cold_start_ms': [r['cold_start_ms'] for r in runs], 'record_page_ms': {kind: [v for r in runs for v in r['record_page_ms'][kind]] for kind in ('todo', 'note', 'person')}, 'first_open_ms': {'warmed': first_opens(runs), 'unwarmed': first_opens(unwarmed)}, 'scope': 'synthetic-ui-stub-simulator', 'optimized': True, 'frame_boundary': 'first-display-timestamp-after-mount', 'device_type': sys.argv[2], 'runtime': sys.argv[3], 'runtime_name': sys.argv[5]}import subprocessraw['commit'] = subprocess.check_output(['git', '-C', sys.argv[4], 'rev-parse', 'HEAD'], text=True).strip()(out / 'samples.json').write_text(json.dumps(raw, indent=2) + '\n')PY