This document explains how Perfetto's trace processor works, from ingesting raw trace files to providing SQL-queryable data. It covers the key components, data flow, and architectural patterns that enable the trace processor to handle traces from various formats (Proto, JSON, Systrace, etc.) and transform them into a unified analytical database.
The trace processor is a system that ingests trace files of various formats, parses their contents, sorts events by timestamp, and stores the data in a columnar SQL database for analysis. It processes traces in chunks to efficiently handle large files.
Raw Trace → ForwardingTraceParser → Format-Specific ChunkedTraceReader → TraceSorter → TraceStorage → SQL Query Engine
ForwardingTraceParser (src/trace_processor/forwarding_trace_parser.cc:95-134)
GuessTraceType() from first bytessrc/trace_processor/trace_reader_registry.h)src/trace_processor/importers/common/chunked_trace_reader.h)Format Registration (src/trace_processor/trace_processor_impl.cc:475-519)
context()->reader_registry->RegisterTraceReader<JsonTraceTokenizer>(kJsonTraceType); context()->reader_registry->RegisterTraceReader<ProtoTraceReader>(kProtoTraceType); context()->reader_registry->RegisterTraceReader<SystraceTraceParser>(kSystraceTraceType);
JsonTraceTokenizer (src/trace_processor/importers/json/json_trace_tokenizer.h:73)
ProtoTraceReader (src/trace_processor/importers/proto/proto_trace_reader.h:58)
src/trace_processor/importers/proto/proto_importer_module.h:110)src/trace_processor/importers/proto/)SystraceTraceParser (src/trace_processor/importers/systrace/systrace_trace_parser.h:34)
perf_importer::PerfDataTokenizer (binary perf.data format)gecko_importer::GeckoTraceTokenizer (Firefox traces)FuchsiaTraceTokenizer (Fuchsia kernel traces)TraceSorter (src/trace_processor/sorter/trace_sorter.h:43)
TraceStorage (src/trace_processor/storage/trace_storage.h)
TraceProcessorContext (src/trace_processor/types/trace_processor_context.h)
All format readers implement same interface but with completely different internal architectures:
Each format defines its own event types and creates typed streams:
Stream<JsonEvent> for JSON tracesStream<TracePacketData> for proto eventsStream<SystraceLine> for systrace linesCore Infrastructure:
src/trace_processor/forwarding_trace_parser.{h,cc} - Format detection and delegationsrc/trace_processor/trace_reader_registry.{h,cc} - Reader registrationsrc/trace_processor/sorter/trace_sorter.h - Event sortingsrc/trace_processor/storage/trace_storage.h - Columnar storageFormat Readers (examples):
src/trace_processor/importers/json/json_trace_tokenizer.h - JSON processingsrc/trace_processor/importers/proto/proto_trace_reader.h - Proto entry pointsrc/trace_processor/importers/proto/proto_importer_module.h - Proto module systemsrc/trace_processor/importers/systrace/systrace_trace_parser.h - Systrace processingRegistration:
src/trace_processor/trace_processor_impl.cc:475-519 - Where all readers are registered