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_; |
74 | 78 |
75 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \ | 79 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \ |
76 static bool stream_##name##_enabled_; | 80 static bool stream_##name##_enabled_; |
77 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG) | 81 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG) |
78 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG | 82 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 class TimelineEventRecorder { | 615 class TimelineEventRecorder { |
612 public: | 616 public: |
613 TimelineEventRecorder(); | 617 TimelineEventRecorder(); |
614 virtual ~TimelineEventRecorder() {} | 618 virtual ~TimelineEventRecorder() {} |
615 | 619 |
616 TimelineEventBlock* GetNewBlock(); | 620 TimelineEventBlock* GetNewBlock(); |
617 | 621 |
618 // Interface method(s) which must be implemented. | 622 // Interface method(s) which must be implemented. |
619 virtual void PrintJSON(JSONStream* js, TimelineEventFilter* filter) = 0; | 623 virtual void PrintJSON(JSONStream* js, TimelineEventFilter* filter) = 0; |
620 virtual void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter) = 0; | 624 virtual void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter) = 0; |
621 | 625 virtual const char* name() const = 0; |
622 int64_t GetNextAsyncId(); | 626 int64_t GetNextAsyncId(); |
623 | 627 |
624 void FinishBlock(TimelineEventBlock* block); | 628 void FinishBlock(TimelineEventBlock* block); |
625 | 629 |
626 protected: | 630 protected: |
627 void WriteTo(const char* directory); | 631 void WriteTo(const char* directory); |
628 | 632 |
629 // Interface method(s) which must be implemented. | 633 // Interface method(s) which must be implemented. |
630 virtual TimelineEvent* StartEvent() = 0; | 634 virtual TimelineEvent* StartEvent() = 0; |
631 virtual void CompleteEvent(TimelineEvent* event) = 0; | 635 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. | 659 // A recorder that stores events in a ring buffer of fixed capacity. |
656 class TimelineEventRingRecorder : public TimelineEventRecorder { | 660 class TimelineEventRingRecorder : public TimelineEventRecorder { |
657 public: | 661 public: |
658 static const intptr_t kDefaultCapacity = 8192; | 662 static const intptr_t kDefaultCapacity = 8192; |
659 | 663 |
660 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity); | 664 explicit TimelineEventRingRecorder(intptr_t capacity = kDefaultCapacity); |
661 ~TimelineEventRingRecorder(); | 665 ~TimelineEventRingRecorder(); |
662 | 666 |
663 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 667 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
664 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 668 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
| 669 const char* name() const { |
| 670 return "ring"; |
| 671 } |
665 | 672 |
666 protected: | 673 protected: |
667 TimelineEvent* StartEvent(); | 674 TimelineEvent* StartEvent(); |
668 void CompleteEvent(TimelineEvent* event); | 675 void CompleteEvent(TimelineEvent* event); |
669 TimelineEventBlock* GetHeadBlockLocked(); | 676 TimelineEventBlock* GetHeadBlockLocked(); |
670 intptr_t FindOldestBlockIndex() const; | 677 intptr_t FindOldestBlockIndex() const; |
671 TimelineEventBlock* GetNewBlockLocked(); | 678 TimelineEventBlock* GetNewBlockLocked(); |
672 void Clear(); | 679 void Clear(); |
673 | 680 |
674 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); | 681 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); |
(...skipping 11 matching lines...) Expand all Loading... |
686 TimelineEventStreamingRecorder(); | 693 TimelineEventStreamingRecorder(); |
687 ~TimelineEventStreamingRecorder(); | 694 ~TimelineEventStreamingRecorder(); |
688 | 695 |
689 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 696 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
690 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 697 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
691 | 698 |
692 // Called when |event| is ready to be streamed. It is unsafe to keep a | 699 // 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. | 700 // reference to |event| as it may be freed as soon as this function returns. |
694 virtual void StreamEvent(TimelineEvent* event) = 0; | 701 virtual void StreamEvent(TimelineEvent* event) = 0; |
695 | 702 |
| 703 const char* name() const { |
| 704 return "streaming"; |
| 705 } |
| 706 |
696 protected: | 707 protected: |
697 TimelineEventBlock* GetNewBlockLocked() { | 708 TimelineEventBlock* GetNewBlockLocked() { |
698 return NULL; | 709 return NULL; |
699 } | 710 } |
700 TimelineEventBlock* GetHeadBlockLocked() { | 711 TimelineEventBlock* GetHeadBlockLocked() { |
701 return NULL; | 712 return NULL; |
702 } | 713 } |
703 void Clear() { | 714 void Clear() { |
704 } | 715 } |
705 TimelineEvent* StartEvent(); | 716 TimelineEvent* StartEvent(); |
706 void CompleteEvent(TimelineEvent* event); | 717 void CompleteEvent(TimelineEvent* event); |
707 }; | 718 }; |
708 | 719 |
709 | 720 |
710 // A recorder that stores events in chains of blocks of events. | 721 // A recorder that stores events in chains of blocks of events. |
711 // NOTE: This recorder will continue to allocate blocks until it exhausts | 722 // NOTE: This recorder will continue to allocate blocks until it exhausts |
712 // memory. | 723 // memory. |
713 class TimelineEventEndlessRecorder : public TimelineEventRecorder { | 724 class TimelineEventEndlessRecorder : public TimelineEventRecorder { |
714 public: | 725 public: |
715 TimelineEventEndlessRecorder(); | 726 TimelineEventEndlessRecorder(); |
716 | 727 |
717 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); | 728 void PrintJSON(JSONStream* js, TimelineEventFilter* filter); |
718 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); | 729 void PrintTraceEvent(JSONStream* js, TimelineEventFilter* filter); |
719 | 730 |
| 731 const char* name() const { |
| 732 return "endless"; |
| 733 } |
| 734 |
720 protected: | 735 protected: |
721 TimelineEvent* StartEvent(); | 736 TimelineEvent* StartEvent(); |
722 void CompleteEvent(TimelineEvent* event); | 737 void CompleteEvent(TimelineEvent* event); |
723 TimelineEventBlock* GetNewBlockLocked(); | 738 TimelineEventBlock* GetNewBlockLocked(); |
724 TimelineEventBlock* GetHeadBlockLocked(); | 739 TimelineEventBlock* GetHeadBlockLocked(); |
725 void Clear(); | 740 void Clear(); |
726 | 741 |
727 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); | 742 void PrintJSONEvents(JSONArray* array, TimelineEventFilter* filter); |
728 | 743 |
729 TimelineEventBlock* head_; | 744 TimelineEventBlock* head_; |
(...skipping 19 matching lines...) Expand all Loading... |
749 | 764 |
750 private: | 765 private: |
751 TimelineEventBlock* current_; | 766 TimelineEventBlock* current_; |
752 TimelineEventRecorder* recorder_; | 767 TimelineEventRecorder* recorder_; |
753 }; | 768 }; |
754 | 769 |
755 | 770 |
756 } // namespace dart | 771 } // namespace dart |
757 | 772 |
758 #endif // VM_TIMELINE_H_ | 773 #endif // VM_TIMELINE_H_ |
OLD | NEW |