Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Reviews, improves, and writes SwiftUI code following state management, view composition, performance, and iOS 26+ Liquid Glass best practices.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/trace-recording.md
1# Recording an Instruments Trace23Use this reference when the user asks to record a new trace — either to4attach to a running app, launch one fresh, or capture a specific session5of actions they'll perform interactively.67The bundled `scripts/record_trace.py` wraps `xctrace record` with:89- The **SwiftUI** template by default (override with `--template`).10- **Manual stop** via Ctrl+C, a stop-file, or `--time-limit`.11- JSON discovery for devices and templates.12- Normal Python exit codes so an agent can orchestrate.1314## Typical flows1516### A) Attach to a running app on a connected device1718```bash19python3 "${SKILL_DIR}/scripts/record_trace.py" \20--device "Pol's iPhone" \21--attach "Helm" \22--output ~/Desktop/helm-session.trace23```2425Leave it running while the user exercises the app. Stop with **Ctrl+C**.2627### B) Launch an app and record from the first frame2829```bash30python3 "${SKILL_DIR}/scripts/record_trace.py" \31--device "<UDID>" \32--launch "/path/to/App.app" \33--output ~/Desktop/launch.trace34```3536Useful for diagnosing cold-start hitches and view-creation cost.3738### C) Agent-driven: start in background, stop via stop-file3940When you (the agent) are running non-interactively — e.g. via41`Bash run_in_background` — use a stop-file so you can signal the42recording to end cleanly:4344```bash45# Start recording (background)46python3 "${SKILL_DIR}/scripts/record_trace.py" \47--attach Helm --stop-file /tmp/stop-trace \48--output ~/Desktop/session.trace4950# ...user does their thing...5152# Stop cleanly (from another shell or tool call)53touch /tmp/stop-trace54```5556The script polls every 0.5s for the stop-file, sends SIGINT to xctrace57when it appears, and waits up to 60s for the trace to finalise.5859### D) Time-boxed recording6061```bash62python3 "${SKILL_DIR}/scripts/record_trace.py" \63--attach Helm --time-limit 30s --output ~/Desktop/30s.trace64```6566xctrace stops itself at the limit.6768## Discovery helpers6970```bash71# List every connected device, simulator, and the host — JSON.72python3 "${SKILL_DIR}/scripts/record_trace.py" --list-devices7374# List all Instruments templates — JSON with a flat list + by-section map.75python3 "${SKILL_DIR}/scripts/record_trace.py" --list-templates76```7778Device entries have `kind` (`devices`, `devices offline`, `simulators`),79`name`, `os`, `udid`. Offline devices are known but unplugged / unpaired —80plug them in before recording.8182## Picking a template8384> **Hard rule: the `SwiftUI` template only populates the SwiftUI lane on a85> real device — a physical iOS/iPadOS device or the host Mac. On the iOS86> Simulator it records but the SwiftUI lane comes back empty.** If the87> chosen UDID falls under the `simulators` kind from `--list-devices`,88> switch to `Time Profiler`. It still gives you Time Profiler + Hangs +89> Animation Hitches, which `analyze_trace.py` analyses and correlates90> normally; only the `swiftui` lane will report `available: false`.9192Decision flow:9394| Target | Template to pass |95|----------------------------------------------|----------------------|96| Physical iOS/iPadOS device (connected) | `SwiftUI` (default) |97| Host Mac (macOS app, `--all-processes`, etc.)| `SwiftUI` (default) |98| iOS / iPadOS / watchOS / tvOS Simulator | `Time Profiler` |99100Always confirm the target kind with `--list-devices` before starting a101recording: entries under `simulators` mean you must switch to Time102Profiler; entries under `devices` (both connected devices and the host103Mac) support the SwiftUI template. Entries under `devices offline` need104the user to connect/unlock/trust the device before recording.105106For ad-hoc hang hunting on any target, `Time Profiler` or107`Animation Hitches` alone may be enough.108109## Chaining into analysis110111The recording script prints `trace written: <path>` on exit. Feed that112path straight into `analyze_trace.py`:113114```bash115TRACE=$(python3 "${SKILL_DIR}/scripts/record_trace.py" \116--attach Helm --stop-file /tmp/stop-trace --output ~/Desktop/session.trace \1172>&1 | awk '/trace written:/ {print $NF}')118python3 "${SKILL_DIR}/scripts/analyze_trace.py" --trace "$TRACE" --json-only119```120121If the user wanted a specific scope, combine with `--list-logs` /122`--list-signposts` / `--window` from `references/trace-analysis.md`.123124## Failure modes to handle125126- **Device offline** — `--list-devices` shows it in `devices offline`.127Ask the user to connect/unlock the device and retry.128- **Output path exists** — the script refuses to overwrite. Either pick129a new `--output` or delete the existing bundle.130- **App not running (for `--attach`)** — xctrace exits with an error;131fall back to `--launch` or tell the user to open the app first.132- **Signing / trust on device** — iOS requires a development build133signed with the user's team. If xctrace returns a signing error, point134the user to trust the developer profile on the device.135