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 28 matching lines...) Expand all Loading... |
39 public: | 39 public: |
40 // Initialize timeline system. Not thread safe. | 40 // Initialize timeline system. Not thread safe. |
41 static void InitOnce(); | 41 static void InitOnce(); |
42 | 42 |
43 // Shutdown timeline system. Not thread safe. | 43 // Shutdown timeline system. Not thread safe. |
44 static void Shutdown(); | 44 static void Shutdown(); |
45 | 45 |
46 // Access the global recorder. Not thread safe. | 46 // Access the global recorder. Not thread safe. |
47 static TimelineEventRecorder* recorder(); | 47 static TimelineEventRecorder* recorder(); |
48 | 48 |
49 static bool EnableStreamByDefault(const char* stream_name); | 49 static void SetupIsolateStreams(Isolate* isolate); |
50 | 50 |
51 static TimelineStream* GetVMStream(); | 51 static TimelineStream* GetVMStream(); |
52 | 52 |
53 static TimelineStream* GetVMApiStream(); | 53 static TimelineStream* GetVMApiStream(); |
54 | 54 |
55 // Reclaim all |TimelineEventBlocks|s that are cached by threads. | 55 // Reclaim all |TimelineEventBlocks|s that are cached by threads. |
56 static void ReclaimCachedBlocksFromThreads(); | 56 static void ReclaimCachedBlocksFromThreads(); |
57 | 57 |
58 static void Clear(); | 58 static void Clear(); |
59 | 59 |
| 60 // Print information about streams to JSON. |
| 61 static void PrintFlagsToJSON(JSONStream* json); |
| 62 |
60 #define ISOLATE_TIMELINE_STREAM_FLAGS(name, not_used) \ | 63 #define ISOLATE_TIMELINE_STREAM_FLAGS(name, not_used) \ |
61 static const bool* Stream##name##EnabledFlag() { \ | 64 static const bool* Stream##name##EnabledFlag() { \ |
62 return &stream_##name##_enabled_; \ | 65 return &stream_##name##_enabled_; \ |
63 } \ | 66 } \ |
64 static void SetStream##name##Enabled(bool enabled) { \ | 67 static void SetStream##name##Enabled(bool enabled) { \ |
65 stream_##name##_enabled_ = enabled; \ | 68 stream_##name##_enabled_ = enabled; \ |
66 } | 69 } |
67 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_FLAGS) | 70 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_FLAGS) |
68 #undef ISOLATE_TIMELINE_STREAM_FLAGS | 71 #undef ISOLATE_TIMELINE_STREAM_FLAGS |
| 72 static void SetVMStreamEnabled(bool enabled); |
69 | 73 |
70 private: | 74 private: |
71 static TimelineEventRecorder* recorder_; | 75 static TimelineEventRecorder* recorder_; |
72 static TimelineStream vm_stream_; | 76 static TimelineStream vm_stream_; |
73 static TimelineStream vm_api_stream_; | 77 static TimelineStream vm_api_stream_; |
| 78 static MallocGrowableArray<char*>* enabled_streams_; |
74 | 79 |
75 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \ | 80 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \ |
76 static bool stream_##name##_enabled_; | 81 static bool stream_##name##_enabled_; |
77 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG) | 82 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG) |
78 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG | 83 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG |
79 | 84 |
80 friend class TimelineRecorderOverride; | 85 friend class TimelineRecorderOverride; |
81 friend class ReclaimBlocksIsolateVisitor; | 86 friend class ReclaimBlocksIsolateVisitor; |
82 }; | 87 }; |
83 | 88 |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 class TimelineEventRecorder { | 616 class TimelineEventRecorder { |
612 public: | 617 public: |
613 TimelineEventRecorder(); | 618 TimelineEventRecorder(); |
614 virtual ~TimelineEventRecorder() {} | 619 virtual ~TimelineEventRecorder() {} |
615 | 620 |
616 TimelineEventBlock* GetNewBlock(); | 621 TimelineEventBlock* GetNewBlock(); |
617 | 622 |
618 // Interface method(s) which must be implemented. | 623 // Interface method(s) which must be implemented. |
619 virtual void PrintJSON(JSONStream* js, TimelineEventFilter* filter) = 0; | 624 virtual void PrintJSON(JSONStream* js, TimelineEventFilter* filter) = 0; |
620 virtual void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter) = 0; | 625 virtual void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter) = 0; |
621 | 626 virtual const char* name() const = 0; |
622 int64_t GetNextAsyncId(); | 627 int64_t GetNextAsyncId(); |
623 | 628 |
624 void FinishBlock(TimelineEventBlock* block); | 629 void FinishBlock(TimelineEventBlock* block); |
625 | 630 |
626 protected: | 631 protected: |
627 void WriteTo(const char* directory); | 632 void WriteTo(const char* directory); |
628 | 633 |
629 // Interface method(s) which must be implemented. | 634 // Interface method(s) which must be implemented. |
630 virtual TimelineEvent* StartEvent() = 0; | 635 virtual TimelineEvent* StartEvent() = 0; |
631 virtual void CompleteEvent(TimelineEvent* event) = 0; | 636 virtual void CompleteEvent(TimelineEvent* event) = 0; |
(...skipping 23 matching lines...) Expand all Loading... |
655 // A recorder that stores events in a ring buffer of fixed capacity. | 660 // A recorder that stores events in a ring buffer of fixed capacity. |
656 class TimelineEventRingRecorder : public TimelineEventRecorder { | 661 class TimelineEventRingRecorder : public TimelineEventRecorder { |
657 public: | 662 public: |
658 static const intptr_t kDefaultCapacity = 8192; | 663 static const intptr_t kDefaultCapacity = 8192; |
659 | 664 |
660 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity); | 665 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity); |
661 ~TimelineEventRingRecorder(); | 666 ~TimelineEventRingRecorder(); |
662 | 667 |
663 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 668 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
664 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 669 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
| 670 const char* name() const { |
| 671 return "ring"; |
| 672 } |
665 | 673 |
666 protected: | 674 protected: |
667 TimelineEvent* StartEvent(); | 675 TimelineEvent* StartEvent(); |
668 void CompleteEvent(TimelineEvent* event); | 676 void CompleteEvent(TimelineEvent* event); |
669 TimelineEventBlock* GetHeadBlockLocked(); | 677 TimelineEventBlock* GetHeadBlockLocked(); |
670 intptr_t FindOldestBlockIndex() const; | 678 intptr_t FindOldestBlockIndex() const; |
671 TimelineEventBlock* GetNewBlockLocked(); | 679 TimelineEventBlock* GetNewBlockLocked(); |
672 void Clear(); | 680 void Clear(); |
673 | 681 |
674 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); | 682 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); |
(...skipping 11 matching lines...) Expand all Loading... |
686 TimelineEventStreamingRecorder(); | 694 TimelineEventStreamingRecorder(); |
687 ~TimelineEventStreamingRecorder(); | 695 ~TimelineEventStreamingRecorder(); |
688 | 696 |
689 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 697 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
690 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 698 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
691 | 699 |
692 // Called when |event| is ready to be streamed. It is unsafe to keep a | 700 // Called when |event| is ready to be streamed. It is unsafe to keep a |
693 // reference to |event| as it may be freed as soon as this function returns. | 701 // reference to |event| as it may be freed as soon as this function returns. |
694 virtual void StreamEvent(TimelineEvent* event) = 0; | 702 virtual void StreamEvent(TimelineEvent* event) = 0; |
695 | 703 |
| 704 const char* name() const { |
| 705 return "streaming"; |
| 706 } |
| 707 |
696 protected: | 708 protected: |
697 TimelineEventBlock* GetNewBlockLocked() { | 709 TimelineEventBlock* GetNewBlockLocked() { |
698 return NULL; | 710 return NULL; |
699 } | 711 } |
700 TimelineEventBlock* GetHeadBlockLocked() { | 712 TimelineEventBlock* GetHeadBlockLocked() { |
701 return NULL; | 713 return NULL; |
702 } | 714 } |
703 void Clear() { | 715 void Clear() { |
704 } | 716 } |
705 TimelineEvent* StartEvent(); | 717 TimelineEvent* StartEvent(); |
706 void CompleteEvent(TimelineEvent* event); | 718 void CompleteEvent(TimelineEvent* event); |
707 }; | 719 }; |
708 | 720 |
709 | 721 |
710 // A recorder that stores events in chains of blocks of events. | 722 // A recorder that stores events in chains of blocks of events. |
711 // NOTE: This recorder will continue to allocate blocks until it exhausts | 723 // NOTE: This recorder will continue to allocate blocks until it exhausts |
712 // memory. | 724 // memory. |
713 class TimelineEventEndlessRecorder : public TimelineEventRecorder { | 725 class TimelineEventEndlessRecorder : public TimelineEventRecorder { |
714 public: | 726 public: |
715 TimelineEventEndlessRecorder(); | 727 TimelineEventEndlessRecorder(); |
716 | 728 |
717 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 729 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
718 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 730 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
719 | 731 |
| 732 const char* name() const { |
| 733 return "endless"; |
| 734 } |
| 735 |
720 protected: | 736 protected: |
721 TimelineEvent* StartEvent(); | 737 TimelineEvent* StartEvent(); |
722 void CompleteEvent(TimelineEvent* event); | 738 void CompleteEvent(TimelineEvent* event); |
723 TimelineEventBlock* GetNewBlockLocked(); | 739 TimelineEventBlock* GetNewBlockLocked(); |
724 TimelineEventBlock* GetHeadBlockLocked(); | 740 TimelineEventBlock* GetHeadBlockLocked(); |
725 void Clear(); | 741 void Clear(); |
726 | 742 |
727 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); | 743 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); |
728 | 744 |
729 TimelineEventBlock* head_; | 745 TimelineEventBlock* head_; |
(...skipping 19 matching lines...) Expand all Loading... |
749 | 765 |
750 private: | 766 private: |
751 TimelineEventBlock* current_; | 767 TimelineEventBlock* current_; |
752 TimelineEventRecorder* recorder_; | 768 TimelineEventRecorder* recorder_; |
753 }; | 769 }; |
754 | 770 |
755 | 771 |
756 } // namespace dart | 772 } // namespace dart |
757 | 773 |
758 #endif // VM_TIMELINE_H_ | 774 #endif // VM_TIMELINE_H_ |
OLD | NEW |