From e26fe2817cc276c1d803aa65fcd1d0e0e453da80 Mon Sep 17 00:00:00 2001 From: Derek Xu Date: Wed, 10 May 2023 19:06:10 +0000 Subject: [PATCH] [VM/Timeline] Start skipping over dart::TimelineEvents that provide no useful information when writing Perfetto traces TEST=Checked that traces written using the Perfetto file recorder, and traces retrieved through `getPerfettoVMTimeline` still looked correct. Change-Id: I7e327ef525c99187fa8aea868d1cc48721af9f98 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302420 Reviewed-by: Ben Konyi --- runtime/vm/timeline.cc | 25 +++++++++++++++++++++++++ runtime/vm/timeline.h | 1 + 2 files changed, 26 insertions(+) diff --git a/runtime/vm/timeline.cc b/runtime/vm/timeline.cc index 37d8253065a..656fed1a13f 100644 --- a/runtime/vm/timeline.cc +++ b/runtime/vm/timeline.cc @@ -860,9 +860,24 @@ inline void AddEndEventFields( perfetto::protos::pbzero::TrackEvent::Type::TYPE_SLICE_END); } +bool TimelineEvent::CanBeRepresentedByPerfettoTracePacket() const { + switch (event_type()) { + case TimelineEvent::kBegin: + case TimelineEvent::kEnd: + case TimelineEvent::kInstant: + case TimelineEvent::kAsyncBegin: + case TimelineEvent::kAsyncEnd: + case TimelineEvent::kAsyncInstant: + return true; + default: + return false; + } +} + void TimelineEvent::PopulateTracePacket( perfetto::protos::pbzero::TracePacket* packet) const { ASSERT(packet != nullptr); + ASSERT(CanBeRepresentedByPerfettoTracePacket()); perfetto_utils::SetTrustedPacketSequenceId(packet); // TODO(derekx): We should be able to set the unit_multiplier_ns field in a @@ -1648,6 +1663,9 @@ void TimelineEventFixedBufferRecorder::PrintPerfettoEvents( const TimelineEventFilter& filter) { PrintEventsCommon(filter, [this, &jsonBase64String](const TimelineEvent& event) { + if (!event.CanBeRepresentedByPerfettoTracePacket()) { + return; + } event.PopulateTracePacket(packet().get()); perfetto_utils::AppendPacketToJSONBase64String(jsonBase64String, &packet()); packet().Reset(); @@ -2113,9 +2131,13 @@ void TimelineEventPerfettoFileRecorder::WritePacket( } void TimelineEventPerfettoFileRecorder::DrainImpl(const TimelineEvent& event) { + if (!event.CanBeRepresentedByPerfettoTracePacket()) { + return; + } event.PopulateTracePacket(packet().get()); WritePacket(&packet()); packet().Reset(); + if (event.event_type() == TimelineEvent::kAsyncBegin || event.event_type() == TimelineEvent::kAsyncInstant) { AddAsyncTrackMetadataBasedOnEvent(event); @@ -2168,6 +2190,9 @@ void TimelineEventEndlessRecorder::PrintPerfettoEvents( const TimelineEventFilter& filter) { PrintEventsCommon(filter, [this, &jsonBase64String](const TimelineEvent& event) { + if (!event.CanBeRepresentedByPerfettoTracePacket()) { + return; + } event.PopulateTracePacket(packet().get()); perfetto_utils::AppendPacketToJSONBase64String(jsonBase64String, &packet()); packet().Reset(); diff --git a/runtime/vm/timeline.h b/runtime/vm/timeline.h index 6fe7ed31ecb..86c7f1aa4bf 100644 --- a/runtime/vm/timeline.h +++ b/runtime/vm/timeline.h @@ -458,6 +458,7 @@ class TimelineEvent { #endif void PrintJSON(JSONWriter* writer) const; #if defined(SUPPORT_PERFETTO) && !defined(PRODUCT) + bool CanBeRepresentedByPerfettoTracePacket() const; /* * Populates the fields of |packet| with this event's data. */