-
Notifications
You must be signed in to change notification settings - Fork 112
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
base: master
Are you sure you want to change the base?
Changes from 22 commits
405a5c1
1687276
2cbf111
9ee2661
9d4693c
4407d9e
e67fa58
c4fa16e
1e6df1f
0a58b24
f729460
685ec0a
49f3bd9
5c6e457
2f78475
6e5f11c
06467d1
253120d
ff63cc3
1c1dad6
1e14dc6
b2f35cb
a58ed23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| ``` |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not 100% sure what we discussed. Did we say we wanted the protobuf schema generation in a separate repository, like we have with sentry-conventions?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we talked about it, but it's actually a lot less than I thought it would be. Maybe we just treat it like |
| 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." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // 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 { | ||
| ProcessTree process_tree = 2; | ||
| ClockSnapshot clock_snapshot = 6; | ||
| StreamingProfilePacket streaming_profile_packet = 54; | ||
| TrackDescriptor track_descriptor = 60; | ||
| PerfSample perf_sample = 66; | ||
| } | ||
| } | ||
|
|
||
| // --- process tree ------------------------------------------------------------ | ||
|
|
||
| message ProcessTree { | ||
| message Thread { | ||
| optional int32 tid = 1; | ||
| optional string name = 2; | ||
| optional int32 tgid = 3; | ||
| } | ||
| repeated ProcessTree.Thread threads = 2; | ||
| } | ||
|
|
||
| // --- 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; | ||
| } | ||
|
|
||
| message StreamingProfilePacket { | ||
| repeated uint64 callstack_iid = 1; | ||
| repeated int64 timestamp_delta_us = 2; | ||
| } | ||
|
|
||
| // --- track descriptors ------------------------------------------------------- | ||
|
|
||
| message TrackDescriptor { | ||
| optional uint64 uuid = 1; | ||
| optional ThreadDescriptor thread = 4; | ||
| } | ||
|
|
||
| message ThreadDescriptor { | ||
| optional int32 pid = 1; | ||
| optional int32 tid = 2; | ||
| optional string thread_name = 5; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,27 @@ pub struct DebugImage { | |
| uuid: Option<Uuid>, | ||
| } | ||
|
|
||
| impl DebugImage { | ||
| /// Creates a native (ELF/Symbolic) debug image from Perfetto mapping data. | ||
| pub fn native_image( | ||
|
Comment on lines
+46
to
+47
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like there is only a single usage in the perfetto code and it is very perfetto specific (according to docstring), maybe just inline it instead and make the fields public? |
||
| code_file: String, | ||
| debug_id: DebugId, | ||
| image_addr: u64, | ||
| image_vmaddr: u64, | ||
| image_size: u64, | ||
| ) -> Self { | ||
| Self { | ||
| code_file: Some(code_file.into()), | ||
| debug_id: Some(debug_id), | ||
| image_type: ImageType::Symbolic, | ||
| image_addr: Some(Addr(image_addr)), | ||
| image_vmaddr: Some(Addr(image_vmaddr)), | ||
| image_size, | ||
| uuid: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn get_proguard_image(uuid: &str) -> Result<DebugImage, UuidError> { | ||
| Ok(DebugImage { | ||
| code_file: None, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the change bigger than this?