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" |
11 #include "vm/log.h" | 11 #include "vm/log.h" |
12 #include "vm/object.h" | 12 #include "vm/object.h" |
| 13 #include "vm/service_event.h" |
13 #include "vm/thread.h" | 14 #include "vm/thread.h" |
14 #include "vm/timeline.h" | 15 #include "vm/timeline.h" |
15 | 16 |
16 namespace dart { | 17 namespace dart { |
17 | 18 |
18 #ifndef PRODUCT | 19 #ifndef PRODUCT |
19 | 20 |
20 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline"); | 21 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline"); |
21 DEFINE_FLAG(bool, trace_timeline, false, | 22 DEFINE_FLAG(bool, trace_timeline, false, |
22 "Trace timeline backend"); | 23 "Trace timeline backend"); |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1211 | 1212 |
1212 | 1213 |
1213 void TimelineEventRingRecorder::CompleteEvent(TimelineEvent* event) { | 1214 void TimelineEventRingRecorder::CompleteEvent(TimelineEvent* event) { |
1214 if (event == NULL) { | 1215 if (event == NULL) { |
1215 return; | 1216 return; |
1216 } | 1217 } |
1217 ThreadBlockCompleteEvent(event); | 1218 ThreadBlockCompleteEvent(event); |
1218 } | 1219 } |
1219 | 1220 |
1220 | 1221 |
1221 TimelineEventStreamingRecorder::TimelineEventStreamingRecorder() { | 1222 TimelineEventCallbackRecorder::TimelineEventCallbackRecorder() { |
1222 } | 1223 } |
1223 | 1224 |
1224 | 1225 |
1225 TimelineEventStreamingRecorder::~TimelineEventStreamingRecorder() { | 1226 TimelineEventCallbackRecorder::~TimelineEventCallbackRecorder() { |
1226 } | 1227 } |
1227 | 1228 |
1228 | 1229 |
1229 void TimelineEventStreamingRecorder::PrintJSON(JSONStream* js, | 1230 void TimelineEventCallbackRecorder::PrintJSON(JSONStream* js, |
1230 TimelineEventFilter* filter) { | 1231 TimelineEventFilter* filter) { |
1231 if (!FLAG_support_service) { | 1232 if (!FLAG_support_service) { |
1232 return; | 1233 return; |
1233 } | 1234 } |
1234 JSONObject topLevel(js); | 1235 JSONObject topLevel(js); |
1235 topLevel.AddProperty("type", "_Timeline"); | 1236 topLevel.AddProperty("type", "_Timeline"); |
1236 { | 1237 { |
1237 JSONArray events(&topLevel, "traceEvents"); | 1238 JSONArray events(&topLevel, "traceEvents"); |
1238 PrintJSONMeta(&events); | 1239 PrintJSONMeta(&events); |
1239 } | 1240 } |
1240 } | 1241 } |
1241 | 1242 |
1242 | 1243 |
1243 void TimelineEventStreamingRecorder::PrintTraceEvent( | 1244 void TimelineEventCallbackRecorder::PrintTraceEvent( |
1244 JSONStream* js, | 1245 JSONStream* js, |
1245 TimelineEventFilter* filter) { | 1246 TimelineEventFilter* filter) { |
1246 if (!FLAG_support_service) { | 1247 if (!FLAG_support_service) { |
1247 return; | 1248 return; |
1248 } | 1249 } |
1249 JSONArray events(js); | 1250 JSONArray events(js); |
1250 } | 1251 } |
1251 | 1252 |
1252 | 1253 |
1253 TimelineEvent* TimelineEventStreamingRecorder::StartEvent() { | 1254 TimelineEvent* TimelineEventCallbackRecorder::StartEvent() { |
1254 TimelineEvent* event = new TimelineEvent(); | 1255 TimelineEvent* event = new TimelineEvent(); |
1255 return event; | 1256 return event; |
1256 } | 1257 } |
1257 | 1258 |
1258 | 1259 |
1259 void TimelineEventStreamingRecorder::CompleteEvent(TimelineEvent* event) { | 1260 void TimelineEventCallbackRecorder::CompleteEvent(TimelineEvent* event) { |
1260 StreamEvent(event); | 1261 OnEvent(event); |
1261 delete event; | 1262 delete event; |
1262 } | 1263 } |
1263 | 1264 |
1264 | 1265 |
1265 TimelineEventEndlessRecorder::TimelineEventEndlessRecorder() | 1266 TimelineEventEndlessRecorder::TimelineEventEndlessRecorder() |
1266 : head_(NULL), | 1267 : head_(NULL), |
1267 block_index_(0) { | 1268 block_index_(0) { |
1268 } | 1269 } |
1269 | 1270 |
1270 | 1271 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 thread_id_(OSThread::kInvalidThreadId), | 1390 thread_id_(OSThread::kInvalidThreadId), |
1390 in_use_(false) { | 1391 in_use_(false) { |
1391 } | 1392 } |
1392 | 1393 |
1393 | 1394 |
1394 TimelineEventBlock::~TimelineEventBlock() { | 1395 TimelineEventBlock::~TimelineEventBlock() { |
1395 Reset(); | 1396 Reset(); |
1396 } | 1397 } |
1397 | 1398 |
1398 | 1399 |
| 1400 void TimelineEventBlock::PrintJSON(JSONStream* js) const { |
| 1401 ASSERT(!in_use()); |
| 1402 JSONArray events(js); |
| 1403 for (intptr_t i = 0; i < length(); i++) { |
| 1404 const TimelineEvent* event = At(i); |
| 1405 events.AddValue(event); |
| 1406 } |
| 1407 } |
| 1408 |
| 1409 |
1399 TimelineEvent* TimelineEventBlock::StartEvent() { | 1410 TimelineEvent* TimelineEventBlock::StartEvent() { |
1400 ASSERT(!IsFull()); | 1411 ASSERT(!IsFull()); |
1401 if (FLAG_trace_timeline) { | 1412 if (FLAG_trace_timeline) { |
1402 OSThread* os_thread = OSThread::Current(); | 1413 OSThread* os_thread = OSThread::Current(); |
1403 ASSERT(os_thread != NULL); | 1414 ASSERT(os_thread != NULL); |
1404 intptr_t tid = OSThread::ThreadIdToIntPtr(os_thread->id()); | 1415 intptr_t tid = OSThread::ThreadIdToIntPtr(os_thread->id()); |
1405 OS::Print("StartEvent in block %p for thread %" Px "\n", this, tid); | 1416 OS::Print("StartEvent in block %p for thread %" Px "\n", this, tid); |
1406 } | 1417 } |
1407 return &events_[length_++]; | 1418 return &events_[length_++]; |
1408 } | 1419 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 thread_id_ = os_thread->trace_id(); | 1469 thread_id_ = os_thread->trace_id(); |
1459 in_use_ = true; | 1470 in_use_ = true; |
1460 } | 1471 } |
1461 | 1472 |
1462 | 1473 |
1463 void TimelineEventBlock::Finish() { | 1474 void TimelineEventBlock::Finish() { |
1464 if (FLAG_trace_timeline) { | 1475 if (FLAG_trace_timeline) { |
1465 OS::Print("Finish block %p\n", this); | 1476 OS::Print("Finish block %p\n", this); |
1466 } | 1477 } |
1467 in_use_ = false; | 1478 in_use_ = false; |
| 1479 if (Service::timeline_stream.enabled()) { |
| 1480 ServiceEvent service_event(NULL, ServiceEvent::kTimelineEvents); |
| 1481 service_event.set_timeline_event_block(this); |
| 1482 Service::HandleEvent(&service_event); |
| 1483 } |
1468 } | 1484 } |
1469 | 1485 |
1470 | 1486 |
1471 TimelineEventBlockIterator::TimelineEventBlockIterator( | 1487 TimelineEventBlockIterator::TimelineEventBlockIterator( |
1472 TimelineEventRecorder* recorder) | 1488 TimelineEventRecorder* recorder) |
1473 : current_(NULL), | 1489 : current_(NULL), |
1474 recorder_(NULL) { | 1490 recorder_(NULL) { |
1475 Reset(recorder); | 1491 Reset(recorder); |
1476 } | 1492 } |
1477 | 1493 |
(...skipping 29 matching lines...) Expand all Loading... |
1507 TimelineEventBlock* TimelineEventBlockIterator::Next() { | 1523 TimelineEventBlock* TimelineEventBlockIterator::Next() { |
1508 ASSERT(current_ != NULL); | 1524 ASSERT(current_ != NULL); |
1509 TimelineEventBlock* r = current_; | 1525 TimelineEventBlock* r = current_; |
1510 current_ = current_->next(); | 1526 current_ = current_->next(); |
1511 return r; | 1527 return r; |
1512 } | 1528 } |
1513 | 1529 |
1514 #endif // !PRODUCT | 1530 #endif // !PRODUCT |
1515 | 1531 |
1516 } // namespace dart | 1532 } // namespace dart |
OLD | NEW |