Skip to content

Commit 00b3627

Browse files
committed
[vm] Reduce duplication when writing Perfetto packets
Consolidate code populating TracePacket in a single function instead of multiple helpers. Most of the duplication in the previous code was caused by how Duration events were handled - this CL avoids this duplication by making the core helper takes event_type, timestamp and timeline event. This allows to perform Duration split simply by doing: PopulateAndWritePacket(TimelineEvent::kBegin, event.TimeOrigin(), event); PopulateAndWritePacket(TimelineEvent::kEnd, event.TimeEnd(), event); Instead of duplicating large chunks of code. TEST=ci Change-Id: Ica5d00264f3e872b939059ea90fcbfbf6c8768e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417201 Reviewed-by: Derek Xu <[email protected]>
1 parent c513372 commit 00b3627

File tree

7 files changed

+185
-222
lines changed

7 files changed

+185
-222
lines changed

pkg/vm_service_protos/lib/src/protos/perfetto/trace/track_event/track_event.pb.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class TrackEvent extends $pb.GeneratedMessage {
151151
4, _omitFieldNames ? '' : 'debugAnnotations', $pb.PbFieldType.PM,
152152
subBuilder: $1.DebugAnnotation.create)
153153
..e<TrackEvent_Type>(9, _omitFieldNames ? '' : 'type', $pb.PbFieldType.OE,
154-
defaultOrMaker: TrackEvent_Type.TYPE_SLICE_BEGIN,
154+
defaultOrMaker: TrackEvent_Type.TYPE_UNSPECIFIED,
155155
valueOf: TrackEvent_Type.valueOf,
156156
enumValues: TrackEvent_Type.values)
157157
..a<$fixnum.Int64>(

pkg/vm_service_protos/lib/src/protos/perfetto/trace/track_event/track_event.pbenum.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import 'package:protobuf/protobuf.dart' as $pb;
2323

2424
/// Type of the TrackEvent (required if |phase| in LegacyEvent is not set).
2525
class TrackEvent_Type extends $pb.ProtobufEnum {
26+
static const TrackEvent_Type TYPE_UNSPECIFIED =
27+
TrackEvent_Type._(0, _omitEnumNames ? '' : 'TYPE_UNSPECIFIED');
28+
2629
/// Slice events are events that have a begin and end timestamp, i.e. a
2730
/// duration. They can be nested similar to a callstack: If, on the same
2831
/// track, event B begins after event A, but before A ends, B is a child
@@ -50,6 +53,7 @@ class TrackEvent_Type extends $pb.ProtobufEnum {
5053
TrackEvent_Type._(3, _omitEnumNames ? '' : 'TYPE_INSTANT');
5154

5255
static const $core.List<TrackEvent_Type> values = <TrackEvent_Type>[
56+
TYPE_UNSPECIFIED,
5357
TYPE_SLICE_BEGIN,
5458
TYPE_SLICE_END,
5559
TYPE_INSTANT,

pkg/vm_service_protos/lib/src/protos/perfetto/trace/track_event/track_event.pbjson.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const TrackEvent$json = {
6363
const TrackEvent_Type$json = {
6464
'1': 'Type',
6565
'2': [
66+
{'1': 'TYPE_UNSPECIFIED', '2': 0},
6667
{'1': 'TYPE_SLICE_BEGIN', '2': 1},
6768
{'1': 'TYPE_SLICE_END', '2': 2},
6869
{'1': 'TYPE_INSTANT', '2': 3},
@@ -76,6 +77,6 @@ final $typed_data.Uint8List trackEventDescriptor = $convert.base64Decode(
7677
'eXBlUgR0eXBlEh0KCnRyYWNrX3V1aWQYCyABKARSCXRyYWNrVXVpZBIZCghmbG93X2lkcxgvIA'
7778
'MoBlIHZmxvd0lkcxIwChR0ZXJtaW5hdGluZ19mbG93X2lkcxgwIAMoBlISdGVybWluYXRpbmdG'
7879
'bG93SWRzEk0KEWRlYnVnX2Fubm90YXRpb25zGAQgAygLMiAucGVyZmV0dG8ucHJvdG9zLkRlYn'
79-
'VnQW5ub3RhdGlvblIQZGVidWdBbm5vdGF0aW9ucyJCCgRUeXBlEhQKEFRZUEVfU0xJQ0VfQkVH'
80-
'SU4QARISCg5UWVBFX1NMSUNFX0VORBACEhAKDFRZUEVfSU5TVEFOVBADQgwKCm5hbWVfZmllbG'
81-
'Q=');
80+
'VnQW5ub3RhdGlvblIQZGVidWdBbm5vdGF0aW9ucyJYCgRUeXBlEhQKEFRZUEVfVU5TUEVDSUZJ'
81+
'RUQQABIUChBUWVBFX1NMSUNFX0JFR0lOEAESEgoOVFlQRV9TTElDRV9FTkQQAhIQCgxUWVBFX0'
82+
'lOU1RBTlQQA0IMCgpuYW1lX2ZpZWxk');

runtime/vm/protos/perfetto/trace/track_event/track_event.pbzero.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ using TrackEvent_Type = perfetto_pbzero_enum_TrackEvent::Type;
3232

3333
namespace perfetto_pbzero_enum_TrackEvent {
3434
enum Type : int32_t {
35+
TYPE_UNSPECIFIED = 0,
3536
TYPE_SLICE_BEGIN = 1,
3637
TYPE_SLICE_END = 2,
3738
TYPE_INSTANT = 3,
@@ -40,13 +41,16 @@ enum Type : int32_t {
4041
using TrackEvent_Type = perfetto_pbzero_enum_TrackEvent::Type;
4142

4243
constexpr TrackEvent_Type TrackEvent_Type_MIN =
43-
TrackEvent_Type::TYPE_SLICE_BEGIN;
44+
TrackEvent_Type::TYPE_UNSPECIFIED;
4445
constexpr TrackEvent_Type TrackEvent_Type_MAX = TrackEvent_Type::TYPE_INSTANT;
4546

4647
PERFETTO_PROTOZERO_CONSTEXPR14_OR_INLINE
4748
const char* TrackEvent_Type_Name(
4849
::perfetto::protos::pbzero::TrackEvent_Type value) {
4950
switch (value) {
51+
case ::perfetto::protos::pbzero::TrackEvent_Type::TYPE_UNSPECIFIED:
52+
return "TYPE_UNSPECIFIED";
53+
5054
case ::perfetto::protos::pbzero::TrackEvent_Type::TYPE_SLICE_BEGIN:
5155
return "TYPE_SLICE_BEGIN";
5256

@@ -116,6 +120,7 @@ class TrackEvent : public ::protozero::Message {
116120
static inline const char* Type_Name(Type value) {
117121
return ::perfetto::protos::pbzero::TrackEvent_Type_Name(value);
118122
}
123+
static inline const Type TYPE_UNSPECIFIED = Type::TYPE_UNSPECIFIED;
119124
static inline const Type TYPE_SLICE_BEGIN = Type::TYPE_SLICE_BEGIN;
120125
static inline const Type TYPE_SLICE_END = Type::TYPE_SLICE_END;
121126
static inline const Type TYPE_INSTANT = Type::TYPE_INSTANT;

runtime/vm/protos/perfetto/trace/track_event/track_event.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ message TrackEvent {
112112

113113
// Type of the TrackEvent (required if |phase| in LegacyEvent is not set).
114114
enum Type {
115+
TYPE_UNSPECIFIED = 0;
116+
115117
// Slice events are events that have a begin and end timestamp, i.e. a
116118
// duration. They can be nested similar to a callstack: If, on the same
117119
// track, event B begins after event A, but before A ends, B is a child

0 commit comments

Comments
 (0)