native-app-performance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNative App Performance (CLI-only)
原生应用性能分析(仅CLI方式)
Goal: record Time Profiler via , extract samples, symbolicate, and propose hotspots without opening Instruments.
xctrace目标:通过录制Time Profiler追踪,提取样本、符号化并找出性能热点,无需打开Instruments。
xctraceQuick start (CLI)
快速开始(CLI方式)
- Record Time Profiler (attach):
bash
undefined- 录制Time Profiler(附加进程):
bash
undefinedStart app yourself, then attach
自行启动应用,然后附加进程
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --attach <pid>
2) Record Time Profiler (launch):
```bash
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --launch -- /path/App.app/Contents/MacOS/App- Extract time samples:
bash
scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml- Get load address for symbolication:
bash
undefinedxcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --attach <pid>
2) 录制Time Profiler(启动应用):
```bash
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --launch -- /path/App.app/Contents/MacOS/App- 提取时间样本:
bash
scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml- 获取符号化所需的加载地址:
bash
undefinedWhile app is running
应用运行时执行
vmmap <pid> | rg -m1 "__TEXT" -n
5) Symbolicate + rank hotspots:
```bash
scripts/top_hotspots.py --samples /tmp/time-sample.xml \
--binary /path/App.app/Contents/MacOS/App \
--load-address 0x100000000 --top 30vmmap <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 30Workflow notes
工作流注意事项
- Always confirm you’re profiling the correct binary (local build vs /Applications). Prefer direct binary path for .
--launch - Ensure you trigger the slow path during capture (menu open/close, refresh, etc.).
- If stacks are empty, capture longer or avoid idle sections.
- and
xcrun xctrace help recordshow correct flags.xcrun xctrace help export
- 始终确认你正在剖析的是正确的二进制文件(本地构建版本 vs /Applications目录下的版本)。使用参数时,优先指定直接的二进制文件路径。
--launch - 确保在捕获过程中触发慢路径操作(如打开/关闭菜单、刷新等)。
- 如果调用栈为空,延长捕获时间或避免在空闲时段捕获。
- 和
xcrun xctrace help record命令可查看正确的参数选项。xcrun xctrace help export
Included scripts
包含的脚本
- : record via attach or launch.
scripts/record_time_profiler.sh - : export time-sample XML from a trace.
scripts/extract_time_samples.py - : symbolicate and rank top app frames.
scripts/top_hotspots.py
- :通过附加进程或启动应用的方式录制追踪。
scripts/record_time_profiler.sh - :从追踪文件导出时间样本XML。
scripts/extract_time_samples.py - :对应用的调用栈帧进行符号化并排序出Top热点。
scripts/top_hotspots.py
Gotchas
注意事项
- ASLR means you must use the runtime load address from
__TEXT.vmmap - If using a new build, update the path; symbols must match the trace.
--binary - CLI-only flow: no need to open Instruments if stacks are symbolicated via .
atos
- ASLR意味着你必须使用获取运行时的
vmmap段加载地址。__TEXT - 如果使用新构建的应用,更新路径;符号必须与追踪文件匹配。
--binary - 仅CLI流程:如果通过完成符号化,无需打开Instruments。
atos