xctrace Skill
Profile and analyze app performance using Apple's Instruments toolchain via xctrace.
Quick Start
# 1. List available profiling templates
python scripts/trace_templates.py
# 2. Record a 10-second Time Profiler trace of your app
python scripts/trace_record.py --template "Time Profiler" --attach MyApp --time-limit 10s
# 3. Export trace data to JSON for analysis
python scripts/trace_export.py --input recording.trace --toc
# 4. Analyze a trace and get a summary
python scripts/trace_analyze.py --input recording.trace
All scripts support --help for detailed options and --json for machine-readable output.
Scripts
Profiling
trace_templates.py - List available Instruments templates
- Shows all templates: Time Profiler, Allocations, Leaks, SwiftUI, etc.
- Options:
--json
trace_record.py - Record a performance trace
- Profile by attaching to running app or launching
- Set time limits, output paths
- Options:
--template, --attach, --launch, --time-limit, --output, --all-processes, --json
trace_attach.py - Profile an already-running process
- Convenience wrapper for trace_record with --attach
- Options:
--pid, --name, --template, --time-limit, --output, --json
Analysis
trace_export.py - Export trace data
- Table of contents (--toc) or XPath queries
- Options:
--input, --output, --toc, --xpath, --json
trace_analyze.py - Generate performance summary
- Extracts key metrics from trace
- Identifies hotspots, allocations, issues
- Options:
--input, --verbose, --json
trace_compare.py - Compare two traces
- Before/after performance comparison
- Options:
--baseline, --current, --json
Binary Inspection
- binary_inspect.py - Inspect Mach-O binaries
- View linked libraries, symbols, headers
- Useful for understanding crashes, dependencies
- Options:
--headers, --libraries, --symbols, --swift-symbols, --json
Common Templates
| Template |
Use Case |
| Time Profiler |
CPU usage, find slow functions |
| Allocations |
Memory usage, object lifetimes |
| Leaks |
Memory leaks |
| SwiftUI |
SwiftUI view body evaluations, identity changes |
| Animation Hitches |
UI jank, dropped frames |
| App Launch |
Startup time analysis |
| Network |
HTTP requests, latency |
| Swift Concurrency |
Actor isolation, task scheduling |
Typical Workflows
"This screen is slow"
# Record while reproducing the issue
python scripts/trace_record.py --template "Time Profiler" --attach MyApp --time-limit 15s
# Analyze
python scripts/trace_analyze.py --input recording.trace
"App is using too much memory"
python scripts/trace_record.py --template "Allocations" --attach MyApp --time-limit 30s
python scripts/trace_analyze.py --input recording.trace
"Is my optimization working?"
# Record baseline
python scripts/trace_record.py --template "Time Profiler" --attach MyApp --output baseline.trace --time-limit 10s
# Make changes, rebuild, then record again
python scripts/trace_record.py --template "Time Profiler" --attach MyApp --output optimized.trace --time-limit 10s
# Compare
python scripts/trace_compare.py --baseline baseline.trace --current optimized.trace
"What's in this binary?"
python scripts/binary_inspect.py --libraries /path/to/MyApp.app/MyApp
python scripts/binary_inspect.py --swift-symbols /path/to/MyApp.app/MyApp
Requirements
- macOS 12+
- Xcode Command Line Tools
- Python 3
Notes
- Traces can be large (100MB+). Use
--time-limit to keep them manageable.
- Some templates require running on device (not simulator).
- For GUI analysis, open
.trace files in Instruments.app.
1---2name: xctrace-skill3description: Profile iOS/macOS app performance with Instruments (xctrace). Use when investigating CPU hotspots, memory leaks, animation hitches, or comparing performance before/after changes.4---56# xctrace Skill78Profile and analyze app performance using Apple's Instruments toolchain via `xctrace`.910## Quick Start1112```bash13# 1. List available profiling templates14python scripts/trace_templates.py1516# 2. Record a 10-second Time Profiler trace of your app17python scripts/trace_record.py --template "Time Profiler" --attach MyApp --time-limit 10s1819# 3. Export trace data to JSON for analysis20python scripts/trace_export.py --input recording.trace --toc2122# 4. Analyze a trace and get a summary23python scripts/trace_analyze.py --input recording.trace24```2526All scripts support `--help` for detailed options and `--json` for machine-readable output.2728## Scripts2930### Profiling31321. **trace_templates.py** - List available Instruments templates33 - Shows all templates: Time Profiler, Allocations, Leaks, SwiftUI, etc.34 - Options: `--json`35362. **trace_record.py** - Record a performance trace37 - Profile by attaching to running app or launching38 - Set time limits, output paths39 - Options: `--template`, `--attach`, `--launch`, `--time-limit`, `--output`, `--all-processes`, `--json`40413. **trace_attach.py** - Profile an already-running process42 - Convenience wrapper for trace_record with --attach43 - Options: `--pid`, `--name`, `--template`, `--time-limit`, `--output`, `--json`4445### Analysis46474. **trace_export.py** - Export trace data48 - Table of contents (--toc) or XPath queries49 - Options: `--input`, `--output`, `--toc`, `--xpath`, `--json`50515. **trace_analyze.py** - Generate performance summary52 - Extracts key metrics from trace53 - Identifies hotspots, allocations, issues54 - Options: `--input`, `--verbose`, `--json`55566. **trace_compare.py** - Compare two traces57 - Before/after performance comparison58 - Options: `--baseline`, `--current`, `--json`5960### Binary Inspection61627. **binary_inspect.py** - Inspect Mach-O binaries63 - View linked libraries, symbols, headers64 - Useful for understanding crashes, dependencies65 - Options: `--headers`, `--libraries`, `--symbols`, `--swift-symbols`, `--json`6667## Common Templates6869| Template | Use Case |70|----------|----------|71| Time Profiler | CPU usage, find slow functions |72| Allocations | Memory usage, object lifetimes |73| Leaks | Memory leaks |74| SwiftUI | SwiftUI view body evaluations, identity changes |75| Animation Hitches | UI jank, dropped frames |76| App Launch | Startup time analysis |77| Network | HTTP requests, latency |78| Swift Concurrency | Actor isolation, task scheduling |7980## Typical Workflows8182### "This screen is slow"83```bash84# Record while reproducing the issue85python scripts/trace_record.py --template "Time Profiler" --attach MyApp --time-limit 15s8687# Analyze88python scripts/trace_analyze.py --input recording.trace89```9091### "App is using too much memory"92```bash93python scripts/trace_record.py --template "Allocations" --attach MyApp --time-limit 30s94python scripts/trace_analyze.py --input recording.trace95```9697### "Is my optimization working?"98```bash99# Record baseline100python scripts/trace_record.py --template "Time Profiler" --attach MyApp --output baseline.trace --time-limit 10s101102# Make changes, rebuild, then record again103python scripts/trace_record.py --template "Time Profiler" --attach MyApp --output optimized.trace --time-limit 10s104105# Compare106python scripts/trace_compare.py --baseline baseline.trace --current optimized.trace107```108109### "What's in this binary?"110```bash111python scripts/binary_inspect.py --libraries /path/to/MyApp.app/MyApp112python scripts/binary_inspect.py --swift-symbols /path/to/MyApp.app/MyApp113```114115## Requirements116117- macOS 12+118- Xcode Command Line Tools119- Python 3120121## Notes122123- Traces can be large (100MB+). Use `--time-limit` to keep them manageable.124- Some templates require running on device (not simulator).125- For GUI analysis, open `.trace` files in Instruments.app.