π¦ ClawHub
Instruments Profiling
by @steipete
Use when profiling native macOS or iOS apps with Instruments/xctrace. Covers correct binary selection, CLI arguments, exports, and common gotchas.
TERMINAL
clawhub install instruments-profilingπ About This Skill
name: instruments-profiling description: Use when profiling native macOS or iOS apps with Instruments/xctrace. Covers correct binary selection, CLI arguments, exports, and common gotchas. metadata: short-description: Instruments profiling for macOS/iOS apps
Instruments Profiling (macOS/iOS)
Use this skill when the user wants performance profiling or stack analysis for native apps.
Focus: Time Profiler, xctrace CLI, and picking the correct binary/app instance.
Quick Start (CLI)
xcrun xctrace list templatesxcrun xctrace record --template 'Time Profiler' --time-limit 60s --output /tmp/App.trace --launch -- /path/To/App.app
xcrun xctrace record --template 'Time Profiler' --time-limit 60s --output /tmp/App.trace --attach
open -a Instruments /tmp/App.traceNote: xcrun xctrace --help is not a valid subcommand. Use xcrun xctrace help record.
Picking the Correct Binary (Critical)
Gotcha: Instruments may profile the wrong app (e.g., one in /Applications) if LaunchServices resolves a different bundle.
Use these rules:
xcrun xctrace record ... --launch -- /path/App.app/Contents/MacOS/App
.app, ensure itβs the intended bundle:open -n /path/App.app
- Verify with ps -p -o comm= -o command=
/Applications/App.app and a local build exist, explicitly target the local build path.Command Arguments (xctrace)
--template 'Time Profiler': template name from xctrace list templates.--launch -- : everything after -- is the target command (binary or app bundle).--attach : attach to running process.--output : .trace output. If omitted, file saved in CWD.--time-limit 60s|5m: set capture duration.--device : required for iOS device runs.--target-stdout -: stream launched process stdout to terminal (useful for CLI tools).Exporting Stacks (CLI)
xcrun xctrace export --input /tmp/App.trace --toc
xcrun xctrace export --input /tmp/App.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]' --output /tmp/time-profile.xml
Instruments UI Workflow
Gotchas & Fixes
--attach with known PID.
xctrace may need Developer Tools permission.time-profile exports are huge.iOS Specific Notes
xcrun xctrace list devices and --device .xctrace --attach.