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 #ifndef VM_TIMELINE_H_ | 5 #ifndef VM_TIMELINE_H_ |
6 #define VM_TIMELINE_H_ | 6 #define VM_TIMELINE_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/bitfield.h" | 9 #include "vm/bitfield.h" |
10 | 10 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const char* name, | 74 const char* name, |
75 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5); | 75 const char* fmt, ...) PRINTF_ATTRIBUTE(4, 5); |
76 | 76 |
77 // Mandatory to call when this event is completely filled out. | 77 // Mandatory to call when this event is completely filled out. |
78 void Complete(); | 78 void Complete(); |
79 | 79 |
80 EventType event_type() const { | 80 EventType event_type() const { |
81 return EventTypeField::decode(state_); | 81 return EventTypeField::decode(state_); |
82 } | 82 } |
83 | 83 |
| 84 bool IsFinishedDuration() const { |
| 85 return (event_type() == kDuration) && (timestamp1_ > timestamp0_); |
| 86 } |
| 87 |
84 int64_t TimeOrigin() const; | 88 int64_t TimeOrigin() const; |
85 int64_t AsyncId() const; | 89 int64_t AsyncId() const; |
86 int64_t TimeDuration() const; | 90 int64_t TimeDuration() const; |
| 91 int64_t TimeEnd() const { |
| 92 ASSERT(IsFinishedDuration()); |
| 93 return timestamp1_; |
| 94 } |
87 | 95 |
88 void PrintJSON(JSONStream* stream) const; | 96 void PrintJSON(JSONStream* stream) const; |
89 | 97 |
90 ThreadId thread() const { | 98 ThreadId thread() const { |
91 return thread_; | 99 return thread_; |
92 } | 100 } |
93 | 101 |
94 const char* label() const { | 102 const char* label() const { |
95 return label_; | 103 return label_; |
96 } | 104 } |
97 | 105 |
| 106 // Does this duration end before |micros| ? |
| 107 bool DurationFinishedBefore(int64_t micros) const { |
| 108 return TimeEnd() <= micros; |
| 109 } |
| 110 |
| 111 // Does this duration fully contain |other| ? |
| 112 bool DurationContains(TimelineEvent* other) const { |
| 113 ASSERT(IsFinishedDuration()); |
| 114 ASSERT(other->IsFinishedDuration()); |
| 115 if (other->TimeOrigin() < TimeOrigin()) { |
| 116 return false; |
| 117 } |
| 118 if (other->TimeEnd() < TimeOrigin()) { |
| 119 return false; |
| 120 } |
| 121 if (other->TimeOrigin() > TimeEnd()) { |
| 122 return false; |
| 123 } |
| 124 if (other->TimeEnd() > TimeEnd()) { |
| 125 return false; |
| 126 } |
| 127 return true; |
| 128 } |
| 129 |
98 private: | 130 private: |
99 struct TimelineEventArgument { | 131 struct TimelineEventArgument { |
100 const char* name; | 132 const char* name; |
101 char* value; | 133 char* value; |
102 }; | 134 }; |
103 | 135 |
104 int64_t timestamp0_; | 136 int64_t timestamp0_; |
105 int64_t timestamp1_; | 137 int64_t timestamp1_; |
106 TimelineEventArgument* arguments_; | 138 TimelineEventArgument* arguments_; |
107 intptr_t arguments_length_; | 139 intptr_t arguments_length_; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 virtual void CompleteEvent(TimelineEvent* event) = 0; | 396 virtual void CompleteEvent(TimelineEvent* event) = 0; |
365 | 397 |
366 // Utility method(s). | 398 // Utility method(s). |
367 void PrintJSONMeta(JSONArray* array) const; | 399 void PrintJSONMeta(JSONArray* array) const; |
368 TimelineEvent* ThreadBlockStartEvent(); | 400 TimelineEvent* ThreadBlockStartEvent(); |
369 | 401 |
370 Mutex lock_; | 402 Mutex lock_; |
371 | 403 |
372 friend class TimelineEventBlockIterator; | 404 friend class TimelineEventBlockIterator; |
373 friend class TimelineStream; | 405 friend class TimelineStream; |
| 406 friend class TimelineTestHelper; |
374 friend class Isolate; | 407 friend class Isolate; |
375 | 408 |
376 private: | 409 private: |
377 DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder); | 410 DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder); |
378 }; | 411 }; |
379 | 412 |
380 | 413 |
381 // A recorder that stores events in a ring buffer of fixed capacity. | 414 // A recorder that stores events in a ring buffer of fixed capacity. |
382 // This recorder does track Dart objects. | 415 // This recorder does track Dart objects. |
383 class TimelineEventRingRecorder : public TimelineEventRecorder { | 416 class TimelineEventRingRecorder : public TimelineEventRecorder { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 | 494 |
462 protected: | 495 protected: |
463 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 496 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
464 TimelineEvent* StartEvent(const Object& object); | 497 TimelineEvent* StartEvent(const Object& object); |
465 TimelineEvent* StartEvent(); | 498 TimelineEvent* StartEvent(); |
466 void CompleteEvent(TimelineEvent* event); | 499 void CompleteEvent(TimelineEvent* event); |
467 | 500 |
468 TimelineEventBlock* GetNewBlockLocked(); | 501 TimelineEventBlock* GetNewBlockLocked(); |
469 void PrintJSONEvents(JSONArray* array) const; | 502 void PrintJSONEvents(JSONArray* array) const; |
470 | 503 |
| 504 // Useful only for testing. Only works for one thread. |
| 505 void Clear(); |
| 506 |
471 TimelineEventBlock* head_; | 507 TimelineEventBlock* head_; |
472 intptr_t block_index_; | 508 intptr_t block_index_; |
| 509 |
| 510 friend class TimelineTestHelper; |
473 }; | 511 }; |
474 | 512 |
475 | 513 |
476 // An iterator for blocks. | 514 // An iterator for blocks. |
477 class TimelineEventBlockIterator { | 515 class TimelineEventBlockIterator { |
478 public: | 516 public: |
479 explicit TimelineEventBlockIterator(TimelineEventRecorder* recorder); | 517 explicit TimelineEventBlockIterator(TimelineEventRecorder* recorder); |
480 ~TimelineEventBlockIterator(); | 518 ~TimelineEventBlockIterator(); |
481 | 519 |
482 void Reset(TimelineEventRecorder* recorder); | 520 void Reset(TimelineEventRecorder* recorder); |
483 | 521 |
484 // Returns false when there are no more blocks. | 522 // Returns false when there are no more blocks. |
485 bool HasNext() const; | 523 bool HasNext() const; |
486 | 524 |
487 // Returns the next block and moves forward. | 525 // Returns the next block and moves forward. |
488 TimelineEventBlock* Next(); | 526 TimelineEventBlock* Next(); |
489 | 527 |
490 private: | 528 private: |
491 TimelineEventBlock* current_; | 529 TimelineEventBlock* current_; |
492 TimelineEventRecorder* recorder_; | 530 TimelineEventRecorder* recorder_; |
493 }; | 531 }; |
494 | 532 |
495 } // namespace dart | 533 } // namespace dart |
496 | 534 |
497 #endif // VM_TIMELINE_H_ | 535 #endif // VM_TIMELINE_H_ |
OLD | NEW |