Skip to content

Commit ad706a9

Browse files
bderoCommit Queue
authored andcommitted
Revert "[VM/Timeline] Improve handling of track metadata"
This reverts commit 3787601. Reason for revert: Introduces a crash that's blocking the Dart->Flutter roller: flutter/flutter#120012 Original change's description: > [VM/Timeline] Improve handling of track metadata > > The track information that we send over the service is currently > incomplete. Since we only iterate over the threads that exist at the > time when getVMTimeline is called, we're missing information about any > threads that were joined before that. This CL fixes this issue. > > TEST=CI, ASAN, and I manually checked that more track names are > populated when the changes in this CL are applied > > Change-Id: Ic4edc9910884c3f4743dc0ca65aa7d2a695ff09d > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280058 > Reviewed-by: Ben Konyi <[email protected]> > Commit-Queue: Derek Xu <[email protected]> [email protected],[email protected],[email protected] Change-Id: I920c8d439a3b253c331dd730b637dbfeaad62157 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281000 Commit-Queue: Derek Xu <[email protected]> Reviewed-by: Derek Xu <[email protected]> Auto-Submit: Brandon DeRosier <[email protected]>
1 parent d00acae commit ad706a9

File tree

2 files changed

+33
-111
lines changed

2 files changed

+33
-111
lines changed

runtime/vm/timeline.cc

Lines changed: 26 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
#include <fcntl.h>
1212

1313
#include <cstdlib>
14-
#include <utility>
1514

1615
#include "platform/atomic.h"
17-
#include "platform/hashmap.h"
1816
#include "vm/isolate.h"
1917
#include "vm/json_stream.h"
2018
#include "vm/lockers.h"
@@ -631,16 +629,6 @@ void TimelineEvent::Init(EventType event_type, const char* label) {
631629
OSThread* os_thread = OSThread::Current();
632630
ASSERT(os_thread != NULL);
633631
thread_ = os_thread->trace_id();
634-
if (FLAG_timeline_recorder != nullptr &&
635-
// There is no way to retrieve track metadata when a callback or systrace
636-
// recorder is in use, so we don't need to call
637-
// |AddTrackMetadataBasedOnThread()| in these cases.
638-
strcmp("callback", FLAG_timeline_recorder) != 0 &&
639-
strcmp("systrace", FLAG_timeline_recorder) != 0) {
640-
RecorderLockScope rl;
641-
TimelineEventRecorder* recorder = Timeline::recorder();
642-
recorder->AddTrackMetadataBasedOnThread(*os_thread);
643-
}
644632
auto thread = Thread::Current();
645633
auto isolate = thread != nullptr ? thread->isolate() : nullptr;
646634
auto isolate_group = thread != nullptr ? thread->isolate_group() : nullptr;
@@ -853,27 +841,6 @@ const char* TimelineEvent::GetFormattedIsolateGroupId() const {
853841
return formatted_isolate_group_id;
854842
}
855843

856-
TimelineTrackMetadata::TimelineTrackMetadata(
857-
intptr_t pid,
858-
intptr_t tid,
859-
Utils::CStringUniquePtr&& track_name)
860-
: pid_(pid), tid_(tid), track_name_(std::move(track_name)) {}
861-
862-
#if !defined(PRODUCT)
863-
void TimelineTrackMetadata::PrintJSON(const JSONArray& jsarr_events) const {
864-
JSONObject jsobj(&jsarr_events);
865-
jsobj.AddProperty("name", "thread_name");
866-
jsobj.AddProperty("ph", "M");
867-
jsobj.AddProperty("pid", pid());
868-
jsobj.AddProperty("tid", tid());
869-
{
870-
JSONObject jsobj_args(&jsobj, "args");
871-
jsobj_args.AddPropertyF("name", "%s (%" Pd ")", track_name(), tid());
872-
jsobj_args.AddProperty("mode", "basic");
873-
}
874-
}
875-
#endif // !defined(PRODUCT)
876-
877844
TimelineStream::TimelineStream(const char* name,
878845
const char* fuchsia_name,
879846
bool has_static_labels,
@@ -1067,28 +1034,30 @@ IsolateTimelineEventFilter::IsolateTimelineEventFilter(
10671034
isolate_id_(isolate_id) {}
10681035

10691036
TimelineEventRecorder::TimelineEventRecorder()
1070-
: time_low_micros_(0),
1071-
time_high_micros_(0),
1072-
track_uuid_to_track_metadata_(
1073-
&SimpleHashMap::SamePointerValue,
1074-
TimelineEventRecorder::kTrackUuidToTrackMetadataInitialCapacity) {}
1075-
1076-
TimelineEventRecorder::~TimelineEventRecorder() {
1077-
for (SimpleHashMap::Entry* entry = track_uuid_to_track_metadata_.Start();
1078-
entry != nullptr; entry = track_uuid_to_track_metadata_.Next(entry)) {
1079-
TimelineTrackMetadata* value =
1080-
static_cast<TimelineTrackMetadata*>(entry->value);
1081-
delete value;
1082-
}
1083-
}
1037+
: time_low_micros_(0), time_high_micros_(0) {}
10841038

10851039
#ifndef PRODUCT
1086-
void TimelineEventRecorder::PrintJSONMeta(const JSONArray& jsarr_events) const {
1087-
for (SimpleHashMap::Entry* entry = track_uuid_to_track_metadata_.Start();
1088-
entry != nullptr; entry = track_uuid_to_track_metadata_.Next(entry)) {
1089-
TimelineTrackMetadata* value =
1090-
static_cast<TimelineTrackMetadata*>(entry->value);
1091-
value->PrintJSON(jsarr_events);
1040+
void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const {
1041+
OSThreadIterator it;
1042+
while (it.HasNext()) {
1043+
OSThread* thread = it.Next();
1044+
const char* thread_name = thread->name();
1045+
if (thread_name == NULL) {
1046+
// Only emit a thread name if one was set.
1047+
continue;
1048+
}
1049+
JSONObject obj(events);
1050+
int64_t pid = OS::ProcessId();
1051+
int64_t tid = OSThread::ThreadIdToIntPtr(thread->trace_id());
1052+
obj.AddProperty("name", "thread_name");
1053+
obj.AddProperty("ph", "M");
1054+
obj.AddProperty64("pid", pid);
1055+
obj.AddProperty64("tid", tid);
1056+
{
1057+
JSONObject args(&obj, "args");
1058+
args.AddPropertyF("name", "%s (%" Pd64 ")", thread_name, tid);
1059+
args.AddProperty("mode", "basic");
1060+
}
10921061
}
10931062
}
10941063
#endif
@@ -1240,25 +1209,6 @@ TimelineEventBlock* TimelineEventRecorder::GetNewBlock() {
12401209
return GetNewBlockLocked();
12411210
}
12421211

1243-
void TimelineEventRecorder::AddTrackMetadataBasedOnThread(
1244-
const OSThread& thread) {
1245-
intptr_t pid = OS::ProcessId();
1246-
intptr_t tid = OSThread::ThreadIdToIntPtr(thread.trace_id());
1247-
const char* thread_name = thread.name();
1248-
1249-
void* key = reinterpret_cast<void*>(tid);
1250-
const intptr_t hash = Utils::WordHash(tid);
1251-
SimpleHashMap::Entry* entry =
1252-
track_uuid_to_track_metadata_.Lookup(key, hash, true);
1253-
if (entry->value == nullptr) {
1254-
TimelineTrackMetadata* metadata = new TimelineTrackMetadata(
1255-
pid, tid,
1256-
Utils::CreateCStringUniquePtr(
1257-
Utils::StrDup(thread_name == nullptr ? "" : thread_name)));
1258-
entry->value = metadata;
1259-
}
1260-
}
1261-
12621212
TimelineEventFixedBufferRecorder::TimelineEventFixedBufferRecorder(
12631213
intptr_t capacity)
12641214
: memory_(NULL),
@@ -1332,7 +1282,7 @@ void TimelineEventFixedBufferRecorder::PrintJSON(JSONStream* js,
13321282
topLevel.AddProperty("type", "Timeline");
13331283
{
13341284
JSONArray events(&topLevel, "traceEvents");
1335-
PrintJSONMeta(events);
1285+
PrintJSONMeta(&events);
13361286
PrintJSONEvents(&events, filter);
13371287
}
13381288
topLevel.AddPropertyTimeMicros("timeOriginMicros", TimeOriginMicros());
@@ -1343,7 +1293,7 @@ void TimelineEventFixedBufferRecorder::PrintTraceEvent(
13431293
JSONStream* js,
13441294
TimelineEventFilter* filter) {
13451295
JSONArray events(js);
1346-
PrintJSONMeta(events);
1296+
PrintJSONMeta(&events);
13471297
PrintJSONEvents(&events, filter);
13481298
}
13491299
#endif
@@ -1688,7 +1638,7 @@ void TimelineEventEndlessRecorder::PrintJSON(JSONStream* js,
16881638
topLevel.AddProperty("type", "Timeline");
16891639
{
16901640
JSONArray events(&topLevel, "traceEvents");
1691-
PrintJSONMeta(events);
1641+
PrintJSONMeta(&events);
16921642
PrintJSONEvents(&events, filter);
16931643
}
16941644
topLevel.AddPropertyTimeMicros("timeOriginMicros", TimeOriginMicros());
@@ -1699,7 +1649,7 @@ void TimelineEventEndlessRecorder::PrintTraceEvent(
16991649
JSONStream* js,
17001650
TimelineEventFilter* filter) {
17011651
JSONArray events(js);
1702-
PrintJSONMeta(events);
1652+
PrintJSONMeta(&events);
17031653
PrintJSONEvents(&events, filter);
17041654
}
17051655
#endif

runtime/vm/timeline.h

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "include/dart_tools_api.h"
99

1010
#include "platform/atomic.h"
11-
#include "platform/hashmap.h"
1211
#include "vm/allocation.h"
1312
#include "vm/bitfield.h"
1413
#include "vm/globals.h"
@@ -587,31 +586,6 @@ class TimelineEvent {
587586
DISALLOW_COPY_AND_ASSIGN(TimelineEvent);
588587
};
589588

590-
class TimelineTrackMetadata {
591-
public:
592-
TimelineTrackMetadata(intptr_t pid,
593-
intptr_t tid,
594-
Utils::CStringUniquePtr&& track_name);
595-
intptr_t pid() const { return pid_; }
596-
intptr_t tid() const { return tid_; }
597-
const char* track_name() const { return track_name_.get(); }
598-
#if !defined(PRODUCT)
599-
/*
600-
* Prints a Chrome-format event representing the metadata stored by this
601-
* object into |jsarr_events|.
602-
*/
603-
void PrintJSON(const JSONArray& jsarr_events) const;
604-
#endif // !defined(PRODUCT)
605-
606-
private:
607-
// The ID of the process that this track is associated with.
608-
intptr_t pid_;
609-
// The trace ID of the thread that this track is associated with.
610-
intptr_t tid_;
611-
// The name of this track.
612-
Utils::CStringUniquePtr track_name_;
613-
};
614-
615589
#ifdef SUPPORT_TIMELINE
616590
#define TIMELINE_DURATION(thread, stream, name) \
617591
TimelineBeginEndScope tbes(thread, Timeline::Get##stream##Stream(), name);
@@ -834,20 +808,20 @@ class IsolateTimelineEventFilter : public TimelineEventFilter {
834808
class TimelineEventRecorder : public MallocAllocated {
835809
public:
836810
TimelineEventRecorder();
837-
virtual ~TimelineEventRecorder();
811+
virtual ~TimelineEventRecorder() {}
812+
813+
TimelineEventBlock* GetNewBlock();
838814

839815
// Interface method(s) which must be implemented.
840816
#ifndef PRODUCT
841817
virtual void PrintJSON(JSONStream* js, TimelineEventFilter* filter) = 0;
842818
virtual void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter) = 0;
843819
#endif
844820
virtual const char* name() const = 0;
845-
virtual intptr_t Size() = 0;
846-
TimelineEventBlock* GetNewBlock();
821+
847822
void FinishBlock(TimelineEventBlock* block);
848-
// This function must be called at least once for each thread that corresponds
849-
// to a track in the trace.
850-
void AddTrackMetadataBasedOnThread(const OSThread& thread);
823+
824+
virtual intptr_t Size() = 0;
851825

852826
protected:
853827
#ifndef PRODUCT
@@ -863,7 +837,7 @@ class TimelineEventRecorder : public MallocAllocated {
863837

864838
// Utility method(s).
865839
#ifndef PRODUCT
866-
void PrintJSONMeta(const JSONArray& jsarr_events) const;
840+
void PrintJSONMeta(JSONArray* array) const;
867841
#endif
868842
TimelineEvent* ThreadBlockStartEvent();
869843
void ThreadBlockCompleteEvent(TimelineEvent* event);
@@ -883,8 +857,6 @@ class TimelineEventRecorder : public MallocAllocated {
883857
friend class Timeline;
884858

885859
private:
886-
static const intptr_t kTrackUuidToTrackMetadataInitialCapacity = 1 << 4;
887-
SimpleHashMap track_uuid_to_track_metadata_;
888860
DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder);
889861
};
890862

0 commit comments

Comments
 (0)