Analyze profiles with AI

Because ProfilingManager profiles use the standard Perfetto format and can be queried with PerfettoSQL, you can pair an AI coding agent with the Perfetto AI skill to automate root-cause analysis directly in your workspace instead of manually navigating timelines in the Perfetto UI or writing custom queries against the Perfetto Standard Library:

  1. Load the profile: The agent opens the collected profile using Perfetto's trace_processor.
  2. Execute diagnostic queries: Guided by the Perfetto AI skill, the agent queries standard library modules (such as android.frames.timeline for jank or android.memory.heap_graph.dominator_tree for memory leaks) and iteratively refines its queries.
  3. Correlate with source code: The agent maps custom trace slices, sampled call stacks, or retaining class names in the profile directly to your Kotlin or Java source files and proposes a fix.

Set up the Perfetto AI skill

The open source Perfetto AI skill teaches coding agents how to run trace_processor, write PerfettoSQL, and follow guided workflows for Android memory and CPU analysis. Each install bundles a trace_processor wrapper, so you don't need to install trace_processor separately:

  • Install with AI: Run the following prompt in any AI coding agent:

    Following instructions from https://perfetto.dev/docs/getting-started/using-ai set up the Perfetto AI skill to be usable by any agent
    
  • Install manually: Follow the setup instructions in Using AI with Perfetto for your agent (such as Claude Code, Codex, Cursor, Antigravity, or OpenCode).

Workflow examples

Place one or more captured profiles in your workspace and prompt your AI agent to investigate. You can analyze a single profile to diagnose an individual issue or pass multiple profiles to compare patterns and regressions in bulk.

Analyze Java heap dumps and OOMs

When you provide a Java heap dump captured directly with PROFILING_TYPE_JAVA_HEAP_DUMP or automatically through the TRIGGER_TYPE_OOM trigger, an AI agent using the Perfetto AI skill can help you identify:

  • Memory leaks: Objects, such as destroyed Activity or Fragment instances, that remain reachable from GC roots when they should have been reclaimed.
  • Heavily duplicated objects: Classes with an unexpectedly high instance count that collectively consume a large share of the heap.
  • Memory inefficiencies: Oversized caches, redundant data structures, or single dominator objects retaining a disproportionate amount of memory.

To investigate an OutOfMemoryError heap dump and correlate it with your app's source code, run a prompt like the following:

Analyze the Perfetto OOM heap dump at </path/to/profile>, which corresponds to
the codebase located at </path/to/codebase> using the Perfetto AI skill and find
the root cause of the OutOfMemoryError.

To see a complete example of the report this prompt generates, including the dominator tree retention path, source-code root cause, and proposed fix, see Automate the OOM investigation with an AI agent in Case study: Debug an OOM crash.

Analyze system traces and ANRs

When you provide a system trace captured directly with PROFILING_TYPE_SYSTEM_TRACE or automatically through the TRIGGER_TYPE_ANR trigger, an AI agent using the Perfetto AI skill can help you identify:

  • Blocking main-thread operations: Long-running trace slices or synchronous calls that prevent the UI thread from processing input events or drawing frames before the ANR threshold.
  • Thread state bottlenecks: Intervals where the main thread is stuck in Sleeping (such as blocking network I/O or Thread.sleep timeouts), Blocked (lock contention), or Runnable (CPU scheduling delays) states.
  • Main-thread CPU spikes: Expensive computations or tight loops executing directly on the UI thread instead of a background thread.

To investigate an ANR system trace and correlate it with your app's source code, run a prompt like the following:

Analyze the Perfetto system trace at </path/to/trace.perfetto-trace>, which
corresponds to an ANR trace, and find the root cause of the ANR using the
Perfetto AI skill. The codebase is located at </path/to/codebase>.

To see a complete example of the report this prompt generates, including the main-thread slice breakdown, thread_state interval reconstruction, and source-code mapping, see Automate the ANR investigation with an AI agent in Case study: Debug an ANR.