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/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/json_stream.h" | 8 #include "vm/json_stream.h" |
9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
11 #include "vm/thread.h" | 11 #include "vm/thread.h" |
12 #include "vm/timeline.h" | 12 #include "vm/timeline.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 DEFINE_FLAG(bool, trace_timeline, false, "Trace timeline code."); | 16 DEFINE_FLAG(bool, trace_timeline, false, "Trace timeline backend"); |
17 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline"); | 17 DEFINE_FLAG(bool, complete_timeline, false, "Record the complete timeline"); |
18 | 18 |
19 TimelineEvent::TimelineEvent() | 19 TimelineEvent::TimelineEvent() |
20 : timestamp0_(0), | 20 : timestamp0_(0), |
21 timestamp1_(0), | 21 timestamp1_(0), |
22 arguments_(NULL), | 22 arguments_(NULL), |
23 arguments_length_(0), | 23 arguments_length_(0), |
24 state_(0), | 24 state_(0), |
25 label_(NULL), | 25 label_(NULL), |
26 stream_(NULL), | 26 stream_(NULL), |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 : next_(NULL), | 579 : next_(NULL), |
580 length_(0) { | 580 length_(0) { |
581 } | 581 } |
582 | 582 |
583 | 583 |
584 TimelineEvent* TimelineEventBlock::StartEvent() { | 584 TimelineEvent* TimelineEventBlock::StartEvent() { |
585 ASSERT(!IsFull()); | 585 ASSERT(!IsFull()); |
586 return &events_[length_++]; | 586 return &events_[length_++]; |
587 } | 587 } |
588 | 588 |
| 589 |
| 590 ThreadId TimelineEventBlock::thread() const { |
| 591 ASSERT(length_ > 0); |
| 592 return events_[0].thread(); |
| 593 } |
| 594 |
| 595 |
| 596 int64_t TimelineEventBlock::LowerTimeBound() const { |
| 597 ASSERT(length_ > 0); |
| 598 return events_[0].TimeOrigin(); |
| 599 } |
| 600 |
| 601 |
| 602 bool TimelineEventBlock::CheckBlock() { |
| 603 if (length() == 0) { |
| 604 return true; |
| 605 } |
| 606 |
| 607 // - events in the block come from one thread. |
| 608 ThreadId tid = thread(); |
| 609 for (intptr_t i = 0; i < length(); i++) { |
| 610 if (At(i)->thread() != tid) { |
| 611 return false; |
| 612 } |
| 613 } |
| 614 |
| 615 // - events have monotonically increasing timestamps. |
| 616 int64_t last_time = LowerTimeBound(); |
| 617 for (intptr_t i = 0; i < length(); i++) { |
| 618 if (last_time > At(i)->TimeOrigin()) { |
| 619 return false; |
| 620 } |
| 621 last_time = At(i)->TimeOrigin(); |
| 622 } |
| 623 |
| 624 return true; |
| 625 } |
| 626 |
| 627 |
| 628 TimelineEventBlockIterator::TimelineEventBlockIterator( |
| 629 TimelineEventEndlessRecorder* recorder) |
| 630 : current_(NULL), |
| 631 recorder_(recorder) { |
| 632 if (recorder_ == NULL) { |
| 633 return; |
| 634 } |
| 635 recorder->lock_.Lock(); |
| 636 } |
| 637 |
| 638 |
| 639 TimelineEventBlockIterator::~TimelineEventBlockIterator() { |
| 640 if (recorder_ == NULL) { |
| 641 return; |
| 642 } |
| 643 recorder_->lock_.Unlock(); |
| 644 } |
| 645 |
| 646 |
| 647 void TimelineEventBlockIterator::Reset() { |
| 648 current_ = NULL; |
| 649 } |
| 650 |
| 651 |
| 652 bool TimelineEventBlockIterator::Next() { |
| 653 if (recorder_ == NULL) { |
| 654 return false; |
| 655 } |
| 656 if (current_ == NULL) { |
| 657 current_ = recorder_->head_; |
| 658 } else { |
| 659 current_ = current_->next(); |
| 660 } |
| 661 return current_ != NULL; |
| 662 } |
| 663 |
589 } // namespace dart | 664 } // namespace dart |
OLD | NEW |