[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 <bkonyi@google.com>
This commit is contained in:
Derek Xu
2023-05-10 19:06:10 +00:00
committed by Commit Queue
parent 5d57b747e9
commit e26fe2817c
2 changed files with 26 additions and 0 deletions
+25
View File
@@ -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();
+1
View File
@@ -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.
*/