native-app-performance

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Native App Performance (CLI-only)

原生应用性能分析(仅CLI方式)

Goal: record Time Profiler via
xctrace
, extract samples, symbolicate, and propose hotspots without opening Instruments.
目标:通过
xctrace
录制Time Profiler追踪,提取样本、符号化并找出性能热点,无需打开Instruments。

Quick start (CLI)

快速开始(CLI方式)

  1. Record Time Profiler (attach):
bash
undefined
  1. 录制Time Profiler(附加进程):
bash
undefined

Start 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
  1. Extract time samples:
bash
scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml
  1. Get load address for symbolication:
bash
undefined
xcrun 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
  1. 提取时间样本:
bash
scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml
  1. 获取符号化所需的加载地址:
bash
undefined

While 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 30
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

Workflow 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.
  • xcrun xctrace help record
    and
    xcrun xctrace help export
    show correct flags.
  • 始终确认你正在剖析的是正确的二进制文件(本地构建版本 vs /Applications目录下的版本)。使用
    --launch
    参数时,优先指定直接的二进制文件路径。
  • 确保在捕获过程中触发慢路径操作(如打开/关闭菜单、刷新等)。
  • 如果调用栈为空,延长捕获时间或避免在空闲时段捕获。
  • xcrun xctrace help record
    xcrun xctrace help export
    命令可查看正确的参数选项。

Included scripts

包含的脚本

  • scripts/record_time_profiler.sh
    : record via attach or launch.
  • scripts/extract_time_samples.py
    : export time-sample XML from a trace.
  • scripts/top_hotspots.py
    : symbolicate and rank top app frames.
  • scripts/record_time_profiler.sh
    :通过附加进程或启动应用的方式录制追踪。
  • scripts/extract_time_samples.py
    :从追踪文件导出时间样本XML。
  • scripts/top_hotspots.py
    :对应用的调用栈帧进行符号化并排序出Top热点。

Gotchas

注意事项

  • ASLR means you must use the runtime
    __TEXT
    load address from
    vmmap
    .
  • If using a new build, update the
    --binary
    path; symbols must match the trace.
  • CLI-only flow: no need to open Instruments if stacks are symbolicated via
    atos
    .
  • ASLR意味着你必须使用
    vmmap
    获取运行时的
    __TEXT
    段加载地址。
  • 如果使用新构建的应用,更新
    --binary
    路径;符号必须与追踪文件匹配。
  • 仅CLI流程:如果通过
    atos
    完成符号化,无需打开Instruments。