mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
[VM/Timeline] Add a heap-buffered packet as a class member of TimelineEventRecorder
This CL removes the packet_ member in TimelineEventPerfettoFileRecorder and adds a packet_ member to TimelineEventRecorder. This member will be used when sending Perfetto traces through the VM Service. TEST=manually verified that traces recorded with the Perfetto file recorder still contained correct information, CI Change-Id: I796369ea0832c265a04e37d91bc09f93967979a8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288061 Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
parent
20a8899318
commit
6785f8ece7
|
@ -1986,13 +1986,16 @@ void TimelineEventFileRecorder::DrainImpl(const TimelineEvent& event) {
|
|||
TimelineEventPerfettoFileRecorder::TimelineEventPerfettoFileRecorder(
|
||||
const char* path)
|
||||
: TimelineEventFileRecorderBase(path) {
|
||||
perfetto_utils::PopulateClockSnapshotPacket(packet_.get());
|
||||
WritePacket(&packet_);
|
||||
packet_.Reset();
|
||||
protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket>& packet =
|
||||
this->packet();
|
||||
|
||||
perfetto_utils::PopulateProcessDescriptorPacket(packet_.get());
|
||||
WritePacket(&packet_);
|
||||
packet_.Reset();
|
||||
perfetto_utils::PopulateClockSnapshotPacket(packet.get());
|
||||
WritePacket(&packet);
|
||||
packet.Reset();
|
||||
|
||||
perfetto_utils::PopulateProcessDescriptorPacket(packet.get());
|
||||
WritePacket(&packet);
|
||||
packet.Reset();
|
||||
|
||||
OSThread::Start("TimelineEventPerfettoFileRecorder",
|
||||
TimelineEventFileRecorderBaseStart,
|
||||
|
@ -2000,14 +2003,16 @@ TimelineEventPerfettoFileRecorder::TimelineEventPerfettoFileRecorder(
|
|||
}
|
||||
|
||||
TimelineEventPerfettoFileRecorder::~TimelineEventPerfettoFileRecorder() {
|
||||
protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket>& packet =
|
||||
this->packet();
|
||||
ShutDown();
|
||||
for (SimpleHashMap::Entry* entry = track_uuid_to_track_metadata().Start();
|
||||
entry != nullptr; entry = track_uuid_to_track_metadata().Next(entry)) {
|
||||
TimelineTrackMetadata* value =
|
||||
static_cast<TimelineTrackMetadata*>(entry->value);
|
||||
value->PopulateTracePacket(packet_.get());
|
||||
WritePacket(&packet_);
|
||||
packet_.Reset();
|
||||
value->PopulateTracePacket(packet.get());
|
||||
WritePacket(&packet);
|
||||
packet.Reset();
|
||||
}
|
||||
for (SimpleHashMap::Entry* entry =
|
||||
async_track_uuid_to_track_metadata().Start();
|
||||
|
@ -2015,9 +2020,9 @@ TimelineEventPerfettoFileRecorder::~TimelineEventPerfettoFileRecorder() {
|
|||
entry = async_track_uuid_to_track_metadata().Next(entry)) {
|
||||
AsyncTimelineTrackMetadata* value =
|
||||
static_cast<AsyncTimelineTrackMetadata*>(entry->value);
|
||||
value->PopulateTracePacket(packet_.get());
|
||||
WritePacket(&packet_);
|
||||
packet_.Reset();
|
||||
value->PopulateTracePacket(packet.get());
|
||||
WritePacket(&packet);
|
||||
packet.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2041,9 +2046,9 @@ void TimelineEventPerfettoFileRecorder::WritePacket(
|
|||
}
|
||||
|
||||
void TimelineEventPerfettoFileRecorder::DrainImpl(const TimelineEvent& event) {
|
||||
event.PopulateTracePacket(packet_.get());
|
||||
WritePacket(&packet_);
|
||||
packet_.Reset();
|
||||
event.PopulateTracePacket(packet().get());
|
||||
WritePacket(&packet());
|
||||
packet().Reset();
|
||||
if (event.event_type() == TimelineEvent::kAsyncBegin ||
|
||||
event.event_type() == TimelineEvent::kAsyncInstant) {
|
||||
AddAsyncTrackMetadataBasedOnEvent(event);
|
||||
|
|
|
@ -909,6 +909,11 @@ class TimelineEventRecorder : public MallocAllocated {
|
|||
SimpleHashMap& async_track_uuid_to_track_metadata() {
|
||||
return async_track_uuid_to_track_metadata_;
|
||||
}
|
||||
#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
|
||||
protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket>& packet() {
|
||||
return packet_;
|
||||
}
|
||||
#endif // defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
|
||||
|
||||
#ifndef PRODUCT
|
||||
void WriteTo(const char* directory);
|
||||
|
@ -947,6 +952,13 @@ class TimelineEventRecorder : public MallocAllocated {
|
|||
SimpleHashMap track_uuid_to_track_metadata_;
|
||||
Mutex track_uuid_to_track_metadata_lock_;
|
||||
SimpleHashMap async_track_uuid_to_track_metadata_;
|
||||
#if defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
|
||||
// We allocate one heap-buffered packet as a class member, because it lets us
|
||||
// continuously follow a cycle of resetting the buffer and writing its
|
||||
// contents.
|
||||
protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket> packet_;
|
||||
#endif // defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder);
|
||||
};
|
||||
|
||||
|
@ -1244,11 +1256,6 @@ class TimelineEventPerfettoFileRecorder : public TimelineEventFileRecorderBase {
|
|||
protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket>* packet)
|
||||
const;
|
||||
void DrainImpl(const TimelineEvent& event) final;
|
||||
|
||||
// We allocate one heap-buffered packet as a class member, because it lets us
|
||||
// continuously follow a cycle of resetting the buffer and writing its to
|
||||
// contents to the file.
|
||||
protozero::HeapBuffered<perfetto::protos::pbzero::TracePacket> packet_;
|
||||
};
|
||||
#endif // defined(SUPPORT_PERFETTO) && !defined(PRODUCT)
|
||||
|
||||
|
|
Loading…
Reference in a new issue