SuperAPI AI 工具集

axiom-xctrace-ref

部署与运维

查看项目

更新于 10-15 20:11

技能介绍

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

主要能力:可录制 CPU、内存分配、泄漏、SwiftUI、Swift 并发等 trace;支持按进程名、PID、全部进程或启动方式指定目标,可指定模拟器或真机设备;支持 --time-limit、--output、--no-prompt、--append-run、--run-name 等录制选项。导出时先用 --toc 查看数据表,再用 --xpath 按 schema 导出,如 cpu-profile、process-info、thread-info。

使用方式:录制示例 xcrun xctrace record --instrument 'CPU Profiler' --attach 'MyApp' --time-limit 10s --output profile.trace;导出示例 xcrun xctrace export --input profile.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="cpu-profile"]'。可用 xcrun xctrace list instruments 与 list templates 查看可用项。配套工具 sample 可做快速 CPU 采样,filtercalltree 可反转调用树、归因库开销与裁剪噪声。

适用场景:CI/CD 流水线中的自动化性能测试、前后版本对比、无 GUI 的 headless 分析。

限制:部分 instrument 需隐私权限;真机分析需开启开发者模式;后台应用分析受限;导出仅支持 XML,无 JSON;Xcode 26+ 中模板可能导出失败,建议改用 --instrument。符号化需提供 dSYM。