analyze-perfetto-trace

Query Metro compiler perfetto traces to locate hot spots and untraced time.

1.4k|106|Updated Nov 5, 2024
One-click install
npx skills add https://github.com/ZacSweers/metro --skill analyze-perfetto-trace
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: analyze-perfetto-trace
Source: https://github.com/ZacSweers/metro/tree/main/.agents/skills/analyze-perfetto-trace
Command: npx skills add https://github.com/ZacSweers/metro --skill analyze-perfetto-trace

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires perfetto.

What problem does it solve?

When Metro's Kotlin compiler plugin feels slow, guessing from source code rarely identifies the real bottleneck. This Skill lets you query Metro's perfetto trace files directly with SQL to find actual hot spots, measure phase durations, and detect untraced time gaps inside compiler phases.

Core Features & Use Cases

  • Trace Querying: Run SQL against the perfetto slice table via the Python perfetto library to rank spans by duration, sum repeated spans by name, and drill into children of any phase.
  • Gap Analysis: Compare a parent span's duration against the sum of its direct children to find untraced work, then decide where to add trace(...) instrumentation.
  • Fresh Trace Generation: Produce new traces from a real project with ./metrow trace or from the in-repo benchmark with benchmark/trace_compile.sh, optionally opening them in ui.perfetto.dev.
  • Use Case: A user shares a perfetto screenshot showing a slow build. You query the trace, discover "Collect supertypes" takes 7.5ms while the suspected "Process declarations" takes only 1.2ms, and direct the optimization effort accordingly.

Quick Start

Analyze the Metro perfetto trace file I just shared and tell me where the compiler is spending the most time.

Frequently Asked Questions about analyze-perfetto-trace

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I analyze a perfetto trace file with Python?

Use the perfetto Python library's TraceProcessor to load the .perfetto-trace file, then run SQL queries against the slice table. Query name and dur columns ordered by duration to find the largest spans, and divide dur by 1e6 to convert nanoseconds to milliseconds.

How do I find where time is going in the Metro compiler?

Start with a top-level slice duration query ordered by dur descending, then drill into the largest phase by listing its direct children. Compare the sum of children to the parent duration; a large gap indicates untraced work that needs new trace instrumentation.

How do I generate a fresh Metro perfetto trace?

Run ./metrow trace with a target project directory and Gradle compile task, which publishes Metro locally, enables tracing, and copies the trace to tmp/traces. For benchmark iteration, use benchmark/trace_compile.sh against the generated benchmark project.

Why does pip install perfetto fail to import afterward?

The perfetto package installs against whichever Python pip points to, which may differ from the interpreter you invoke. On this setup it is installed for Python 3.13, so run queries with the python3.13 binary and verify with an import check first.

Can I compare durations between FIR and IR trace files?

No, FIR and IR traces are separate files with independent timelines, so durations cannot be directly compared across them. Group files by their shared timestamp prefix and analyze the fir-* or ir-* file matching the phase you are investigating.