11
11
#include < fcntl.h>
12
12
13
13
#include < cstdlib>
14
- #include < utility>
15
14
16
15
#include " platform/atomic.h"
17
- #include " platform/hashmap.h"
18
16
#include " vm/isolate.h"
19
17
#include " vm/json_stream.h"
20
18
#include " vm/lockers.h"
@@ -631,16 +629,6 @@ void TimelineEvent::Init(EventType event_type, const char* label) {
631
629
OSThread* os_thread = OSThread::Current ();
632
630
ASSERT (os_thread != NULL );
633
631
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
- }
644
632
auto thread = Thread::Current ();
645
633
auto isolate = thread != nullptr ? thread->isolate () : nullptr ;
646
634
auto isolate_group = thread != nullptr ? thread->isolate_group () : nullptr ;
@@ -853,27 +841,6 @@ const char* TimelineEvent::GetFormattedIsolateGroupId() const {
853
841
return formatted_isolate_group_id;
854
842
}
855
843
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
-
877
844
TimelineStream::TimelineStream (const char * name,
878
845
const char * fuchsia_name,
879
846
bool has_static_labels,
@@ -1067,28 +1034,30 @@ IsolateTimelineEventFilter::IsolateTimelineEventFilter(
1067
1034
isolate_id_ (isolate_id) {}
1068
1035
1069
1036
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 ) {}
1084
1038
1085
1039
#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
+ }
1092
1061
}
1093
1062
}
1094
1063
#endif
@@ -1240,25 +1209,6 @@ TimelineEventBlock* TimelineEventRecorder::GetNewBlock() {
1240
1209
return GetNewBlockLocked ();
1241
1210
}
1242
1211
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
-
1262
1212
TimelineEventFixedBufferRecorder::TimelineEventFixedBufferRecorder (
1263
1213
intptr_t capacity)
1264
1214
: memory_(NULL ),
@@ -1332,7 +1282,7 @@ void TimelineEventFixedBufferRecorder::PrintJSON(JSONStream* js,
1332
1282
topLevel.AddProperty (" type" , " Timeline" );
1333
1283
{
1334
1284
JSONArray events (&topLevel, " traceEvents" );
1335
- PrintJSONMeta (events);
1285
+ PrintJSONMeta (& events);
1336
1286
PrintJSONEvents (&events, filter);
1337
1287
}
1338
1288
topLevel.AddPropertyTimeMicros (" timeOriginMicros" , TimeOriginMicros ());
@@ -1343,7 +1293,7 @@ void TimelineEventFixedBufferRecorder::PrintTraceEvent(
1343
1293
JSONStream* js,
1344
1294
TimelineEventFilter* filter) {
1345
1295
JSONArray events (js);
1346
- PrintJSONMeta (events);
1296
+ PrintJSONMeta (& events);
1347
1297
PrintJSONEvents (&events, filter);
1348
1298
}
1349
1299
#endif
@@ -1688,7 +1638,7 @@ void TimelineEventEndlessRecorder::PrintJSON(JSONStream* js,
1688
1638
topLevel.AddProperty (" type" , " Timeline" );
1689
1639
{
1690
1640
JSONArray events (&topLevel, " traceEvents" );
1691
- PrintJSONMeta (events);
1641
+ PrintJSONMeta (& events);
1692
1642
PrintJSONEvents (&events, filter);
1693
1643
}
1694
1644
topLevel.AddPropertyTimeMicros (" timeOriginMicros" , TimeOriginMicros ());
@@ -1699,7 +1649,7 @@ void TimelineEventEndlessRecorder::PrintTraceEvent(
1699
1649
JSONStream* js,
1700
1650
TimelineEventFilter* filter) {
1701
1651
JSONArray events (js);
1702
- PrintJSONMeta (events);
1652
+ PrintJSONMeta (& events);
1703
1653
PrintJSONEvents (&events, filter);
1704
1654
}
1705
1655
#endif
0 commit comments