用途:面向 macOS/iOS 原生应用的性能剖析与调用栈分析,核心是 Time Profiler 与 xctrace 命令行。
主要能力:列出模板、录制或附加进程、导出 trace 中的采样数据、在 Instruments 中查看调用树。
必要用法:列出模板 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。
选对二进制:LaunchServices 可能解析到 /Applications 下的应用而非本地构建,建议直接指定可执行文件路径,或用 open -n 启动后用 ps -p <pid> -o comm= -o command= 核对进程路径。
导出:先 xcrun xctrace export --input /tmp/App.trace --toc 查看表结构,再用 --xpath 导出 time-profile 表到 XML,随后离线聚合。
限制与注意:iOS 设备需 --device <UDID>;无采样可能因应用退出过快,需延长录制并触发负载;xctrace 可能需要开发者工具权限;XML 导出体积大,应过滤后离线处理;需调试符号才能获得有意义的栈。