| 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 #include "vm/os.h" | 10 #include "vm/os.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class TimelineEventBlock; | 23 class TimelineEventBlock; |
| 24 class TimelineEventRecorder; | 24 class TimelineEventRecorder; |
| 25 class TimelineStream; | 25 class TimelineStream; |
| 26 class Zone; | 26 class Zone; |
| 27 | 27 |
| 28 // (name, enabled by default for isolate). | 28 // (name, enabled by default for isolate). |
| 29 #define ISOLATE_TIMELINE_STREAM_LIST(V) \ | 29 #define ISOLATE_TIMELINE_STREAM_LIST(V) \ |
| 30 V(API, false) \ | 30 V(API, false) \ |
| 31 V(Compiler, false) \ | 31 V(Compiler, false) \ |
| 32 V(Dart, false) \ | 32 V(Dart, false) \ |
| 33 V(Debugger, false) \ |
| 33 V(Embedder, false) \ | 34 V(Embedder, false) \ |
| 34 V(GC, false) \ | 35 V(GC, false) \ |
| 35 V(Isolate, false) \ | 36 V(Isolate, false) \ |
| 36 | 37 |
| 37 class Timeline : public AllStatic { | 38 class Timeline : public AllStatic { |
| 38 public: | 39 public: |
| 39 // Initialize timeline system. Not thread safe. | 40 // Initialize timeline system. Not thread safe. |
| 40 static void InitOnce(); | 41 static void InitOnce(); |
| 41 | 42 |
| 42 // Shutdown timeline system. Not thread safe. | 43 // Shutdown timeline system. Not thread safe. |
| 43 static void Shutdown(); | 44 static void Shutdown(); |
| 44 | 45 |
| 45 // Access the global recorder. Not thread safe. | 46 // Access the global recorder. Not thread safe. |
| 46 static TimelineEventRecorder* recorder(); | 47 static TimelineEventRecorder* recorder(); |
| 47 | 48 |
| 48 static bool EnableStreamByDefault(const char* stream_name); | 49 static bool EnableStreamByDefault(const char* stream_name); |
| 49 | 50 |
| 50 static TimelineStream* GetVMStream(); | 51 static TimelineStream* GetVMStream(); |
| 51 | 52 |
| 52 // Reclaim all |TimelineEventBlocks|s that are cached by threads. | 53 // Reclaim all |TimelineEventBlocks|s that are cached by threads. |
| 53 static void ReclaimCachedBlocksFromThreads(); | 54 static void ReclaimCachedBlocksFromThreads(); |
| 54 | 55 |
| 56 static void Clear(); |
| 57 |
| 55 #define ISOLATE_TIMELINE_STREAM_FLAGS(name, not_used) \ | 58 #define ISOLATE_TIMELINE_STREAM_FLAGS(name, not_used) \ |
| 56 static const bool* Stream##name##EnabledFlag() { \ | 59 static const bool* Stream##name##EnabledFlag() { \ |
| 57 return &stream_##name##_enabled_; \ | 60 return &stream_##name##_enabled_; \ |
| 58 } \ | 61 } \ |
| 59 static void SetStream##name##Enabled(bool enabled) { \ | 62 static void SetStream##name##Enabled(bool enabled) { \ |
| 60 stream_##name##_enabled_ = enabled; \ | 63 stream_##name##_enabled_ = enabled; \ |
| 61 } | 64 } |
| 62 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_FLAGS) | 65 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_FLAGS) |
| 63 #undef ISOLATE_TIMELINE_STREAM_FLAGS | 66 #undef ISOLATE_TIMELINE_STREAM_FLAGS |
| 64 | 67 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 void FinishBlock(TimelineEventBlock* block); | 519 void FinishBlock(TimelineEventBlock* block); |
| 517 | 520 |
| 518 protected: | 521 protected: |
| 519 void WriteTo(const char* directory); | 522 void WriteTo(const char* directory); |
| 520 | 523 |
| 521 // Interface method(s) which must be implemented. | 524 // Interface method(s) which must be implemented. |
| 522 virtual TimelineEvent* StartEvent() = 0; | 525 virtual TimelineEvent* StartEvent() = 0; |
| 523 virtual void CompleteEvent(TimelineEvent* event) = 0; | 526 virtual void CompleteEvent(TimelineEvent* event) = 0; |
| 524 virtual TimelineEventBlock* GetHeadBlockLocked() = 0; | 527 virtual TimelineEventBlock* GetHeadBlockLocked() = 0; |
| 525 virtual TimelineEventBlock* GetNewBlockLocked() = 0; | 528 virtual TimelineEventBlock* GetNewBlockLocked() = 0; |
| 529 virtual void Clear() = 0; |
| 526 | 530 |
| 527 // Utility method(s). | 531 // Utility method(s). |
| 528 void PrintJSONMeta(JSONArray* array) const; | 532 void PrintJSONMeta(JSONArray* array) const; |
| 529 TimelineEvent* ThreadBlockStartEvent(); | 533 TimelineEvent* ThreadBlockStartEvent(); |
| 530 void ThreadBlockCompleteEvent(TimelineEvent* event); | 534 void ThreadBlockCompleteEvent(TimelineEvent* event); |
| 531 | 535 |
| 532 Mutex lock_; | 536 Mutex lock_; |
| 533 uintptr_t async_id_; | 537 uintptr_t async_id_; |
| 534 | 538 |
| 535 friend class TimelineEvent; | 539 friend class TimelineEvent; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 553 | 557 |
| 554 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 558 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
| 555 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 559 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
| 556 | 560 |
| 557 protected: | 561 protected: |
| 558 TimelineEvent* StartEvent(); | 562 TimelineEvent* StartEvent(); |
| 559 void CompleteEvent(TimelineEvent* event); | 563 void CompleteEvent(TimelineEvent* event); |
| 560 TimelineEventBlock* GetHeadBlockLocked(); | 564 TimelineEventBlock* GetHeadBlockLocked(); |
| 561 intptr_t FindOldestBlockIndex() const; | 565 intptr_t FindOldestBlockIndex() const; |
| 562 TimelineEventBlock* GetNewBlockLocked(); | 566 TimelineEventBlock* GetNewBlockLocked(); |
| 567 void Clear(); |
| 563 | 568 |
| 564 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter) const; | 569 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); |
| 565 | 570 |
| 566 TimelineEventBlock** blocks_; | 571 TimelineEventBlock** blocks_; |
| 567 intptr_t capacity_; | 572 intptr_t capacity_; |
| 568 intptr_t num_blocks_; | 573 intptr_t num_blocks_; |
| 569 intptr_t block_cursor_; | 574 intptr_t block_cursor_; |
| 570 }; | 575 }; |
| 571 | 576 |
| 572 | 577 |
| 573 // An abstract recorder that calls |StreamEvent| whenever an event is complete. | 578 // An abstract recorder that calls |StreamEvent| whenever an event is complete. |
| 574 class TimelineEventStreamingRecorder : public TimelineEventRecorder { | 579 class TimelineEventStreamingRecorder : public TimelineEventRecorder { |
| 575 public: | 580 public: |
| 576 TimelineEventStreamingRecorder(); | 581 TimelineEventStreamingRecorder(); |
| 577 ~TimelineEventStreamingRecorder(); | 582 ~TimelineEventStreamingRecorder(); |
| 578 | 583 |
| 579 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 584 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
| 580 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 585 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
| 581 | 586 |
| 582 // Called when |event| is ready to be streamed. It is unsafe to keep a | 587 // Called when |event| is ready to be streamed. It is unsafe to keep a |
| 583 // reference to |event| as it may be freed as soon as this function returns. | 588 // reference to |event| as it may be freed as soon as this function returns. |
| 584 virtual void StreamEvent(TimelineEvent* event) = 0; | 589 virtual void StreamEvent(TimelineEvent* event) = 0; |
| 585 | 590 |
| 586 protected: | 591 protected: |
| 587 TimelineEventBlock* GetNewBlockLocked() { | 592 TimelineEventBlock* GetNewBlockLocked() { |
| 588 return NULL; | 593 return NULL; |
| 589 } | 594 } |
| 590 TimelineEventBlock* GetHeadBlockLocked() { | 595 TimelineEventBlock* GetHeadBlockLocked() { |
| 591 return NULL; | 596 return NULL; |
| 592 } | 597 } |
| 598 void Clear() { |
| 599 } |
| 593 TimelineEvent* StartEvent(); | 600 TimelineEvent* StartEvent(); |
| 594 void CompleteEvent(TimelineEvent* event); | 601 void CompleteEvent(TimelineEvent* event); |
| 595 }; | 602 }; |
| 596 | 603 |
| 597 | 604 |
| 598 // A recorder that stores events in chains of blocks of events. | 605 // A recorder that stores events in chains of blocks of events. |
| 599 // NOTE: This recorder will continue to allocate blocks until it exhausts | 606 // NOTE: This recorder will continue to allocate blocks until it exhausts |
| 600 // memory. | 607 // memory. |
| 601 class TimelineEventEndlessRecorder : public TimelineEventRecorder { | 608 class TimelineEventEndlessRecorder : public TimelineEventRecorder { |
| 602 public: | 609 public: |
| 603 TimelineEventEndlessRecorder(); | 610 TimelineEventEndlessRecorder(); |
| 604 | 611 |
| 605 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 612 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
| 606 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 613 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
| 607 | 614 |
| 608 protected: | 615 protected: |
| 609 TimelineEvent* StartEvent(); | 616 TimelineEvent* StartEvent(); |
| 610 void CompleteEvent(TimelineEvent* event); | 617 void CompleteEvent(TimelineEvent* event); |
| 611 TimelineEventBlock* GetNewBlockLocked(); | 618 TimelineEventBlock* GetNewBlockLocked(); |
| 612 TimelineEventBlock* GetHeadBlockLocked(); | 619 TimelineEventBlock* GetHeadBlockLocked(); |
| 620 void Clear(); |
| 613 | 621 |
| 614 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter) const; | 622 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); |
| 615 | |
| 616 // Useful only for testing. Only works for one thread. | |
| 617 void Clear(); | |
| 618 | 623 |
| 619 TimelineEventBlock* head_; | 624 TimelineEventBlock* head_; |
| 620 intptr_t block_index_; | 625 intptr_t block_index_; |
| 621 | 626 |
| 622 friend class TimelineTestHelper; | 627 friend class TimelineTestHelper; |
| 623 }; | 628 }; |
| 624 | 629 |
| 625 | 630 |
| 626 // An iterator for blocks. | 631 // An iterator for blocks. |
| 627 class TimelineEventBlockIterator { | 632 class TimelineEventBlockIterator { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 639 | 644 |
| 640 private: | 645 private: |
| 641 TimelineEventBlock* current_; | 646 TimelineEventBlock* current_; |
| 642 TimelineEventRecorder* recorder_; | 647 TimelineEventRecorder* recorder_; |
| 643 }; | 648 }; |
| 644 | 649 |
| 645 | 650 |
| 646 } // namespace dart | 651 } // namespace dart |
| 647 | 652 |
| 648 #endif // VM_TIMELINE_H_ | 653 #endif // VM_TIMELINE_H_ |
| OLD | NEW |