Perfetto is an open-source platform for system tracing, profiling and trace analysis, developed by Google and used as the default tracing system on Android since Android 9. In mobile performance work, it records what the kernel, the framework and individual apps are doing on a shared timeline, which lets engineers explain jank, slow app startup, ANRs, wake locks and battery drain with evidence rather than guesswork.
Perfetto replaced the older systrace workflow and extends far beyond it: it combines kernel ftrace events, userspace trace points, CPU and memory profiling and a SQL-based trace processor in one toolchain that also serves Chrome and Linux.
How Perfetto records a trace
Perfetto uses a producer and consumer architecture around a central tracing service. On Android, the traced daemon owns shared-memory buffers, producers such as traced_probes and instrumented apps write events into them, and a consumer such as the perfetto command-line tool starts the session and collects the result.
Each session is driven by a trace config, a protobuf text file that declares which data sources to enable, the buffer sizes, and the duration. The output is a single protobuf trace file, usually with the .perfetto-trace or .pftrace extension, that contains every event with nanosecond timestamps.
The main components and their roles are summarized below.
| Component | Role | Where it runs |
|---|---|---|
| traced | Central tracing service and buffer owner | Device daemon |
| traced_probes | Kernel ftrace, process and power data | Device daemon |
| perfetto CLI | Starts sessions and saves trace files | Device shell via adb |
| Track Event SDK | Custom app and library instrumentation | Inside the app process |
| Trace Processor | Parses traces into SQL tables | Host machine or browser |
| Perfetto UI | Timeline visualization and queries | Web browser, offline capable |
Data sources and profiling modes
The power of Perfetto comes from combining data sources in a single trace, so that a dropped frame can be correlated with CPU frequency, scheduler decisions, binder calls and garbage collection at the same instant. Choosing too many sources inflates the trace, so experienced engineers enable only what the question requires.
| Data source | Typical content | Questions it answers |
|---|---|---|
| ftrace scheduling | Thread states, CPU placement, wakeups | Why a thread was runnable but not running |
| atrace categories | Framework slices such as view, gfx, am | Where main-thread time went |
| CPU frequency and idle | Clock changes and idle states | Whether thermal or power limits slowed work |
| heapprofd | Sampled native allocations with call stacks | Which code grows native memory |
| Java heap dump | Object graph of the managed heap | What retains memory and causes leaks |
| Callstack sampling | Periodic CPU stack samples | Which functions consume CPU time |
| Battery and power rails | Counters from the power subsystem | Which component drains energy |
Recording happens in two buffer modes. Ring buffer mode keeps the most recent events in memory and overwrites old data, which suits short reproductions. Long trace mode periodically writes buffers to a file, which allows traces lasting minutes to hours at the cost of more storage and I/O.
Analyzing traces with SQL
Perfetto treats a trace as a queryable database. The Trace Processor imports the raw file into tables such as slice, thread_state, counter and process, and engineers query them with PerfettoSQL, a SQL dialect with a standard library of performance metrics.
This approach turns one-off investigations into repeatable analysis. A team can write a query that measures time to first frame or main-thread blocking, run it across hundreds of traces from a lab, and track the result over releases. Python bindings let the same queries run inside continuous integration pipelines.
The UI and the query engine serve different stages of an investigation.
| Approach | Strength | Best use |
|---|---|---|
| Timeline view | Shows causality across threads at a glance | Exploring a single jank or ANR |
| Ad hoc SQL query | Precise numbers from one trace | Measuring durations and counts |
| Batch trace analysis | Statistics across many traces | Regression detection and benchmarks |
Perfetto compared with other mobile profiling tools
Perfetto is the system-wide tracing layer, while other tools focus on narrower views or other platforms. The Android Studio Profiler uses Perfetto data internally for its system trace view but offers a simplified, app-focused interface. On iOS, Xcode Instruments fills a comparable role, and MetricKit and Android vitals provide aggregated field data rather than detailed traces.
| Tool | Platform | Scope | Data origin |
|---|---|---|---|
| Perfetto | Android, Chrome, Linux | Whole system, kernel to app | Lab or targeted field traces |
| Android Studio Profiler | Android | One debuggable app | Developer machine sessions |
| Xcode Instruments | iOS and macOS | App and system templates | Developer machine sessions |
| Android vitals | Android | Aggregated quality metrics | Production user devices |
In practice, field metrics reveal that a problem exists, and Perfetto traces explain why it happens. Mature teams connect the two by reproducing a vitals regression in the lab and capturing a focused trace.
Practical pitfalls when tracing
Trace quality depends heavily on setup discipline. Misleading traces usually come from configuration mistakes rather than from the tool itself.
- Debug builds distort timing: profile a release-like build with R8 and Baseline Profiles applied.
- Too small a buffer loses data: events overwritten in ring buffer mode leave gaps at the critical moment.
- Tracing has overhead: heavy ftrace categories or high sampling rates can change the behavior being measured.
- Missing app slices: without custom trace sections or the Track Event SDK, app code appears as anonymous main-thread time.
- Thermal state matters: a warm device throttles the CPU and produces slower, unrepresentative results.
The simple explanation
Perfetto works like a flight recorder for a phone. While an app runs, it writes down what every part of the system was doing, moment by moment, including the processor, the screen drawing and the memory.
Afterward, engineers replay the recording on a detailed timeline. When an app stutters or starts slowly, they can see exactly which task was waiting and why. Instead of guessing, they fix the real cause.
How it is used in practice
A team maintaining a shopping app sees in Android vitals that cold startup time on mid-range phones has risen from about 1.1 seconds to 1.8 seconds after a release. An engineer reproduces the launch on a comparable device, records a Perfetto trace with scheduling, atrace and CPU frequency enabled, and opens it in the Perfetto UI.
The timeline shows the main thread blocked for roughly 400 milliseconds on disk reads while a newly added analytics library loads its configuration during application creation. A PerfettoSQL query confirms the same pattern across ten repeated traces. The team moves the initialization to a background thread and defers it until after the first frame, and the next release brings startup back to about 1.1 seconds, which the lab traces and field metrics both confirm.