OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <cstdlib> | 5 #include <cstdlib> |
6 | 6 |
7 #include "vm/atomic.h" | 7 #include "vm/atomic.h" |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
9 #include "vm/json_stream.h" | 9 #include "vm/json_stream.h" |
10 #include "vm/lockers.h" | 10 #include "vm/lockers.h" |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 | 413 |
414 const char* TimelineEvent::GetSerializedJSON() const { | 414 const char* TimelineEvent::GetSerializedJSON() const { |
415 ASSERT(pre_serialized_json()); | 415 ASSERT(pre_serialized_json()); |
416 ASSERT(arguments_length_ == 1); | 416 ASSERT(arguments_length_ == 1); |
417 ASSERT(arguments_ != NULL); | 417 ASSERT(arguments_ != NULL); |
418 return arguments_[0].value; | 418 return arguments_[0].value; |
419 } | 419 } |
420 | 420 |
421 | 421 |
422 void TimelineEvent::PrintJSON(JSONStream* stream) const { | 422 void TimelineEvent::PrintJSON(JSONStream* stream) const { |
| 423 if (!FLAG_support_service) { |
| 424 return; |
| 425 } |
423 if (pre_serialized_json()) { | 426 if (pre_serialized_json()) { |
424 // Event has already been serialized into JSON- just append the | 427 // Event has already been serialized into JSON- just append the |
425 // raw data. | 428 // raw data. |
426 stream->AppendSerializedObject(GetSerializedJSON()); | 429 stream->AppendSerializedObject(GetSerializedJSON()); |
427 return; | 430 return; |
428 } | 431 } |
429 JSONObject obj(stream); | 432 JSONObject obj(stream); |
430 int64_t pid = OS::ProcessId(); | 433 int64_t pid = OS::ProcessId(); |
431 int64_t tid = OSThread::ThreadIdToIntPtr(thread_); | 434 int64_t tid = OSThread::ThreadIdToIntPtr(thread_); |
432 obj.AddProperty("name", label_); | 435 obj.AddProperty("name", label_); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 isolate_id_(isolate_id) { | 774 isolate_id_(isolate_id) { |
772 } | 775 } |
773 | 776 |
774 | 777 |
775 TimelineEventRecorder::TimelineEventRecorder() | 778 TimelineEventRecorder::TimelineEventRecorder() |
776 : async_id_(0) { | 779 : async_id_(0) { |
777 } | 780 } |
778 | 781 |
779 | 782 |
780 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const { | 783 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const { |
| 784 if (!FLAG_support_service) { |
| 785 return; |
| 786 } |
781 OSThreadIterator it; | 787 OSThreadIterator it; |
782 while (it.HasNext()) { | 788 while (it.HasNext()) { |
783 OSThread* thread = it.Next(); | 789 OSThread* thread = it.Next(); |
784 const char* thread_name = thread->name(); | 790 const char* thread_name = thread->name(); |
785 if (thread_name == NULL) { | 791 if (thread_name == NULL) { |
786 // Only emit a thread name if one was set. | 792 // Only emit a thread name if one was set. |
787 continue; | 793 continue; |
788 } | 794 } |
789 JSONObject obj(events); | 795 JSONObject obj(events); |
790 int64_t pid = OS::ProcessId(); | 796 int64_t pid = OS::ProcessId(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 Thread* T = Thread::Current(); | 870 Thread* T = Thread::Current(); |
865 if (T != NULL) { | 871 if (T != NULL) { |
866 T->DecrementNoSafepointScopeDepth(); | 872 T->DecrementNoSafepointScopeDepth(); |
867 } | 873 } |
868 #endif // defined(DEBUG) | 874 #endif // defined(DEBUG) |
869 thread_block_lock->Unlock(); | 875 thread_block_lock->Unlock(); |
870 } | 876 } |
871 | 877 |
872 | 878 |
873 void TimelineEventRecorder::WriteTo(const char* directory) { | 879 void TimelineEventRecorder::WriteTo(const char* directory) { |
| 880 if (!FLAG_support_service) { |
| 881 return; |
| 882 } |
874 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 883 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
875 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | 884 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
876 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | 885 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
877 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { | 886 if ((file_open == NULL) || (file_write == NULL) || (file_close == NULL)) { |
878 return; | 887 return; |
879 } | 888 } |
880 Thread* T = Thread::Current(); | 889 Thread* T = Thread::Current(); |
881 StackZone zone(T); | 890 StackZone zone(T); |
882 | 891 |
883 Timeline::ReclaimCachedBlocksFromThreads(); | 892 Timeline::ReclaimCachedBlocksFromThreads(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 TimelineEventBlock* block = blocks_[i]; | 970 TimelineEventBlock* block = blocks_[i]; |
962 delete block; | 971 delete block; |
963 } | 972 } |
964 free(blocks_); | 973 free(blocks_); |
965 } | 974 } |
966 | 975 |
967 | 976 |
968 void TimelineEventRingRecorder::PrintJSONEvents( | 977 void TimelineEventRingRecorder::PrintJSONEvents( |
969 JSONArray* events, | 978 JSONArray* events, |
970 TimelineEventFilter* filter) { | 979 TimelineEventFilter* filter) { |
| 980 if (!FLAG_support_service) { |
| 981 return; |
| 982 } |
971 MutexLocker ml(&lock_); | 983 MutexLocker ml(&lock_); |
972 intptr_t block_offset = FindOldestBlockIndex(); | 984 intptr_t block_offset = FindOldestBlockIndex(); |
973 if (block_offset == -1) { | 985 if (block_offset == -1) { |
974 // All blocks are empty. | 986 // All blocks are empty. |
975 return; | 987 return; |
976 } | 988 } |
977 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { | 989 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { |
978 TimelineEventBlock* block = | 990 TimelineEventBlock* block = |
979 blocks_[(block_idx + block_offset) % num_blocks_]; | 991 blocks_[(block_idx + block_offset) % num_blocks_]; |
980 if (!filter->IncludeBlock(block)) { | 992 if (!filter->IncludeBlock(block)) { |
981 continue; | 993 continue; |
982 } | 994 } |
983 for (intptr_t event_idx = 0; event_idx < block->length(); event_idx++) { | 995 for (intptr_t event_idx = 0; event_idx < block->length(); event_idx++) { |
984 TimelineEvent* event = block->At(event_idx); | 996 TimelineEvent* event = block->At(event_idx); |
985 if (filter->IncludeEvent(event) && | 997 if (filter->IncludeEvent(event) && |
986 event->Within(filter->time_origin_micros(), | 998 event->Within(filter->time_origin_micros(), |
987 filter->time_extent_micros())) { | 999 filter->time_extent_micros())) { |
988 events->AddValue(event); | 1000 events->AddValue(event); |
989 } | 1001 } |
990 } | 1002 } |
991 } | 1003 } |
992 } | 1004 } |
993 | 1005 |
994 | 1006 |
995 void TimelineEventRingRecorder::PrintJSON(JSONStream* js, | 1007 void TimelineEventRingRecorder::PrintJSON(JSONStream* js, |
996 TimelineEventFilter* filter) { | 1008 TimelineEventFilter* filter) { |
| 1009 if (!FLAG_support_service) { |
| 1010 return; |
| 1011 } |
997 JSONObject topLevel(js); | 1012 JSONObject topLevel(js); |
998 topLevel.AddProperty("type", "_Timeline"); | 1013 topLevel.AddProperty("type", "_Timeline"); |
999 { | 1014 { |
1000 JSONArray events(&topLevel, "traceEvents"); | 1015 JSONArray events(&topLevel, "traceEvents"); |
1001 PrintJSONMeta(&events); | 1016 PrintJSONMeta(&events); |
1002 PrintJSONEvents(&events, filter); | 1017 PrintJSONEvents(&events, filter); |
1003 } | 1018 } |
1004 } | 1019 } |
1005 | 1020 |
1006 | 1021 |
1007 void TimelineEventRingRecorder::PrintTraceEvent(JSONStream* js, | 1022 void TimelineEventRingRecorder::PrintTraceEvent(JSONStream* js, |
1008 TimelineEventFilter* filter) { | 1023 TimelineEventFilter* filter) { |
| 1024 if (!FLAG_support_service) { |
| 1025 return; |
| 1026 } |
1009 JSONArray events(js); | 1027 JSONArray events(js); |
1010 PrintJSONEvents(&events, filter); | 1028 PrintJSONEvents(&events, filter); |
1011 } | 1029 } |
1012 | 1030 |
1013 | 1031 |
1014 TimelineEventBlock* TimelineEventRingRecorder::GetHeadBlockLocked() { | 1032 TimelineEventBlock* TimelineEventRingRecorder::GetHeadBlockLocked() { |
1015 return blocks_[0]; | 1033 return blocks_[0]; |
1016 } | 1034 } |
1017 | 1035 |
1018 | 1036 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() { | 1090 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() { |
1073 } | 1091 } |
1074 | 1092 |
1075 | 1093 |
1076 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() { | 1094 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() { |
1077 } | 1095 } |
1078 | 1096 |
1079 | 1097 |
1080 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js, | 1098 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js, |
1081 TimelineEventFilter* filter) { | 1099 TimelineEventFilter* filter) { |
| 1100 if (!FLAG_support_service) { |
| 1101 return; |
| 1102 } |
1082 JSONObject topLevel(js); | 1103 JSONObject topLevel(js); |
1083 topLevel.AddProperty("type", "_Timeline"); | 1104 topLevel.AddProperty("type", "_Timeline"); |
1084 { | 1105 { |
1085 JSONArray events(&topLevel, "traceEvents"); | 1106 JSONArray events(&topLevel, "traceEvents"); |
1086 PrintJSONMeta(&events); | 1107 PrintJSONMeta(&events); |
1087 } | 1108 } |
1088 } | 1109 } |
1089 | 1110 |
1090 | 1111 |
1091 void TimelineEventStreamingRecorder::PrintTraceEvent( | 1112 void TimelineEventStreamingRecorder::PrintTraceEvent( |
1092 JSONStream* js, | 1113 JSONStream* js, |
1093 TimelineEventFilter* filter) { | 1114 TimelineEventFilter* filter) { |
| 1115 if (!FLAG_support_service) { |
| 1116 return; |
| 1117 } |
1094 JSONArray events(js); | 1118 JSONArray events(js); |
1095 } | 1119 } |
1096 | 1120 |
1097 | 1121 |
1098 TimelineEvent* TimelineEventStreamingRecorder::StartEvent() { | 1122 TimelineEvent* TimelineEventStreamingRecorder::StartEvent() { |
1099 TimelineEvent* event = new TimelineEvent(); | 1123 TimelineEvent* event = new TimelineEvent(); |
1100 return event; | 1124 return event; |
1101 } | 1125 } |
1102 | 1126 |
1103 | 1127 |
1104 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) { | 1128 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) { |
1105 StreamEvent(event); | 1129 StreamEvent(event); |
1106 delete event; | 1130 delete event; |
1107 } | 1131 } |
1108 | 1132 |
1109 | 1133 |
1110 TimelineEventEndlessRecorder::TimelineEventEndlessRecorder() | 1134 TimelineEventEndlessRecorder::TimelineEventEndlessRecorder() |
1111 : head_(NULL), | 1135 : head_(NULL), |
1112 block_index_(0) { | 1136 block_index_(0) { |
1113 } | 1137 } |
1114 | 1138 |
1115 | 1139 |
1116 void TimelineEventEndlessRecorder::PrintJSON(JSONStream* js, | 1140 void TimelineEventEndlessRecorder::PrintJSON(JSONStream* js, |
1117 TimelineEventFilter* filter) { | 1141 TimelineEventFilter* filter) { |
| 1142 if (!FLAG_support_service) { |
| 1143 return; |
| 1144 } |
1118 JSONObject topLevel(js); | 1145 JSONObject topLevel(js); |
1119 topLevel.AddProperty("type", "_Timeline"); | 1146 topLevel.AddProperty("type", "_Timeline"); |
1120 { | 1147 { |
1121 JSONArray events(&topLevel, "traceEvents"); | 1148 JSONArray events(&topLevel, "traceEvents"); |
1122 PrintJSONMeta(&events); | 1149 PrintJSONMeta(&events); |
1123 PrintJSONEvents(&events, filter); | 1150 PrintJSONEvents(&events, filter); |
1124 } | 1151 } |
1125 } | 1152 } |
1126 | 1153 |
1127 | 1154 |
1128 void TimelineEventEndlessRecorder::PrintTraceEvent( | 1155 void TimelineEventEndlessRecorder::PrintTraceEvent( |
1129 JSONStream* js, | 1156 JSONStream* js, |
1130 TimelineEventFilter* filter) { | 1157 TimelineEventFilter* filter) { |
| 1158 if (!FLAG_support_service) { |
| 1159 return; |
| 1160 } |
1131 JSONArray events(js); | 1161 JSONArray events(js); |
1132 PrintJSONEvents(&events, filter); | 1162 PrintJSONEvents(&events, filter); |
1133 } | 1163 } |
1134 | 1164 |
1135 | 1165 |
1136 TimelineEventBlock* TimelineEventEndlessRecorder::GetHeadBlockLocked() { | 1166 TimelineEventBlock* TimelineEventEndlessRecorder::GetHeadBlockLocked() { |
1137 return head_; | 1167 return head_; |
1138 } | 1168 } |
1139 | 1169 |
1140 | 1170 |
(...skipping 23 matching lines...) Expand all Loading... |
1164 | 1194 |
1165 static int TimelineEventBlockCompare(TimelineEventBlock* const* a, | 1195 static int TimelineEventBlockCompare(TimelineEventBlock* const* a, |
1166 TimelineEventBlock* const* b) { | 1196 TimelineEventBlock* const* b) { |
1167 return (*a)->LowerTimeBound() - (*b)->LowerTimeBound(); | 1197 return (*a)->LowerTimeBound() - (*b)->LowerTimeBound(); |
1168 } | 1198 } |
1169 | 1199 |
1170 | 1200 |
1171 void TimelineEventEndlessRecorder::PrintJSONEvents( | 1201 void TimelineEventEndlessRecorder::PrintJSONEvents( |
1172 JSONArray* events, | 1202 JSONArray* events, |
1173 TimelineEventFilter* filter) { | 1203 TimelineEventFilter* filter) { |
| 1204 if (!FLAG_support_service) { |
| 1205 return; |
| 1206 } |
1174 MutexLocker ml(&lock_); | 1207 MutexLocker ml(&lock_); |
1175 // Collect all interesting blocks. | 1208 // Collect all interesting blocks. |
1176 MallocGrowableArray<TimelineEventBlock*> blocks(8); | 1209 MallocGrowableArray<TimelineEventBlock*> blocks(8); |
1177 TimelineEventBlock* current = head_; | 1210 TimelineEventBlock* current = head_; |
1178 while (current != NULL) { | 1211 while (current != NULL) { |
1179 if (filter->IncludeBlock(current)) { | 1212 if (filter->IncludeBlock(current)) { |
1180 blocks.Add(current); | 1213 blocks.Add(current); |
1181 } | 1214 } |
1182 current = current->next(); | 1215 current = current->next(); |
1183 } | 1216 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 | 1374 |
1342 | 1375 |
1343 TimelineEventBlock* TimelineEventBlockIterator::Next() { | 1376 TimelineEventBlock* TimelineEventBlockIterator::Next() { |
1344 ASSERT(current_ != NULL); | 1377 ASSERT(current_ != NULL); |
1345 TimelineEventBlock* r = current_; | 1378 TimelineEventBlock* r = current_; |
1346 current_ = current_->next(); | 1379 current_ = current_->next(); |
1347 return r; | 1380 return r; |
1348 } | 1381 } |
1349 | 1382 |
1350 } // namespace dart | 1383 } // namespace dart |
OLD | NEW |