Skill v1.0.1
currentAutomated scan100/1003 files
version: "1.0.1" name: axiom-xctrace-ref description: Use when automating Instruments profiling, running headless performance analysis, or integrating profiling into CI/CD - comprehensive xctrace CLI reference with record/export patterns license: MIT metadata: version: "1.0.0"
xctrace CLI Reference
Command-line interface for Instruments profiling. Enables headless performance analysis without GUI.
Overview
xctrace is the CLI tool behind Instruments.app. Use it for:
- Automated profiling in CI/CD pipelines
- Headless trace collection without GUI
- Programmatic trace analysis via XML export
- Performance regression detection
Requires: Xcode 12+ (xctrace 12.0+). This reference tested with Xcode 26.2.
Quick Reference
# Record a 10-second CPU profilexcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output profile.trace# Export to XML for analysisxcrun xctrace export --input profile.trace --toc # See available tablesxcrun xctrace export --input profile.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]'# List available instrumentsxcrun xctrace list instruments# List available templatesxcrun xctrace list templates
Recording Traces
Basic Recording
# Using an instrument (recommended for CLI automation)xcrun xctrace record --instrument 'CPU Profiler' --attach 'AppName' --time-limit 10s --output trace.trace# Using a template (may fail on export in Xcode 26+)xcrun xctrace record --template 'Time Profiler' --attach 'AppName' --time-limit 10s --output trace.trace
Note: In Xcode 26+, use --instrument instead of --template for reliable export. Templates may produce traces with "Document Missing Template Error" on export.
Target Selection
# Attach to running process by namexcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s# Attach to running process by PIDxcrun xctrace record --instrument 'CPU Profiler' --attach 12345 --time-limit 10s# Profile all processesxcrun xctrace record --instrument 'CPU Profiler' --all-processes --time-limit 10s# Launch and profilexcrun xctrace record --instrument 'CPU Profiler' --launch -- /path/to/app arg1 arg2# Target specific device (simulator or physical)xcrun xctrace record --instrument 'CPU Profiler' --device 'iPhone 17 Pro' --attach 'MyApp' --time-limit 10sxcrun xctrace record --instrument 'CPU Profiler' --device 947DF45C-4ACB-4B3E-A043-DF2CD59A59B3 --all-processes --time-limit 10s
Recording Options
| Flag | Description | |
|---|---|---|
--output <path> | Output .trace file path | |
--time-limit <time> | Recording duration (e.g., 10s, 1m, 500ms) | |
--no-prompt | Skip privacy warnings (use in automation) | |
--append-run | Add run to existing trace | |
--run-name <name> | Name the recording run |
Core Instruments
CPU Profiler
CPU sampling for finding hot functions.
xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output cpu.trace
Schema: cpu-profile Columns: time, thread, process, core, thread-state, weight (cycles), stack
Allocations
Memory allocation tracking.
xcrun xctrace record --instrument 'Allocations' --attach 'MyApp' --time-limit 30s --output alloc.trace
Schema: allocations Use for: Finding memory growth, object counts, allocation patterns
Leaks
Memory leak detection.
xcrun xctrace record --instrument 'Leaks' --attach 'MyApp' --time-limit 30s --output leaks.trace
Schema: leaks Use for: Detecting unreleased memory, retain cycles
SwiftUI
SwiftUI view body analysis.
xcrun xctrace record --instrument 'SwiftUI' --attach 'MyApp' --time-limit 10s --output swiftui.trace
Schema: swiftui Use for: Finding excessive view updates, body re-evaluations
Swift Concurrency
Actor and Task analysis.
xcrun xctrace record --instrument 'Swift Tasks' --instrument 'Swift Actors' --attach 'MyApp' --time-limit 10s --output concurrency.trace
Schemas: swift-task, swift-actor Use for: Task scheduling, actor isolation, async performance
All Available Instruments
Activity Monitor Audio Client Audio ServerAudio Statistics CPU Counters CPU ProfilerCore Animation Activity Core Animation Commits Core Animation FPSCore Animation Server Core ML Data FaultsData Fetches Data Saves Disk I/O LatencyDisk Usage Display Filesystem ActivityFilesystem Suggestions Foundation Models Frame LifetimesGCD Performance GPU HTTP TrafficHangs Hitches LeaksLocation Energy Model Metal Application Metal GPU CountersMetal Performance Overview Metal Resource Events Network ConnectionsNeural Engine Points of Interest Power ProfilerProcessor Trace RealityKit Frames RealityKit MetricsRunloops Sampler SceneKit ApplicationSwift Actors Swift Tasks SwiftUISystem Call Trace System Load Thread StatesTime Profiler VM Tracker Virtual Memory Trace
Exporting Traces
Table of Contents
# See all available data tables in a tracexcrun xctrace export --input trace.trace --toc
Output structure:
<trace-toc><run number="1"><info><target>...</target><summary>...</summary></info><processes>...</processes><data><table schema="cpu-profile" .../><table schema="thread-info"/><table schema="process-info"/></data></run></trace-toc>
XPath Export
# Export specific table by schemaxcrun xctrace export --input trace.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]'# Export process infoxcrun xctrace export --input trace.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="process-info"]'# Export thread infoxcrun xctrace export --input trace.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="thread-info"]'
CPU Profile Schema
<schema name="cpu-profile"><col><mnemonic>time</mnemonic><name>Sample Time</name></col><col><mnemonic>thread</mnemonic><name>Thread</name></col><col><mnemonic>process</mnemonic><name>Process</name></col><col><mnemonic>core</mnemonic><name>Core</name></col><col><mnemonic>thread-state</mnemonic><name>State</name></col><col><mnemonic>weight</mnemonic><name>Cycles</name></col><col><mnemonic>stack</mnemonic><name>Backtrace</name></col></schema>
Each row contains:
sample-time: Timestamp in nanosecondsthread: Thread ID and nameprocess: Process name and PIDcore: CPU core numberthread-state: Running, Blocked, etc.cycle-weight: CPU cyclesbacktrace: Call stack with function names
Process Discovery
Find Running Simulator Apps
# List apps in booted simulatorxcrun simctl spawn booted launchctl list | grep UIKitApplication# Output format: PID Status com.apple.UIKitApplication:com.bundle.id[xxxx][rb-legacy]
Find Device UUID
# List booted simulators (JSON)xcrun simctl list devices booted -j# List all devicesxcrun simctl list devices
Find Process by Name
# Get PID of running apppgrep -f "MyApp"# List all processes with app nameps aux | grep MyApp
Automation Patterns
CI/CD Integration
#!/bin/bash# performance-test.shAPP_NAME="MyApp"TRACE_DIR="./traces"TIME_LIMIT="30s"# Boot simulator if neededxcrun simctl boot "iPhone 17 Pro" 2>/dev/null || true# Wait for app to launchsleep 5# Record CPU profilexcrun xctrace record \--instrument 'CPU Profiler' \--device "iPhone 17 Pro" \--attach "$APP_NAME" \--time-limit "$TIME_LIMIT" \--no-prompt \--output "$TRACE_DIR/cpu.trace"# Export for analysisxcrun xctrace export \--input "$TRACE_DIR/cpu.trace" \--xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]' \> "$TRACE_DIR/cpu-profile.xml"# Parse and check thresholds# (Use xmllint, python, or custom tool to parse XML)
Before/After Comparison
# Record baselinexcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output baseline.trace# Make changes, rebuild app# Record after changesxcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output after.trace# Export both for comparisonxcrun xctrace export --input baseline.trace --xpath '...' > baseline.xmlxcrun xctrace export --input after.trace --xpath '...' > after.xml
Troubleshooting
"Document Missing Template Error" on Export
Cause: Recording used --template flag in Xcode 26+ Fix: Use --instrument instead:
# Instead ofxcrun xctrace record --template 'Time Profiler' ...# Usexcrun xctrace record --instrument 'CPU Profiler' ...
"Unable to attach to process"
Causes:
- Process not running
- Insufficient permissions
- System Integrity Protection blocking
Fix:
# Verify process existspgrep -f "AppName"# For simulator apps, verify simulator is bootedxcrun simctl list devices booted# Try with --all-processes instead of --attachxcrun xctrace record --instrument 'CPU Profiler' --all-processes --time-limit 5s
Empty Trace Export
Cause: Recording too short or no activity during recording Fix: Increase --time-limit or ensure app is actively used during recording
Symbolication Issues
Raw addresses in backtraces (e.g., 0x18f17ed94) instead of function names.
Fix: Ensure dSYMs are available:
# Symbolicate trace (if needed)xcrun xctrace symbolicate --input trace.trace --dsym /path/to/App.dSYM
Limitations
- Privacy restrictions: Some instruments require privacy permissions granted in System Preferences
- Device support: Physical device profiling requires Developer Mode enabled
- Background apps: Limited profiling of backgrounded apps
- Export format: XML only (no JSON export)
- Template vs Instrument: In Xcode 26+, templates may not export properly
Resources
Skills: axiom-performance-profiling, axiom-memory-debugging, axiom-swiftui-performance
Docs: /xcode/instruments, /os/logging/recording-performance-data