RFC-0003: Simpleperf Proto Import Support #3176
Replies: 1 comment
-
📝 RFC Document Updated View changes: Commit History |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
📄 RFC Doc: 0003-simpleperf-proto-import.md
Simpleperf Proto Import Support
Authors: @lalitm
Status: Draft
Problem
Perfetto currently lacks support for importing profiling data from Android's Simpleperf tool in its protobuf format. Simpleperf is a widely-used native profiling tool on Android that can capture CPU profiles with call stacks. The tool can export data in a custom protobuf format (via
simpleperf report-sample --protobuf
), but Perfetto cannot currently parse this format.Without this capability, users who want to analyze Simpleperf profiles in Perfetto's UI or query them using SQL need to manually convert the data or use separate tools, creating friction in the profiling workflow.
Decision
Implement a new importer in Trace Processor to natively support the Simpleperf protobuf format. This will allow users to directly load Simpleperf profiles into Perfetto for analysis.
Design
File Format
The Simpleperf protobuf format follows this structure:
Each
Record
message is defined incmd_report_sample.proto
and can contain:--trace-offcpu
is used)A key advantage of this format is that Simpleperf performs symbolization before export, so symbol names are already resolved in the File records. Note that obfuscated symbols are not deobfuscated - that remains the responsibility of post-processing tools.
Implementation Components
1. Proto Definitions
Import the Simpleperf proto definition (
cmd_report_sample.proto
) intoprotos/third_party/simpleperf/
with namespaceperfetto.third_party.simpleperf.proto
to avoid conflicts with other proto definitions.The BUILD.gn configuration generates:
simpleperf.descriptor
) for diff test infrastructure2. Tokenizer (
simpleperf_proto_tokenizer.{cc,h}
)The tokenizer is responsible for parsing the binary file format and extracting individual records. It uses
TraceBlobViewReader
for efficient streaming parsing without copying data unnecessarily.State Machine:
kExpectingMagic
: Read and validate "SIMPLEPERF" magic (10 bytes)kExpectingVersion
: Read and validate version number (2 bytes, must be 1)kExpectingRecordSize
: Read 32-bit little-endian record sizekExpectingRecord
: Read the protobuf record data of the specified sizekFinished
: End marker (size=0) encountered, no more recordsRecord Processing:
Records are handled differently based on their type:
Metadata Records (File, MetaInfo, LostSituation):
ParseRecord()
Example for File records:
Thread Records:
SimpleperfProtoEvent
and pushed to trace sorter with this timestampTimestamped Records (Sample, ContextSwitch):
last_seen_timestamp_
for subsequent Thread recordsSimpleperfProtoEvent
and pushed to trace sorterThis design ensures:
3. Parser (
simpleperf_proto_parser.{cc,h}
)The parser receives sorted timestamped events (Sample, ContextSwitch, and Thread records) from the trace sorter. File/MetaInfo/LostSituation records have already been processed by the tokenizer.
Thread Records:
Thread records are processed in timestamp order to handle PID/TID reuse correctly:
Sample Records:
Sample records contain the actual profiling data:
ContextSwitch Records:
When
--trace-offcpu
is used, Simpleperf records thread scheduling events:4. Diff Test Infrastructure
Add
SimpleperfProto
class topython/generators/diff_tests/testing.py
:The trace generator in
trace_generator.py
serializes this into binary format:Tests can be written as:
5. Trace Type Detection
Add
kSimpleperfProtoTraceType
to theTraceType
enum and register detection logic:Register the reader in
TraceProcessorImpl
:Data Flow
Phased Implementation
Phase 1 (Current):
Phase 2:
Phase 3:
Open questions
kOther
)?💬 Discussion Guidelines:
Beta Was this translation helpful? Give feedback.
All reactions