Skip to content

Commit 89adb88

Browse files
authored
Merge branch 'main' into dev/parthsane/add_proto_for_proc_state
2 parents da375d1 + e4f5045 commit 89adb88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3133
-158
lines changed

Android.bp

Lines changed: 488 additions & 0 deletions
Large diffs are not rendered by default.

BUILD

Lines changed: 193 additions & 0 deletions
Large diffs are not rendered by default.

include/perfetto/ext/tracing/core/trace_packet.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class PERFETTO_EXPORT_COMPONENT TracePacket {
6161
// will be valid only as long as the original buffer is valid.
6262
void AddSlice(const void* start, size_t size);
6363

64+
void Clear();
65+
6466
// Total size of all slices.
6567
size_t size() const { return size_; }
6668

@@ -70,9 +72,13 @@ class PERFETTO_EXPORT_COMPONENT TracePacket {
7072
// and its size.
7173
std::tuple<char*, size_t> GetProtoPreamble();
7274

75+
// Returns the raw protobuf bytes of the slices, all stitched together into
76+
// the specified buffer.
77+
void GetRawBytes(std::string*) const;
78+
7379
// Returns the raw protobuf bytes of the slices, all stitched together into
7480
// a string. Only for testing.
75-
std::string GetRawBytesForTesting();
81+
std::string GetRawBytesForTesting() const;
7682

7783
// Remembers the buffer index where this packet was taken from. This is
7884
// usually populated for packets from a TraceBuffer, not synthetic ones.

protos/perfetto/common/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ perfetto_proto_library("@TYPE@") {
4343
"zero",
4444
"cpp",
4545
]
46+
deps = [ "../protovm:@TYPE@" ]
4647
}
4748

4849
# Semantic types for proto field filtering. This is separate from the main

protos/perfetto/common/data_source_descriptor.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package perfetto.protos;
2121
import "protos/perfetto/common/ftrace_descriptor.proto";
2222
import "protos/perfetto/common/gpu_counter_descriptor.proto";
2323
import "protos/perfetto/common/track_event_descriptor.proto";
24+
import "protos/perfetto/protovm/vm_program.proto";
2425

2526
// This message is sent from Producer(s) to the tracing Service when registering
2627
// to advertise their capabilities. It describes the structure of tracing
@@ -60,6 +61,13 @@ message DataSourceDescriptor {
6061
// Introduced in v39 / Android V.
6162
optional bool no_flush = 9;
6263

64+
// If present, the tracing service executes this program within a ProtoVM to
65+
// process overwritten packets (patches). The service computes a hash of the
66+
// program to detect and disambiguate between different versions; if multiple
67+
// versions (from different producers) are specified for the same data source,
68+
// the service instantiates a dedicated ProtoVM for each.
69+
optional VmProgram protovm_program = 10;
70+
6371
// Optional specification about available GPU counters.
6472
optional GpuCounterDescriptor gpu_counter_descriptor = 5 [lazy = true];
6573

protos/perfetto/config/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ perfetto_proto_library("@TYPE@") {
3131
"priority_boost:@TYPE@",
3232
"process_stats:@TYPE@",
3333
"profiling:@TYPE@",
34+
"protovm:@TYPE@",
3435
"statsd:@TYPE@",
3536
"sys_stats:@TYPE@",
3637
"system_info:@TYPE@",

protos/perfetto/config/data_source_config.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import "protos/perfetto/config/gpu/gpu_renderstages_config.proto";
4848
import "protos/perfetto/config/inode_file/inode_file_config.proto";
4949
import "protos/perfetto/config/interceptor_config.proto";
5050
import "protos/perfetto/config/power/android_power_config.proto";
51+
import "protos/perfetto/config/protovm/protovm_config.proto";
5152
import "protos/perfetto/config/statsd/statsd_tracing_config.proto";
5253
import "protos/perfetto/config/priority_boost/priority_boost_config.proto";
5354
import "protos/perfetto/config/process_stats/process_stats_config.proto";
@@ -154,6 +155,20 @@ message DataSourceConfig {
154155

155156
optional PriorityBoostConfig priority_boost = 10;
156157

158+
// If specified, the data source requires the tracing service to process
159+
// overwritten packets (patches) using a ProtoVM instance with this config.
160+
// The ProtoVM program is specified at data source registration time through
161+
// the descriptor.
162+
163+
// TODO(primiano): today when we enable a protovm_config, we actually accept
164+
// that if N producers advertise M different versions of the same program we
165+
// will create M instances of that program.
166+
// To overcome this, we could move the program to the TraceConfig. But doing
167+
// so would bloat the trace config size too big and create problems to statsd.
168+
// Once the config store (b/482305876) exists we should move protovm programs
169+
// onto that.
170+
optional ProtoVmConfig protovm_config = 12;
171+
157172
// Keep the lower IDs (up to 99) for fields that are *not* specific to
158173
// data-sources and needs to be processed by the traced daemon.
159174

protos/perfetto/config/perfetto_config.proto

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,119 @@ message TrackEventDescriptor {
168168

169169
// End of protos/perfetto/common/track_event_descriptor.proto
170170

171+
// Begin of protos/perfetto/protovm/vm_program.proto
172+
173+
message VmProgram {
174+
optional uint32 version = 1;
175+
repeated VmInstruction instructions = 2;
176+
}
177+
178+
message VmInstruction {
179+
oneof operation {
180+
VmOpSelect select = 1;
181+
VmOpRegLoad reg_load = 2;
182+
VmOpMerge merge = 3;
183+
VmOpSet set = 4;
184+
VmOpDel del = 5;
185+
}
186+
187+
enum AbortLevel {
188+
// Skip current instruction but execute following ones
189+
SKIP_CURRENT_INSTRUCTION = 1;
190+
// Skip current instruction as well as following ones (default)
191+
SKIP_CURRENT_INSTRUCTION_AND_BREAK_OUTER = 2;
192+
// Abort whole program
193+
ABORT = 3;
194+
};
195+
optional AbortLevel abort_level = 6;
196+
197+
// Sub-instructions executed if the current instruction succeeds
198+
repeated VmInstruction nested_instructions = 7;
199+
}
200+
201+
message VmOpSelect {
202+
// Enum SRC|DST|BOTH. Default=SRC.
203+
optional VmCursorEnum cursor = 1;
204+
repeated PathComponent relative_path = 2;
205+
206+
// Creates the submessage if doesn't exist in the DST cursor
207+
// (think of mkdir -p). Only valid when cursor=DST|BOTH.
208+
optional bool create_if_not_exist = 3;
209+
210+
// A path component is either: (1) a field id to descend into (common case);
211+
// (2) an array index (for repeated fields); (3) a map lookup operation (for
212+
// repeated fields, where we snoop a sub-field as a map key)
213+
message PathComponent {
214+
oneof field {
215+
uint32 field_id = 1;
216+
uint32 array_index = 2;
217+
218+
// The ID of the field in the repeated submessage that we
219+
// use as a key (e.g. LayerState.layer_id). When setting this
220+
// register_to_match must also be set, to tell what's the
221+
// expected value of the key we are looking up.
222+
uint32 map_key_field_id = 3;
223+
}
224+
225+
// When we are selecting a leaf field, tell what's the field type
226+
// to disambiguate integer types. Using uint64 by default will likely
227+
// do the right thing in 99% cases (so probably we don't need to impl
228+
// this until much later if somebody does a map with a fixed64 key)
229+
// enum ProtoFieldType field_type = 4; // bool | int32 | fixed32 | ...
230+
231+
// Only valid when using field_id. This makes select have foreach
232+
// semantics. This means that the body of nested_instructions is
233+
// executed several times, once per each repeated submessage.
234+
optional bool is_repeated = 5;
235+
236+
// Only valid when using map_key_field_id. This defines which
237+
// register (R1..R32) should be used to match the key of the dict
238+
// in a map lookup operation.
239+
// In other words:
240+
// foreach msg in repeated message {
241+
// if msg[map_key_field_id] == R[register_to_match] {
242+
// break; // Lookup succeeded, PathComponent resolves here.
243+
// }
244+
// }
245+
optional uint32 register_to_match = 6;
246+
247+
// Only valid when using field_id and is_repeated=true. When iterating
248+
// over repeated fields, stores the current iteration index into the
249+
// the register R1..R32 defined below. This can be used to do complex
250+
// operations like "find the entry in the array that has width==100,
251+
// remember its offset in the SRC array and overwrite the matching
252+
// i-th element in the DST array. We will probably never implement
253+
// this but it's here for completeness.
254+
optional uint32 store_foreach_index_into_register = 7;
255+
}
256+
}
257+
258+
message VmOpRegLoad {
259+
// SRC(default) | DST.
260+
optional VmCursorEnum cursor = 1;
261+
// 1=R1, 2=R2... 32=R32
262+
optional uint32 dst_register = 2;
263+
}
264+
265+
// Merges SRC into DST. Both need to point to a message (not a field).
266+
message VmOpMerge {}
267+
268+
// Copies SRC into DST. If a message, replaces the DST node, discarding any
269+
// pre-existing field.
270+
message VmOpSet {}
271+
272+
// Delete the field or message pointed by DST.
273+
message VmOpDel {}
274+
275+
enum VmCursorEnum {
276+
VM_CURSOR_UNSPECIFIED = 0;
277+
VM_CURSOR_SRC = 1;
278+
VM_CURSOR_DST = 2;
279+
VM_CURSOR_BOTH = 3;
280+
}
281+
282+
// End of protos/perfetto/protovm/vm_program.proto
283+
171284
// Begin of protos/perfetto/common/data_source_descriptor.proto
172285

173286
// This message is sent from Producer(s) to the tracing Service when registering
@@ -208,6 +321,13 @@ message DataSourceDescriptor {
208321
// Introduced in v39 / Android V.
209322
optional bool no_flush = 9;
210323

324+
// If present, the tracing service executes this program within a ProtoVM to
325+
// process overwritten packets (patches). The service computes a hash of the
326+
// program to detect and disambiguate between different versions; if multiple
327+
// versions (from different producers) are specified for the same data source,
328+
// the service instantiates a dedicated ProtoVM for each.
329+
optional VmProgram protovm_program = 10;
330+
211331
// Optional specification about available GPU counters.
212332
optional GpuCounterDescriptor gpu_counter_descriptor = 5 [lazy = true];
213333

@@ -2381,6 +2501,14 @@ message PerfEventConfig {
23812501

23822502
// End of protos/perfetto/config/profiling/perf_event_config.proto
23832503

2504+
// Begin of protos/perfetto/config/protovm/protovm_config.proto
2505+
2506+
message ProtoVmConfig {
2507+
optional uint32 memory_limit_kb = 1;
2508+
}
2509+
2510+
// End of protos/perfetto/config/protovm/protovm_config.proto
2511+
23842512
// Begin of protos/perfetto/config/statsd/atom_ids.proto
23852513

23862514
// This enum is obtained by post-processing
@@ -4139,6 +4267,20 @@ message DataSourceConfig {
41394267

41404268
optional PriorityBoostConfig priority_boost = 10;
41414269

4270+
// If specified, the data source requires the tracing service to process
4271+
// overwritten packets (patches) using a ProtoVM instance with this config.
4272+
// The ProtoVM program is specified at data source registration time through
4273+
// the descriptor.
4274+
4275+
// TODO(primiano): today when we enable a protovm_config, we actually accept
4276+
// that if N producers advertise M different versions of the same program we
4277+
// will create M instances of that program.
4278+
// To overcome this, we could move the program to the TraceConfig. But doing
4279+
// so would bloat the trace config size too big and create problems to statsd.
4280+
// Once the config store (b/482305876) exists we should move protovm programs
4281+
// onto that.
4282+
optional ProtoVmConfig protovm_config = 12;
4283+
41424284
// Keep the lower IDs (up to 99) for fields that are *not* specific to
41434285
// data-sources and needs to be processed by the traced daemon.
41444286

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2025 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("../../../../gn/proto_library.gni")
16+
17+
perfetto_proto_library("@TYPE@") {
18+
sources = [ "protovm_config.proto" ]
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
syntax = "proto2";
18+
19+
package perfetto.protos;
20+
21+
message ProtoVmConfig {
22+
optional uint32 memory_limit_kb = 1;
23+
}

0 commit comments

Comments
 (0)