SuperAPI AI 工具集

axiom-xctrace-ref

部署与运维

查看项目

更新于 10-16 00:23

技能介绍

用途:xctrace 是 Instruments.app 背后的命令行工具,用于自动化性能分析、无头 trace 采集、通过 XML 导出进行程序化分析,以及性能回归检测。需 Xcode 12+(xctrace 12.0+),资料基于 Xcode 26.2 测试。

主要能力:可录制 CPU、内存分配、泄漏、SwiftUI、Swift 并发等 trace;列出可用 instruments 与 templates;通过 --toc 查看数据表,用 XPath 导出指定 schema 的表(如 cpu-profile、process-info、thread-info)。支持按进程名、PID、全部进程或启动方式指定目标,可指定模拟器或物理设备。

必要用法:录制示例 xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output profile.trace;导出示例 xcrun xctrace export --input profile.trace --toc 与 xcrun xctrace export --input profile.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]';列出 xcrun xctrace list instruments 与 xcrun xctrace list templates。常用选项包括 --output、--time-limit、--no-prompt、--append-run、--run-name。

适用场景:CI/CD 性能测试脚本、前后版本对比、无头性能分析。

限制:部分 instrument 需隐私权限;物理设备需开启开发者模式;后台应用分析受限;导出仅支持 XML,无 JSON;Xcode 26+ 建议用 --instrument 而非 --template,否则导出可能报 Document Missing Template Error;符号化需 dSYM。