AgentSkillsCN

instruments-trace-viewer

使用 xctrace 查看并分析 Apple Instruments 的 .trace 文件。当用户需要检查跟踪记录的内容、导出性能分析数据、提取 Time Profiler 样本、Allocations 数据,或是将 Instruments 记录的任意数据转换为 XML 格式时,此工具将助您一臂之力。

SKILL.md
--- frontmatter
name: instruments-trace-viewer
description: View and analyze Apple Instruments .trace files using xctrace. Use when asked to inspect trace contents, export profiling data, extract Time Profiler samples, Allocations, SwiftUI metrics, or any Instruments-recorded data to XML format.

Instruments Trace Viewer

Workflow

1. Export Table of Contents

bash
xctrace export --input /path/to/recording.trace --toc

The TOC XML reveals available runs, schema names, and processes.

2. Query Specific Data

Extract tables using schema names from the TOC:

bash
xctrace export --input recording.trace \
  --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-sample"]' \
  --output samples.xml

Common schemas: time-sample, allocation, leak, os-signpost, http-transaction

3. Symbolicate if Needed

When stack traces show addresses instead of function names:

bash
xctrace symbolicate --input recording.trace --dsym /path/to/MyApp.dSYM

dSYM locations: ~/Library/Developer/Xcode/Archives/, DerivedData/<project>/Build/Products/

Essential Commands

CommandPurpose
xctrace export --input <file> --tocList all tables and schemas
xctrace export --input <file> --xpath '<expr>'Extract specific data
xctrace export --input <file> --har --output <file>.harExport network data as HAR
xctrace symbolicate --input <file> --dsym <path>Add symbol names to traces

TOC Structure

xml
<trace-toc>
  <run number="1">
    <data>
      <table schema="time-sample" />
      <table schema="allocation" />
    </data>
    <processes>
      <process name="MyApp" pid="12345">
        <binary name="MyApp" UUID="..." />
      </process>
    </processes>
  </run>
</trace-toc>

XPath Patterns

bash
# All data from a table
--xpath '/trace-toc/run[@number="1"]/data/table[@schema="<schema>"]'

# Process binaries
--xpath '/trace-toc/run[@number="1"]/processes/process[@name="MyApp"]/binary'

# All runs
--xpath '/trace-toc/run/data/table[@schema="time-sample"]'

Template-Specific References

Consult these for detailed XPath patterns and output interpretation:

  • Time Profiler: references/time-profiler.md
  • Allocations: references/allocations.md
  • Leaks: references/leaks.md
  • SwiftUI: references/swiftui.md
  • App Launch: references/app-launch.md
  • Network: references/network.md
  • File Activity: references/file-activity.md
  • Metal System Trace: references/metal-system-trace.md
  • CPU Counters: references/cpu-counters.md
  • Signposts & Points of Interest: references/signposts-poi.md

Troubleshooting

  • Empty output: Schema may not exist—export TOC first to verify available schemas
  • Unsymbolicated after symbolication: Verify dSYM UUID matches binary UUID with dwarfdump --uuid MyApp.dSYM
  • XPath returns nothing: Check run number exists and schema name is case-sensitive exact match