Trace Processor Architecture

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.

Overview

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.

Core Data Pipeline

Raw Trace → ForwardingTraceParser → Format-Specific ChunkedTraceReader → TraceSorter → TraceStorage → SQL Query Engine

Format Detection and Delegation

ForwardingTraceParser (src/trace_processor/forwarding_trace_parser.cc:95-134)

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);

Format-Specific Readers (Diverse Approaches)

1. JSON Traces

JsonTraceTokenizer (src/trace_processor/importers/json/json_trace_tokenizer.h:73)

2. Proto Traces (Complex Modular System)

ProtoTraceReader (src/trace_processor/importers/proto/proto_trace_reader.h:58)

3. Systrace (Line-Based Processing)

SystraceTraceParser (src/trace_processor/importers/systrace/systrace_trace_parser.h:34)

4. Other Formats

Event Sorting and Processing

TraceSorter (src/trace_processor/sorter/trace_sorter.h:43)

Storage Layer

TraceStorage (src/trace_processor/storage/trace_storage.h)

Context and Coordination

TraceProcessorContext (src/trace_processor/types/trace_processor_context.h)

Key Architectural Patterns

1. ChunkedTraceReader Interface

All format readers implement same interface but with completely different internal architectures:

2. TraceSorter::Stream Pattern

Each format defines its own event types and creates typed streams:

3. Parser vs Tokenizer Split

File Path Reference

Core Infrastructure:

Format Readers (examples):

Registration: