Community研究与数据分析github.com

steipete/instruments-profiling

Instruments/xctrace 性能分析:macOS/iOS 跟踪、二进制文件、参数、导出。

instruments-profiling 是什么?

该技能为开发者提供了使用 Instruments 和 xctrace 命令行工具对 macOS 和 iOS 原生应用进行性能分析和堆栈捕获的完整指南。它专注于 Time Profiler 模板,详细说明了如何通过 CLI 启动或附加到进程进行性能记录,以及如何选择正确的二进制文件以避免 Instruments 分析到错误的应用实例(例如 LaunchServices 解析到已安装的正式版而非本地开发版)。该技能还涵盖了导出原始时间分析样本为 XML 以进行后处理、Instruments UI 工作流实用技巧以及 iOS 设备的特定注意事项。所有命令和步骤都针对 Apple 平台进行了优化,并指出了常见的陷阱(如隐私权限提示、空样本)及其解决方案。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/steipete/agent-scripts/tree/main/skills/instruments-profiling

Installed? Explore more 研究与数据分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Instruments 性能分析(macOS/iOS)

当用户需要对原生应用进行性能分析或堆栈分析时使用此技能。 重点:Time Profiler、xctrace CLI 以及选择正确的二进制文件/应用实例。

快速开始(CLI)

  • 列出模板:xcrun xctrace list templates
  • 记录 Time Profiler(启动):
    • xcrun xctrace record --template 'Time Profiler' --time-limit 60s --output /tmp/App.trace --launch -- /path/To/App.app
  • 记录 Time Profiler(附加):
    • 自行启动应用,获取 PID,然后:
    • xcrun xctrace record --template 'Time Profiler' --time-limit 60s --output /tmp/App.trace --attach <pid>
  • 在 Instruments 中打开跟踪:
    • open -a Instruments /tmp/App.trace

注意:xcrun xctrace --help 不是有效的子命令。请使用 xcrun xctrace help record。

选择正确的二进制文件(关键)

陷阱:Instruments 可能会分析错误的应用(例如,/Applications 中的那个),如果 LaunchServices 解析了不同的 bundle。

请使用以下规则:

  • 优先使用直接二进制路径以实现确定性启动:
    • xcrun xctrace record ... --launch -- /path/App.app/Contents/MacOS/App
  • 如果启动 .app,请确保它是预期的 bundle:
    • open -n /path/App.app
    • 使用 ps -p <pid> -o comm= -o command= 验证
  • 如果 /Applications/App.app 和本地构建同时存在,显式指定本地构建路径。
  • 启动后,在信任跟踪之前确认进程路径。

命令参数(xctrace)

  • --template 'Time Profiler':来自 xctrace list templates 的模板名称。
  • --launch -- <cmd>:-- 后的所有内容都是目标命令(二进制文件或应用 bundle)。
  • --attach <pid|name>:附加到正在运行的进程。
  • --output <path>:.trace 输出。如果省略,文件保存在当前工作目录。
  • --time-limit 60s|5m:设置捕获持续时间。
  • --device <name|UDID>:iOS 设备运行必需。
  • --target-stdout -:将启动进程的标准输出流式传输到终端(对 CLI 工具有用)。

导出堆栈(CLI)

  • 检查跟踪表:
    • xcrun xctrace export --input /tmp/App.trace --toc
  • 导出原始时间分析样本:
    • xcrun xctrace export --input /tmp/App.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]' --output /tmp/time-profile.xml
  • 在脚本(Python/Rust)中进行后处理以聚合堆栈。

Instruments UI 工作流

  • 模板:Time Profiler
  • 使用“记录”并捕获慢路径(启动 vs 稳态)
  • 调用树提示:
    • 隐藏系统库
    • 反转调用树
    • 按线程分离
    • 关注热点框架和调用次数

陷阱与修复

  • 分析到错误的应用:LaunchServices 解析已安装的应用而不是本机构建。
    • 修复:使用直接二进制路径或通过已知 PID 的 --attach。
  • 无样本/空跟踪:应用快速退出或从未执行工作负载。
    • 修复:更长的捕获时间,在录制期间触发工作负载。
  • 隐私提示:xctrace 可能需要“开发者工具”权限。
    • 修复:系统设置 → 隐私与安全性 → 开发者工具 → 允许 Terminal/Xcode。
  • 大型 XML 导出:time-profile 导出非常大。
    • 修复:使用 XPath 过滤并离线聚合;不要打印到终端。

iOS 相关说明

  • 设备:使用 xcrun xctrace list devices 和 --device <UDID>。
  • 如果需要,通过 Xcode 启动;使用 xctrace --attach 附加。
  • 确保有调试符号以获得有意义的堆栈。

验证检查清单

  • 确认跟踪进程路径与目标构建匹配。
  • 确认堆栈显示预期的应用框架。
  • 捕获覆盖慢速操作(启动/刷新)。
  • 导出堆栈以便在优化时进行自动差异比较。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

steipete/agent-transcript

GitHub PR/issue agent transcripts: redact, preview, and insert safely.

steipete/beeper

Beeper cache: contact hints, room lookup, WhatsApp/iMessage traces, FTS.

steipete/browser-use

Existing Chrome automation: Chrome plugin first, mcporter fallback.

steipete/clawsweeper-status

ClawSweeper status: URLs, workflow health, active workers, ops snapshot.

steipete/clickclack

ClickClack ops: chat app, Hetzner deploy, DNS/docs/app, Docker rollout.

steipete/cloudflare-registrar

Cloudflare Registrar: domain availability, prices, registration via mcporter.

steipete/codex-debugging

Codex debugging: codex-rs core/tui/exec/cli/app-server/config.

steipete/create-cli

CLI UX/spec: args, flags, help, output, errors, config, dry-run.

steipete/discord-clawd

Discord-backed OpenClaw agent/session relay; not archive search.

steipete/domain-dns-ops

DNS/domain ops: registrars, zones, redirects, DNS/HTTP verify, manager truth.

steipete/frontend-design

Frontend UI: pages, apps, components, polished non-generic design.

steipete/github-author-context

GitHub contributor context: identity, activity, trust, company/team signal.

steipete/github-cache-hygiene

GitHub quota/cache hygiene: gh, ghx, xcache, gitcrawl, mirrors, limits.

steipete/github-deep-review

GitHub deep review: bugs, PRs, best fix, stale-or-real, read code first.

steipete/github-project-triage

GitHub issue/PR triage: queues, CI, blockers, risk, proof, next actions.

steipete/hopper-debugger

Hopper debugging: macOS/iOS binaries, ObjC/Swift symbols, dyld, LLDB.

steipete/mac-maintenance

Mac upkeep: brew update/upgrade, pull clean repos, empty Trash.

steipete/maintainer-orchestrator

Open-source maintainer orchestration: Codex app workers, work recovery, dependencies, vision, releases.

steipete/markdown-converter

Markdown conversion: PDF, Office, HTML, data, OCR, audio, ZIP, YouTube.

steipete/nano-banana-pro

Nano Banana/Gemini image gen/edit: text/image input, 512-4K workflows.

相关技能