介绍
# Native App Performance (CLI-only)
目标:通过 `xctrace` 记录时间分析器,提取样本,进行符号化,并在不打开 Instruments 的情况下找出热点。
## 快速开始 (CLI)
1) 记录时间分析器 (附加):
```bash # Start app yourself, then attach xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --attach <pid> ```
2) 记录时间分析器 (启动):
```bash xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --launch -- /path/App.app/Contents/MacOS/App ```
3) 提取时间样本:
```bash scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml ```
4) 获取符号化所需的加载地址:
```bash # While app is running vmmap <pid> | rg -m1 "__TEXT" -n ```
5) 符号化 + 热点排名:
```bash scripts/top_hotspots.py --samples /tmp/time-sample.xml \ --binary /path/App.app/Contents/MacOS/App \ --load-address 0x100000000 --top 30 ```
## 工作流注意事项
- 始终确认您分析的是正确的二进制文件(本地构建 vs /Applications)。对于 `--launch`,优先使用直接的二进制路径。 - 确保在录制期间触发了慢速路径(菜单打开/关闭、刷新等)。 - 如果堆栈为空,请延长录制时间或避开空闲时段。 - `xcrun xctrace help record` 和 `xcrun xctrace help export` 会显示正确的标志。
## 包含的脚本
- `scripts/record_time_profiler.sh`:通过附加或启动进行录制。 - `scripts/extract_time_samples.py`:从跟踪中导出时间样本 XML。 - `scripts/top_hotspots.py`:对顶层应用帧进行符号化并排名。
## 注意事项
- ASLR 意味着您必须使用 `vmmap` 中的运行时 `__TEXT` 加载地址。 - 如果使用新构建,请更新 `--binary` 路径;符号必须与跟踪匹配。 - 仅限 CLI 流程:如果堆栈通过 `atos` 进行了符号化,则无需打开 Instruments。