-
Notifications
You must be signed in to change notification settings - Fork 118
feat(profiling): Add Perfetto trace format support #5659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
markushi
wants to merge
49
commits into
master
Choose a base branch
from
feat/markushi/perfetto-profiling-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 41 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
405a5c1
feat(profiling): Add Perfetto trace format support
markushi 1687276
style(profiling): Format Perfetto module with cargo fmt
markushi 2cbf111
fix(profiling): Remove private intra-doc link in expand_perfetto
markushi 9ee2661
Merge remote-tracking branch 'origin/master' into feat/markushi/perfe…
markushi 9d4693c
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi 4407d9e
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi e67fa58
Extend profile chunk to support blob attachment via meta_length
markushi c4fa16e
Improve code generation script and docs
markushi 1e6df1f
Guard perfetto processing by feature flag
markushi 0a58b24
Address some more PR comments, add missing tests
markushi f729460
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi 685ec0a
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi 49f3bd9
feat(profiling): Use separate intern tables per Perfetto field and in…
markushi 5c6e457
fix(profiling): Fix clippy lint and add changelog entry
markushi 2f78475
fix(profiling): Apply first timestamp delta in StreamingProfilePacket
markushi 6e5f11c
fix(profiling): Resolve thread ID for StreamingProfilePacket via Trac…
markushi 06467d1
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi 253120d
fix(profiling): Resolve Perfetto samples eagerly to survive increment…
markushi ff63cc3
fix(profiling): Avoid redundant full JSON parse to extract content_type
markushi 1c1dad6
fix(profiling): Check content_type before calling expand_perfetto
markushi 1e14dc6
fix(profiling): Read content_type from metadata and remove dead write
markushi b2f35cb
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi a58ed23
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi 6e8987b
Address PR feedback
markushi b105db6
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi f3f0496
Add e2e tests, remove packets which weren't need for Android profiling
markushi e1c0bac
Ensure profile meta data is not dropped
markushi 34acd48
Fix lint errors
markushi 7238762
Address PR feedback
markushi 8899544
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi db555e6
Update Changelog
markushi 75b8fee
Simplify python tests, don't overwrite timeouts
markushi ad44bf3
Make comments doc friendly
markushi 338c601
Improve ownership handling, introduce helper function for intern_strings
markushi afb382f
Use uuid::Uuid::from_bytes_le, avoid uncessary hex/string roundtrip
markushi 0990673
Apply style suggestions
markushi aecdb7c
Add doc for new pub struct DebugImage
markushi ac8dc49
Fix unneeded rename
markushi 9945807
Merge branch 'master' into feat/markushi/perfetto-profiling-support
markushi d057317
Fix Changelog
markushi b46f029
Merge branch 'master' into feat/markushi/perfetto-profiling-support
jjbayer d34106a
fix: Manually parse trace packets
jjbayer a6fd768
comment
jjbayer c5ae574
keep optional optional
jjbayer bef7f17
lint
jjbayer dd8d044
restore local unwrap_or
jjbayer be742c9
Merge branch 'master' into feat/markushi/perfetto-profiling-support
jjbayer 5fd1156
fix: upper bound for frame_ids
jjbayer bef7314
bound on path segments
jjbayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Perfetto Proto Definitions | ||
|
|
||
| `perfetto_trace.proto` contains a minimal subset of the | ||
| [Perfetto trace proto definitions](https://github.com/google/perfetto/tree/master/protos/perfetto/trace) | ||
| needed to decode profiling data. Field numbers match the upstream definitions. | ||
|
|
||
| The generated Rust code is checked in at `../src/perfetto/proto.rs`. | ||
|
|
||
| ## Regenerating | ||
|
|
||
| Prerequisites: | ||
| - `protoc`: https://github.com/protocolbuffers/protobuf/releases (or `brew install protobuf`) | ||
| - `protoc-gen-prost`: `cargo install protoc-gen-prost` | ||
|
|
||
| Then run: | ||
| ```sh | ||
| ./relay-profiling/protos/generate.sh | ||
| ``` |
|
jjbayer marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Regenerates the checked-in Rust protobuf bindings for Perfetto trace types | ||
| # using protoc with the protoc-gen-prost plugin. | ||
| # | ||
| # Usage: | ||
| # ./relay-profiling/protos/generate.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| PROTO_FILE="$SCRIPT_DIR/perfetto_trace.proto" | ||
| OUTPUT_FILE="$SCRIPT_DIR/../src/perfetto/proto.rs" | ||
|
|
||
| if ! command -v protoc &>/dev/null; then | ||
| echo "error: protoc is not installed." >&2 | ||
| echo " Install it from https://github.com/protocolbuffers/protobuf/releases" >&2 | ||
| echo " or: brew install protobuf" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "Using protoc: $(command -v protoc) ($(protoc --version))" | ||
|
|
||
| if ! command -v protoc-gen-prost &>/dev/null; then | ||
| echo "error: protoc-gen-prost is not installed." >&2 | ||
| echo " Install it with: cargo install protoc-gen-prost" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "Using protoc-gen-prost: $(command -v protoc-gen-prost)" | ||
|
|
||
| if [[ ! -f "$PROTO_FILE" ]]; then | ||
| echo "error: proto file not found at $PROTO_FILE" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| TMPDIR="$(mktemp -d)" | ||
| trap 'rm -rf "$TMPDIR"' EXIT | ||
|
|
||
| echo "Generating Rust bindings..." | ||
| protoc \ | ||
| --prost_out="$TMPDIR" \ | ||
| --proto_path="$SCRIPT_DIR" \ | ||
| "$PROTO_FILE" | ||
|
|
||
| # protoc-gen-prost mirrors the proto package path in the output directory. | ||
| GENERATED=$(find "$TMPDIR" -name '*.rs' -type f | head -1) | ||
|
|
||
| if [[ -z "$GENERATED" || ! -f "$GENERATED" ]]; then | ||
| echo "error: no generated .rs file found in $TMPDIR" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ ! -s "$GENERATED" ]]; then | ||
| echo "error: generated file is empty" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| cp "$GENERATED" "$OUTPUT_FILE" | ||
| echo "Updated $OUTPUT_FILE" | ||
| echo "Done." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Minimal subset of the Perfetto trace proto definitions needed to decode | ||
| // profiling data. Field numbers match the upstream definitions at | ||
| // https://github.com/google/perfetto/tree/master/protos/perfetto/trace | ||
|
|
||
| syntax = "proto2"; | ||
| package perfetto.protos; | ||
|
|
||
| message Trace { | ||
| repeated TracePacket packet = 1; | ||
| } | ||
|
|
||
| message TracePacket { | ||
| optional uint64 timestamp = 8; | ||
|
|
||
| oneof optional_trusted_packet_sequence_id { | ||
| uint32 trusted_packet_sequence_id = 10; | ||
| } | ||
|
|
||
| optional InternedData interned_data = 12; | ||
| optional uint32 sequence_flags = 13; | ||
|
|
||
| // Only the oneof variants we care about; prost will skip the rest. | ||
| oneof data { | ||
| ClockSnapshot clock_snapshot = 6; | ||
| PerfSample perf_sample = 66; | ||
| } | ||
| } | ||
|
|
||
| // --- clock sync --------------------------------------------------------------- | ||
|
|
||
| message ClockSnapshot { | ||
| message Clock { | ||
| optional uint32 clock_id = 1; | ||
| optional uint64 timestamp = 2; | ||
| } | ||
| repeated Clock clocks = 1; | ||
| optional uint32 primary_trace_clock = 2; | ||
| } | ||
|
|
||
| // --- interned data ----------------------------------------------------------- | ||
|
|
||
| message InternedData { | ||
| repeated InternedString function_names = 5; | ||
| repeated Frame frames = 6; | ||
| repeated Callstack callstacks = 7; | ||
| repeated InternedString build_ids = 16; | ||
| repeated InternedString mapping_paths = 17; | ||
| repeated Mapping mappings = 19; | ||
| } | ||
|
|
||
| message InternedString { | ||
| optional uint64 iid = 1; | ||
| optional bytes str = 2; | ||
| } | ||
|
|
||
| // --- profiling common -------------------------------------------------------- | ||
|
|
||
| message Frame { | ||
| optional uint64 iid = 1; | ||
| optional uint64 function_name_id = 2; | ||
| optional uint64 mapping_id = 3; | ||
| optional uint64 rel_pc = 4; | ||
| } | ||
|
|
||
| message Mapping { | ||
| optional uint64 iid = 1; | ||
| optional uint64 build_id = 2; | ||
| optional uint64 start_offset = 3; | ||
| optional uint64 start = 4; | ||
| optional uint64 end = 5; | ||
| optional uint64 load_bias = 6; | ||
| repeated uint64 path_string_ids = 7; | ||
| optional uint64 exact_offset = 8; | ||
| } | ||
|
|
||
| message Callstack { | ||
| optional uint64 iid = 1; | ||
| repeated uint64 frame_ids = 2; | ||
| } | ||
|
|
||
| // --- profiling packets ------------------------------------------------------- | ||
|
|
||
| message PerfSample { | ||
| optional uint32 cpu = 1; | ||
| optional uint32 pid = 2; | ||
| optional uint32 tid = 3; | ||
| optional uint64 callstack_iid = 4; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.