Perfetto Documentation
repository·main·Indexed 27 days ago
https://github.com/google/perfettoAn open-source suite of SDKs, daemons, and tools for system profiling, application tracing, and trace analysis, used extensively in Android and Chromium. Documentation covers the Perfetto Rust SDK (including crates like perfetto-sdk, perfetto-sdk-sys, and protobuf bindings for GPU and Trace Processor), AI agent extension manifests, and the Perfetto Skills architecture for AI-driven trace analysis.
What's inside Perfetto
- The Perfetto Rust SDK provides safe and idiomatic Rust bindings for the Perfetto tracing framework. It allows Rust applications to produce and consume trace data, record track events, and integrate with existing Perfetto infrastructure. The SDK is composed of several crates designed to provide varying levels of abstraction:
Overview of Perfetto components
mainPerfetto is an open-source suite of tools for system profiling, app tracing, and trace analysis. It consists of several key components:
- High-performance tracing daemons: Capture tracing information from multiple processes on a single machine into a unified trace file.
- Low-overhead tracing SDK: Enables direct userspace-to-userspace tracing of timings and state changes in C/C++ code. A community-maintained Rust SDK is also available.
- OS-level probes: Extensive probes on Android and Linux for capturing system-level context like scheduling states, CPU frequencies, memory profiling, and callstack sampling.
- Browser-based UI: A fully local, browser-based tool for visualizing complex, interconnected data on a timeline. It works offline and supports various trace formats.
- SQL-based analysis library: A powerful library for programmatically analyzing large amounts of complex data using SQL, even for data not collected via Perfetto.
Overview of Perfetto UI Automation Commands
mainPerfetto UI provides a stable command surface designed specifically for automation. Unlike internal UI commands, these stable commands have backwards compatibility guarantees and are intended for use in:
- Startup commands: Automatically configuring the UI state when a trace is loaded.
- Macros: Creating reusable workflows for complex analysis tasks.
- Deep linking: Sharing pre-configured views via URLs or
postMessage.
Commands not listed in the automation reference are considered internal implementation details and may change without notice.
Overview of the Data Explorer
mainThe Data Explorer is an interactive tool for exploring trace data using a visual pipeline approach instead of writing manual SQL. You build analysis by connecting nodes on a canvas, starting from a data source and chaining operations like filters, aggregations, and joins.
Key capabilities include:
- No SQL required: Use visual nodes to perform complex operations like joins or conditional expressions.
- Trace-specific operations: Specialized support for intersecting time intervals and pairing start/end events.
- Live results: See data updates in real-time in an interactive data grid.
- Visualizations: Attach Charts nodes to create graphs or dashboards.
- Persistence: Save and share query graphs as JSON files or via permalinks.
Overview of Bigtrace Architecture
mainBigtrace is a tool designed to process millions of traces by distributing TraceProcessor instances across a Kubernetes cluster. The architecture consists of four main components:
- Client: Interfaces for interacting with Bigtrace. Supported clients include a Python API (part of the Perfetto python library), clickhouse-client (CLI for SQL queries via gRPC), and Apache Superset (GUI for SQL and visualization).
- Orchestrator: The central component that shards traces to Worker pods and streams results back to the Client.
- Worker: Individual pods running an instance of TraceProcessor to execute queries on specific traces.
- Object Store (GCS): Stores the traces queried by the service. Currently supports Google Cloud Storage (GCS) or local traces for testing.
Overview of Perfetto
mainPerfetto is an open-source stack designed for performance instrumentation and trace analysis. It provides tools for recording system-level and application-level traces, performing native and Java heap profiling, analyzing traces using SQL, and visualizing large (multi-GB) traces through a web-based UI.Overview of PerfettoSQL
mainPerfettoSQL is a SQL dialect used to query trace contents as if they were a database. It is interpreted by the Trace Processor engine and allows for programmatic data extraction. You can use PerfettoSQL to:
- Extract performance data from traces.
- Create custom visualizations (Debug tracks) for complex analyses.
- Create derived metrics.
- Identify performance bottlenecks using data-driven logic.
Overview of perfetto-sdk features
mainThe
perfetto-sdkprovides safe and ergonomic Rust bindings for the Perfetto tracing framework. Key capabilities include:- Track events: Record events using categories, names, and typed arguments.
- Data sources: Implement custom trace data sources.
- Protozero encoding: Uses pure Rust encoding for minimal overhead.
- Tracing sessions: Programmatically manage trace collection sessions.
Understand Perfetto Protobuf definition groups
mainPerfetto's Protobuf definitions are organized into three distinct functional groups depending on whether they represent trace output, configuration input, or inter-process communication:
trace/: Contains all Protobuf definitions that are output by Perfetto during trace capture.config/: Contains configuration definitions used as input, including:- The global trace configuration sent by a Consumer to the Perfetto trace daemon.
- Per-data-source configurations relayed by the trace daemon to Producers.
- Per-data-source descriptors advertised by Producers when registering with the trace daemon.
ipc/: Defines the IPC (Inter-Process Communication) surface between Perfetto components (Producers, trace daemon, and Consumers). This is primarily relevant for specific build configurations, such as Android, and is not used in Chrome.
Native (C/C++/Rust) Allocation Profiling Overview
mainNative heap profiling intercepts
malloc/freecalls to track the callstack of memory that has been allocated but not yet freed. This allows you to identify the 'code origin' of memory usage.Important Constraints:
- Platform Support: Only works on Android and Linux.
- Non-Retroactive: Profiling only reports allocations that occur after the trace has started. To capture startup allocations, you must begin tracing before the process is launched.
- Overhead Mitigation: Supports sampling to trade off accuracy for lower performance overhead.
Understand the Tracing Protocol ABI
mainThe Perfetto Tracing Protocol ABI is a binary-stable interface that allows processes to contribute tracing data to the tracing service. It consists of three main components:
- Socket protocol: A
SOCK_STREAMUNIX socket interface for communication. - Shared memory layout (SMB): A high-performance staging area for asynchronous data writes.
- Protobuf messages: The data contract used for all communication.
The ABI is designed for backward and forward compatibility and has remained stable since Android 9.
- Socket protocol: A
Understand Perfetto Skills architecture
mainPerfetto Skills are model-agnostic instructions designed to teach AI agents how to perform specific tasks with Perfetto (e.g., querying tables, interpreting results).
All Perfetto knowledge is consolidated into a single skill located at
ai/skills/perfetto/. This skill uses a router pattern: a lean entry point (SKILL-template.md) that dispatches to specialized files to keep the agent's context budget efficient.File Types:
- Workflows (
workflows/<domain>/*.md): Domain-specific guided investigations (e.g., Android memory, Chrome jank). These are self-contained and include their own queries and helper scripts in a siblingscripts/directory. - Infra-references (
infra-references/*.md): Domain-agnostic mechanics, such as how to runtrace_processoror usePerfettoSQL. - Environment-references (
environment-references/*.md): Instructions for environment setup, including how to set$SKILL_ROOTand use the bundledtrace_processor.
- Workflows (