| 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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 int64_t TimelineEvent::TimeOrigin() const { | 673 int64_t TimelineEvent::TimeOrigin() const { |
| 674 return timestamp0_; | 674 return timestamp0_; |
| 675 } | 675 } |
| 676 | 676 |
| 677 | 677 |
| 678 int64_t TimelineEvent::AsyncId() const { | 678 int64_t TimelineEvent::AsyncId() const { |
| 679 return timestamp1_; | 679 return timestamp1_; |
| 680 } | 680 } |
| 681 | 681 |
| 682 | 682 |
| 683 int64_t TimelineEvent::LowTime() const { |
| 684 return timestamp0_; |
| 685 } |
| 686 |
| 687 |
| 688 int64_t TimelineEvent::HighTime() const { |
| 689 if (event_type() == kDuration) { |
| 690 return timestamp1_; |
| 691 } else { |
| 692 return timestamp0_; |
| 693 } |
| 694 } |
| 695 |
| 696 |
| 683 int64_t TimelineEvent::TimeDuration() const { | 697 int64_t TimelineEvent::TimeDuration() const { |
| 684 if (timestamp1_ == 0) { | 698 if (timestamp1_ == 0) { |
| 685 // This duration is still open, use current time as end. | 699 // This duration is still open, use current time as end. |
| 686 return OS::GetCurrentMonotonicMicros() - timestamp0_; | 700 return OS::GetCurrentMonotonicMicros() - timestamp0_; |
| 687 } | 701 } |
| 688 return timestamp1_ - timestamp0_; | 702 return timestamp1_ - timestamp0_; |
| 689 } | 703 } |
| 690 | 704 |
| 691 | 705 |
| 692 bool TimelineEvent::HasThreadCPUTime() const { | 706 bool TimelineEvent::HasThreadCPUTime() const { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 Dart_Port isolate_id, | 1015 Dart_Port isolate_id, |
| 1002 int64_t time_origin_micros, | 1016 int64_t time_origin_micros, |
| 1003 int64_t time_extent_micros) | 1017 int64_t time_extent_micros) |
| 1004 : TimelineEventFilter(time_origin_micros, | 1018 : TimelineEventFilter(time_origin_micros, |
| 1005 time_extent_micros), | 1019 time_extent_micros), |
| 1006 isolate_id_(isolate_id) { | 1020 isolate_id_(isolate_id) { |
| 1007 } | 1021 } |
| 1008 | 1022 |
| 1009 | 1023 |
| 1010 TimelineEventRecorder::TimelineEventRecorder() | 1024 TimelineEventRecorder::TimelineEventRecorder() |
| 1011 : async_id_(0) { | 1025 : async_id_(0), |
| 1026 time_low_micros_(0), |
| 1027 time_high_micros_(0) { |
| 1012 } | 1028 } |
| 1013 | 1029 |
| 1014 | 1030 |
| 1015 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const { | 1031 void TimelineEventRecorder::PrintJSONMeta(JSONArray* events) const { |
| 1016 if (!FLAG_support_service) { | 1032 if (!FLAG_support_service) { |
| 1017 return; | 1033 return; |
| 1018 } | 1034 } |
| 1019 OSThreadIterator it; | 1035 OSThreadIterator it; |
| 1020 while (it.HasNext()) { | 1036 while (it.HasNext()) { |
| 1021 OSThread* thread = it.Next(); | 1037 OSThread* thread = it.Next(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 #if defined(DEBUG) | 1097 #if defined(DEBUG) |
| 1082 if (T != NULL) { | 1098 if (T != NULL) { |
| 1083 T->DecrementNoSafepointScopeDepth(); | 1099 T->DecrementNoSafepointScopeDepth(); |
| 1084 } | 1100 } |
| 1085 #endif // defined(DEBUG) | 1101 #endif // defined(DEBUG) |
| 1086 thread_block_lock->Unlock(); | 1102 thread_block_lock->Unlock(); |
| 1087 return NULL; | 1103 return NULL; |
| 1088 } | 1104 } |
| 1089 | 1105 |
| 1090 | 1106 |
| 1107 void TimelineEventRecorder::ResetTimeTracking() { |
| 1108 time_high_micros_ = 0; |
| 1109 time_low_micros_ = kMaxInt64; |
| 1110 } |
| 1111 |
| 1112 |
| 1113 void TimelineEventRecorder::ReportTime(int64_t micros) { |
| 1114 if (time_high_micros_ < micros) { |
| 1115 time_high_micros_ = micros; |
| 1116 } |
| 1117 if (time_low_micros_ > micros) { |
| 1118 time_low_micros_ = micros; |
| 1119 } |
| 1120 } |
| 1121 |
| 1122 |
| 1123 int64_t TimelineEventRecorder::TimeOriginMicros() const { |
| 1124 return time_low_micros_; |
| 1125 } |
| 1126 |
| 1127 |
| 1128 int64_t TimelineEventRecorder::TimeExtentMicros() const { |
| 1129 return time_high_micros_ - time_low_micros_; |
| 1130 } |
| 1131 |
| 1132 |
| 1091 void TimelineEventRecorder::ThreadBlockCompleteEvent(TimelineEvent* event) { | 1133 void TimelineEventRecorder::ThreadBlockCompleteEvent(TimelineEvent* event) { |
| 1092 if (event == NULL) { | 1134 if (event == NULL) { |
| 1093 return; | 1135 return; |
| 1094 } | 1136 } |
| 1095 // Grab the current thread. | 1137 // Grab the current thread. |
| 1096 OSThread* thread = OSThread::Current(); | 1138 OSThread* thread = OSThread::Current(); |
| 1097 ASSERT(thread != NULL); | 1139 ASSERT(thread != NULL); |
| 1098 // Unlock the thread's block lock. | 1140 // Unlock the thread's block lock. |
| 1099 Mutex* thread_block_lock = thread->timeline_block_lock(); | 1141 Mutex* thread_block_lock = thread->timeline_block_lock(); |
| 1100 ASSERT(thread_block_lock != NULL); | 1142 ASSERT(thread_block_lock != NULL); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 } | 1247 } |
| 1206 | 1248 |
| 1207 | 1249 |
| 1208 void TimelineEventFixedBufferRecorder::PrintJSONEvents( | 1250 void TimelineEventFixedBufferRecorder::PrintJSONEvents( |
| 1209 JSONArray* events, | 1251 JSONArray* events, |
| 1210 TimelineEventFilter* filter) { | 1252 TimelineEventFilter* filter) { |
| 1211 if (!FLAG_support_service) { | 1253 if (!FLAG_support_service) { |
| 1212 return; | 1254 return; |
| 1213 } | 1255 } |
| 1214 MutexLocker ml(&lock_); | 1256 MutexLocker ml(&lock_); |
| 1257 ResetTimeTracking(); |
| 1215 intptr_t block_offset = FindOldestBlockIndex(); | 1258 intptr_t block_offset = FindOldestBlockIndex(); |
| 1216 if (block_offset == -1) { | 1259 if (block_offset == -1) { |
| 1217 // All blocks are empty. | 1260 // All blocks are empty. |
| 1218 return; | 1261 return; |
| 1219 } | 1262 } |
| 1220 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { | 1263 for (intptr_t block_idx = 0; block_idx < num_blocks_; block_idx++) { |
| 1221 TimelineEventBlock* block = | 1264 TimelineEventBlock* block = |
| 1222 blocks_[(block_idx + block_offset) % num_blocks_]; | 1265 blocks_[(block_idx + block_offset) % num_blocks_]; |
| 1223 if (!filter->IncludeBlock(block)) { | 1266 if (!filter->IncludeBlock(block)) { |
| 1224 continue; | 1267 continue; |
| 1225 } | 1268 } |
| 1226 for (intptr_t event_idx = 0; event_idx < block->length(); event_idx++) { | 1269 for (intptr_t event_idx = 0; event_idx < block->length(); event_idx++) { |
| 1227 TimelineEvent* event = block->At(event_idx); | 1270 TimelineEvent* event = block->At(event_idx); |
| 1228 if (filter->IncludeEvent(event) && | 1271 if (filter->IncludeEvent(event) && |
| 1229 event->Within(filter->time_origin_micros(), | 1272 event->Within(filter->time_origin_micros(), |
| 1230 filter->time_extent_micros())) { | 1273 filter->time_extent_micros())) { |
| 1274 ReportTime(event->LowTime()); |
| 1275 ReportTime(event->HighTime()); |
| 1231 events->AddValue(event); | 1276 events->AddValue(event); |
| 1232 } | 1277 } |
| 1233 } | 1278 } |
| 1234 } | 1279 } |
| 1235 } | 1280 } |
| 1236 | 1281 |
| 1237 | 1282 |
| 1238 void TimelineEventFixedBufferRecorder::PrintJSON(JSONStream* js, | 1283 void TimelineEventFixedBufferRecorder::PrintJSON(JSONStream* js, |
| 1239 TimelineEventFilter* filter) { | 1284 TimelineEventFilter* filter) { |
| 1240 if (!FLAG_support_service) { | 1285 if (!FLAG_support_service) { |
| 1241 return; | 1286 return; |
| 1242 } | 1287 } |
| 1243 JSONObject topLevel(js); | 1288 JSONObject topLevel(js); |
| 1244 topLevel.AddProperty("type", "_Timeline"); | 1289 topLevel.AddProperty("type", "_Timeline"); |
| 1245 { | 1290 { |
| 1246 JSONArray events(&topLevel, "traceEvents"); | 1291 JSONArray events(&topLevel, "traceEvents"); |
| 1247 PrintJSONMeta(&events); | 1292 PrintJSONMeta(&events); |
| 1248 PrintJSONEvents(&events, filter); | 1293 PrintJSONEvents(&events, filter); |
| 1249 } | 1294 } |
| 1295 topLevel.AddPropertyTimeMicros("timeOriginMicros", TimeOriginMicros()); |
| 1296 topLevel.AddPropertyTimeMicros("TimeExtentMicros", TimeExtentMicros()); |
| 1250 } | 1297 } |
| 1251 | 1298 |
| 1252 | 1299 |
| 1253 void TimelineEventFixedBufferRecorder::PrintTraceEvent( | 1300 void TimelineEventFixedBufferRecorder::PrintTraceEvent( |
| 1254 JSONStream* js, | 1301 JSONStream* js, |
| 1255 TimelineEventFilter* filter) { | 1302 TimelineEventFilter* filter) { |
| 1256 if (!FLAG_support_service) { | 1303 if (!FLAG_support_service) { |
| 1257 return; | 1304 return; |
| 1258 } | 1305 } |
| 1259 JSONArray events(js); | 1306 JSONArray events(js); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 if (!FLAG_support_service) { | 1433 if (!FLAG_support_service) { |
| 1387 return; | 1434 return; |
| 1388 } | 1435 } |
| 1389 JSONObject topLevel(js); | 1436 JSONObject topLevel(js); |
| 1390 topLevel.AddProperty("type", "_Timeline"); | 1437 topLevel.AddProperty("type", "_Timeline"); |
| 1391 { | 1438 { |
| 1392 JSONArray events(&topLevel, "traceEvents"); | 1439 JSONArray events(&topLevel, "traceEvents"); |
| 1393 PrintJSONMeta(&events); | 1440 PrintJSONMeta(&events); |
| 1394 PrintJSONEvents(&events, filter); | 1441 PrintJSONEvents(&events, filter); |
| 1395 } | 1442 } |
| 1443 topLevel.AddPropertyTimeMicros("timeOriginMicros", TimeOriginMicros()); |
| 1444 topLevel.AddPropertyTimeMicros("TimeExtentMicros", TimeExtentMicros()); |
| 1396 } | 1445 } |
| 1397 | 1446 |
| 1398 | 1447 |
| 1399 void TimelineEventEndlessRecorder::PrintTraceEvent( | 1448 void TimelineEventEndlessRecorder::PrintTraceEvent( |
| 1400 JSONStream* js, | 1449 JSONStream* js, |
| 1401 TimelineEventFilter* filter) { | 1450 TimelineEventFilter* filter) { |
| 1402 if (!FLAG_support_service) { | 1451 if (!FLAG_support_service) { |
| 1403 return; | 1452 return; |
| 1404 } | 1453 } |
| 1405 JSONArray events(js); | 1454 JSONArray events(js); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 } | 1492 } |
| 1444 | 1493 |
| 1445 | 1494 |
| 1446 void TimelineEventEndlessRecorder::PrintJSONEvents( | 1495 void TimelineEventEndlessRecorder::PrintJSONEvents( |
| 1447 JSONArray* events, | 1496 JSONArray* events, |
| 1448 TimelineEventFilter* filter) { | 1497 TimelineEventFilter* filter) { |
| 1449 if (!FLAG_support_service) { | 1498 if (!FLAG_support_service) { |
| 1450 return; | 1499 return; |
| 1451 } | 1500 } |
| 1452 MutexLocker ml(&lock_); | 1501 MutexLocker ml(&lock_); |
| 1502 ResetTimeTracking(); |
| 1453 // Collect all interesting blocks. | 1503 // Collect all interesting blocks. |
| 1454 MallocGrowableArray<TimelineEventBlock*> blocks(8); | 1504 MallocGrowableArray<TimelineEventBlock*> blocks(8); |
| 1455 TimelineEventBlock* current = head_; | 1505 TimelineEventBlock* current = head_; |
| 1456 while (current != NULL) { | 1506 while (current != NULL) { |
| 1457 if (filter->IncludeBlock(current)) { | 1507 if (filter->IncludeBlock(current)) { |
| 1458 blocks.Add(current); | 1508 blocks.Add(current); |
| 1459 } | 1509 } |
| 1460 current = current->next(); | 1510 current = current->next(); |
| 1461 } | 1511 } |
| 1462 // Bail early. | 1512 // Bail early. |
| 1463 if (blocks.length() == 0) { | 1513 if (blocks.length() == 0) { |
| 1464 return; | 1514 return; |
| 1465 } | 1515 } |
| 1466 // Sort the interesting blocks so that blocks with earlier events are | 1516 // Sort the interesting blocks so that blocks with earlier events are |
| 1467 // outputted first. | 1517 // outputted first. |
| 1468 blocks.Sort(TimelineEventBlockCompare); | 1518 blocks.Sort(TimelineEventBlockCompare); |
| 1469 // Output blocks in sorted order. | 1519 // Output blocks in sorted order. |
| 1470 for (intptr_t block_idx = 0; block_idx < blocks.length(); block_idx++) { | 1520 for (intptr_t block_idx = 0; block_idx < blocks.length(); block_idx++) { |
| 1471 current = blocks[block_idx]; | 1521 current = blocks[block_idx]; |
| 1472 intptr_t length = current->length(); | 1522 intptr_t length = current->length(); |
| 1473 for (intptr_t i = 0; i < length; i++) { | 1523 for (intptr_t i = 0; i < length; i++) { |
| 1474 TimelineEvent* event = current->At(i); | 1524 TimelineEvent* event = current->At(i); |
| 1475 if (filter->IncludeEvent(event) && | 1525 if (filter->IncludeEvent(event) && |
| 1476 event->Within(filter->time_origin_micros(), | 1526 event->Within(filter->time_origin_micros(), |
| 1477 filter->time_extent_micros())) { | 1527 filter->time_extent_micros())) { |
| 1528 ReportTime(event->LowTime()); |
| 1529 ReportTime(event->HighTime()); |
| 1478 events->AddValue(event); | 1530 events->AddValue(event); |
| 1479 } | 1531 } |
| 1480 } | 1532 } |
| 1481 } | 1533 } |
| 1482 } | 1534 } |
| 1483 | 1535 |
| 1484 | 1536 |
| 1485 void TimelineEventEndlessRecorder::Clear() { | 1537 void TimelineEventEndlessRecorder::Clear() { |
| 1486 TimelineEventBlock* current = head_; | 1538 TimelineEventBlock* current = head_; |
| 1487 while (current != NULL) { | 1539 while (current != NULL) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 TimelineEventBlock* TimelineEventBlockIterator::Next() { | 1688 TimelineEventBlock* TimelineEventBlockIterator::Next() { |
| 1637 ASSERT(current_ != NULL); | 1689 ASSERT(current_ != NULL); |
| 1638 TimelineEventBlock* r = current_; | 1690 TimelineEventBlock* r = current_; |
| 1639 current_ = current_->next(); | 1691 current_ = current_->next(); |
| 1640 return r; | 1692 return r; |
| 1641 } | 1693 } |
| 1642 | 1694 |
| 1643 #endif // !PRODUCT | 1695 #endif // !PRODUCT |
| 1644 | 1696 |
| 1645 } // namespace dart | 1697 } // namespace dart |
| OLD | NEW |