用途:面向原生 macOS/iOS 应用的性能剖析与调用栈分析,核心是 Time Profiler 与 xctrace 命令行工具,并强调选对要剖析的二进制或应用实例。
主要能力:列出模板、录制 Time Profiler(启动或附加进程)、导出调用栈样本、在 Instruments 中打开 trace,以及处理常见问题。
必要用法:列出模板用 xcrun xctrace list templates;启动录制示例:xcrun xctrace record --template 'Time Profiler' --time-limit 60s --output /tmp/App.trace --launch -- /path/To/App.app;附加进程用 --attach <pid>;打开 trace 用 open -a Instruments /tmp/App.trace。注意 xcrun xctrace --help 不是有效子命令,应使用 xcrun xctrace help record。
选对二进制:Instruments 可能因 LaunchServices 解析到 /Applications 下的应用而剖析错误目标。建议直接指定二进制路径,如 --launch -- /path/App.app/Contents/MacOS/App;若启动 .app 需确认是目标 bundle,并用 ps -p <pid> -o comm= -o command= 核对进程路径。
常用参数:--template、--launch --、--attach、--output、--time-limit、--device(iOS 设备必需)、--target-stdout -。
导出:用 xcrun xctrace export --input /tmp/App.trace --toc 查看表;导出 time-profile 样本用 --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]' --output /tmp/time-profile.xml,再离线聚合。
限制与坑:可能剖析错应用、trace 为空、需要开发者工具权限、XML 导出体积大;iOS 需用 --device 指定 UDID 并确保有调试符号。资料未提供收费、价格或平台支持范围等信息。