跳到正文
Skillpedia
通用编程7.4k · #13237

native-app-performance

它能做什么

这个技能使用 Apple 的命令行工具录制 Time Profiler 跟踪,然后在不打开 Instruments 的情况下对热点进行排名。适合排查原生应用运行缓慢问题的开发者。

适用场景

  • ✓原生 Mac 或 iOS 应用运行缓慢,你想找出耗时的代码的时候。
  • ✓你希望从命令行录制应用的性能数据,而不是在应用内录制的时候。
  • ✓跟踪结果的调用栈为空,需要重新捕获缓慢操作的时候。

技能链接

https://github.com/steipete/agent-scripts/blob/main/skills/native-app-performance/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/steipete/agent-scripts/blob/main/skills/native-app-performance/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请在我执行缓慢操作时,为我的应用录制 90 秒的性能跟踪,并列出最主要的热点。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体使用 xctrace 工具录制跟踪,提取时间采样数据,找到加载地址,并用随附的脚本对最耗时的函数进行排名。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Native App Performance (CLI-only)

Goal: record Time Profiler via xctrace, extract samples, symbolicate, and propose hotspots without opening Instruments.

Quick start (CLI)

  1. Record Time Profiler (attach):
# Start app yourself, then attach
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --attach <pid>
  1. Record Time Profiler (launch):
xcrun xctrace record --template 'Time Profiler' --time-limit 90s --output /tmp/App.trace --launch -- /path/App.app/Contents/MacOS/App
  1. Extract time samples:
scripts/extract_time_samples.py --trace /tmp/App.trace --output /tmp/time-sample.xml
  1. Get load address for symbolication:
# While app is running
vmmap <pid> | rg -m1 "__TEXT" -n
  1. Symbolicate + rank hotspots:
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.

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.

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.
常见问题

我需要打开 Instruments 吗?

不需要。技能在命令行中完成性能分析,无需打开 Instruments。

为什么跟踪结果可能不准确?

技能警告,可能分析到了错误的应用副本,因此应指定确切的二进制路径。

如果调用栈为空怎么办?

技能建议延长录制时间,或避开空闲的部分。

详情

作者的原始描述

Native app performance: xctrace, Time Profiler, traces, hotspots.

repo: steipete/agent-scripts

热度

GitHub 星标
7.4k
排名
#13237
许可证
MIT
更新时间
2026/10/30

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能