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 "include/dart_tools_api.h" | 8 #include "include/dart_tools_api.h" |
9 | 9 |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class Isolate; | 21 class Isolate; |
22 class RawArray; | 22 class RawArray; |
23 class Thread; | 23 class Thread; |
24 class TimelineEvent; | 24 class TimelineEvent; |
25 class TimelineEventBlock; | 25 class TimelineEventBlock; |
26 class TimelineEventRecorder; | 26 class TimelineEventRecorder; |
27 class TimelineStream; | 27 class TimelineStream; |
28 class Zone; | 28 class Zone; |
29 | 29 |
30 // (name, enabled by default for isolate). | 30 // (name, enabled by default for isolate). |
31 #define ISOLATE_TIMELINE_STREAM_LIST(V) \ | 31 #define TIMELINE_STREAM_LIST(V) \ |
32 V(API, false) \ | 32 V(API, false) \ |
33 V(Compiler, false) \ | 33 V(Compiler, false) \ |
34 V(Dart, false) \ | 34 V(Dart, false) \ |
35 V(Debugger, false) \ | 35 V(Debugger, false) \ |
36 V(Embedder, false) \ | 36 V(Embedder, false) \ |
37 V(GC, false) \ | 37 V(GC, false) \ |
38 V(Isolate, false) \ | 38 V(Isolate, false) \ |
| 39 V(VM, false) |
39 | 40 |
40 class Timeline : public AllStatic { | 41 class Timeline : public AllStatic { |
41 public: | 42 public: |
42 // Initialize timeline system. Not thread safe. | 43 // Initialize timeline system. Not thread safe. |
43 static void InitOnce(); | 44 static void InitOnce(); |
44 | 45 |
45 // Shutdown timeline system. Not thread safe. | 46 // Shutdown timeline system. Not thread safe. |
46 static void Shutdown(); | 47 static void Shutdown(); |
47 | 48 |
48 // Access the global recorder. Not thread safe. | 49 // Access the global recorder. Not thread safe. |
49 static TimelineEventRecorder* recorder(); | 50 static TimelineEventRecorder* recorder(); |
50 | 51 |
51 static void SetupIsolateStreams(Isolate* isolate); | |
52 | |
53 static TimelineStream* GetVMStream(); | |
54 | |
55 static TimelineStream* GetVMApiStream(); | |
56 | |
57 // Reclaim all |TimelineEventBlocks|s that are cached by threads. | 52 // Reclaim all |TimelineEventBlocks|s that are cached by threads. |
58 static void ReclaimCachedBlocksFromThreads(); | 53 static void ReclaimCachedBlocksFromThreads(); |
59 | 54 |
60 static void Clear(); | 55 static void Clear(); |
61 | 56 |
62 // Print information about streams to JSON. | 57 // Print information about streams to JSON. |
63 static void PrintFlagsToJSON(JSONStream* json); | 58 static void PrintFlagsToJSON(JSONStream* json); |
64 | 59 |
65 #define ISOLATE_TIMELINE_STREAM_FLAGS(name, not_used) \ | 60 #define TIMELINE_STREAM_ACCESSOR(name, not_used) \ |
| 61 static TimelineStream* Get##name##Stream() { return &stream_##name##_; } |
| 62 TIMELINE_STREAM_LIST(TIMELINE_STREAM_ACCESSOR) |
| 63 #undef TIMELINE_STREAM_ACCESSOR |
| 64 |
| 65 #define TIMELINE_STREAM_FLAGS(name, not_used) \ |
66 static const bool* Stream##name##EnabledFlag() { \ | 66 static const bool* Stream##name##EnabledFlag() { \ |
67 return &stream_##name##_enabled_; \ | 67 return &stream_##name##_enabled_; \ |
68 } \ | 68 } \ |
69 static void SetStream##name##Enabled(bool enabled) { \ | 69 static void SetStream##name##Enabled(bool enabled) { \ |
70 StreamStateChange(#name, stream_##name##_enabled_, enabled); \ | 70 StreamStateChange(#name, stream_##name##_enabled_, enabled); \ |
71 stream_##name##_enabled_ = enabled; \ | 71 stream_##name##_enabled_ = enabled; \ |
72 } | 72 } |
73 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_FLAGS) | 73 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAGS) |
74 #undef ISOLATE_TIMELINE_STREAM_FLAGS | 74 #undef TIMELINE_STREAM_FLAGS |
75 static void SetVMStreamEnabled(bool enabled); | |
76 | 75 |
77 static void set_start_recording_cb( | 76 static void set_start_recording_cb( |
78 Dart_EmbedderTimelineStartRecording start_recording_cb) { | 77 Dart_EmbedderTimelineStartRecording start_recording_cb) { |
79 start_recording_cb_ = start_recording_cb; | 78 start_recording_cb_ = start_recording_cb; |
80 } | 79 } |
81 | 80 |
82 static Dart_EmbedderTimelineStartRecording get_start_recording_cb() { | 81 static Dart_EmbedderTimelineStartRecording get_start_recording_cb() { |
83 return start_recording_cb_; | 82 return start_recording_cb_; |
84 } | 83 } |
85 | 84 |
86 static void set_stop_recording_cb( | 85 static void set_stop_recording_cb( |
87 Dart_EmbedderTimelineStopRecording stop_recording_cb) { | 86 Dart_EmbedderTimelineStopRecording stop_recording_cb) { |
88 stop_recording_cb_ = stop_recording_cb; | 87 stop_recording_cb_ = stop_recording_cb; |
89 } | 88 } |
90 | 89 |
91 static Dart_EmbedderTimelineStopRecording get_stop_recording_cb() { | 90 static Dart_EmbedderTimelineStopRecording get_stop_recording_cb() { |
92 return stop_recording_cb_; | 91 return stop_recording_cb_; |
93 } | 92 } |
94 | 93 |
95 static void set_get_timeline_cb( | |
96 Dart_EmbedderTimelineGetTimeline get_timeline_cb) { | |
97 get_timeline_cb_ = get_timeline_cb; | |
98 } | |
99 | |
100 static Dart_EmbedderTimelineGetTimeline get_get_timeline_cb() { | |
101 return get_timeline_cb_; | |
102 } | |
103 | |
104 private: | 94 private: |
105 static void StreamStateChange(const char* stream_name, bool prev, bool curr); | 95 static void StreamStateChange(const char* stream_name, bool prev, bool curr); |
106 static TimelineEventRecorder* recorder_; | 96 static TimelineEventRecorder* recorder_; |
107 static TimelineStream vm_stream_; | |
108 static TimelineStream vm_api_stream_; | |
109 static MallocGrowableArray<char*>* enabled_streams_; | 97 static MallocGrowableArray<char*>* enabled_streams_; |
110 static Dart_EmbedderTimelineStartRecording start_recording_cb_; | 98 static Dart_EmbedderTimelineStartRecording start_recording_cb_; |
111 static Dart_EmbedderTimelineStopRecording stop_recording_cb_; | 99 static Dart_EmbedderTimelineStopRecording stop_recording_cb_; |
112 static Dart_EmbedderTimelineGetTimeline get_timeline_cb_; | |
113 | 100 |
114 #define ISOLATE_TIMELINE_STREAM_DECLARE_FLAG(name, not_used) \ | 101 #define TIMELINE_STREAM_DECLARE(name, not_used) \ |
115 static bool stream_##name##_enabled_; | 102 static bool stream_##name##_enabled_; \ |
116 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_DECLARE_FLAG) | 103 static TimelineStream stream_##name##_; |
117 #undef ISOLATE_TIMELINE_STREAM_DECLARE_FLAG | 104 TIMELINE_STREAM_LIST(TIMELINE_STREAM_DECLARE) |
| 105 #undef TIMELINE_STREAM_DECLARE |
118 | 106 |
119 friend class TimelineRecorderOverride; | 107 friend class TimelineRecorderOverride; |
120 friend class ReclaimBlocksIsolateVisitor; | 108 friend class ReclaimBlocksIsolateVisitor; |
121 }; | 109 }; |
122 | 110 |
123 | 111 |
124 struct TimelineEventArgument { | 112 struct TimelineEventArgument { |
125 const char* name; | 113 const char* name; |
126 char* value; | 114 char* value; |
127 }; | 115 }; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 ASSERT(IsFinishedDuration()); | 203 ASSERT(IsFinishedDuration()); |
216 return timestamp1_; | 204 return timestamp1_; |
217 } | 205 } |
218 | 206 |
219 void PrintJSON(JSONStream* stream) const; | 207 void PrintJSON(JSONStream* stream) const; |
220 | 208 |
221 ThreadId thread() const { | 209 ThreadId thread() const { |
222 return thread_; | 210 return thread_; |
223 } | 211 } |
224 | 212 |
| 213 void set_thread(ThreadId tid) { |
| 214 thread_ = tid; |
| 215 } |
| 216 |
225 Dart_Port isolate_id() const { | 217 Dart_Port isolate_id() const { |
226 return isolate_id_; | 218 return isolate_id_; |
227 } | 219 } |
228 | 220 |
229 const char* label() const { | 221 const char* label() const { |
230 return label_; | 222 return label_; |
231 } | 223 } |
232 | 224 |
233 // Does this duration end before |micros| ? | 225 // Does this duration end before |micros| ? |
234 bool DurationFinishedBefore(int64_t micros) const { | 226 bool DurationFinishedBefore(int64_t micros) const { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 371 |
380 private: | 372 private: |
381 const char* name_; | 373 const char* name_; |
382 bool enabled_; | 374 bool enabled_; |
383 const bool* globally_enabled_; | 375 const bool* globally_enabled_; |
384 }; | 376 }; |
385 | 377 |
386 #ifndef PRODUCT | 378 #ifndef PRODUCT |
387 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, suffix, function) \ | 379 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, suffix, function) \ |
388 TimelineDurationScope tds(thread, \ | 380 TimelineDurationScope tds(thread, \ |
389 thread->isolate()->GetCompilerStream(), \ | 381 Timeline::GetCompilerStream(), \ |
390 "Compile" suffix); \ | 382 "Compile" suffix); \ |
391 if (tds.enabled()) { \ | 383 if (tds.enabled()) { \ |
392 tds.SetNumArguments(1); \ | 384 tds.SetNumArguments(1); \ |
393 tds.CopyArgument( \ | 385 tds.CopyArgument( \ |
394 0, \ | 386 0, \ |
395 "function", \ | 387 "function", \ |
396 function.ToLibNamePrefixedQualifiedCString()); \ | 388 function.ToLibNamePrefixedQualifiedCString()); \ |
397 } | 389 } |
398 #else | 390 #else |
399 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, suffix, function) | 391 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, suffix, function) |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 virtual TimelineEvent* StartEvent() = 0; | 663 virtual TimelineEvent* StartEvent() = 0; |
672 virtual void CompleteEvent(TimelineEvent* event) = 0; | 664 virtual void CompleteEvent(TimelineEvent* event) = 0; |
673 virtual TimelineEventBlock* GetHeadBlockLocked() = 0; | 665 virtual TimelineEventBlock* GetHeadBlockLocked() = 0; |
674 virtual TimelineEventBlock* GetNewBlockLocked() = 0; | 666 virtual TimelineEventBlock* GetNewBlockLocked() = 0; |
675 virtual void Clear() = 0; | 667 virtual void Clear() = 0; |
676 | 668 |
677 // Utility method(s). | 669 // Utility method(s). |
678 void PrintJSONMeta(JSONArray* array) const; | 670 void PrintJSONMeta(JSONArray* array) const; |
679 TimelineEvent* ThreadBlockStartEvent(); | 671 TimelineEvent* ThreadBlockStartEvent(); |
680 void ThreadBlockCompleteEvent(TimelineEvent* event); | 672 void ThreadBlockCompleteEvent(TimelineEvent* event); |
681 void PrintEmbedderJSONEvents(JSONStream* events); | |
682 | 673 |
683 Mutex lock_; | 674 Mutex lock_; |
684 uintptr_t async_id_; | 675 uintptr_t async_id_; |
685 | 676 |
686 friend class TimelineEvent; | 677 friend class TimelineEvent; |
687 friend class TimelineEventBlockIterator; | 678 friend class TimelineEventBlockIterator; |
688 friend class TimelineStream; | 679 friend class TimelineStream; |
689 friend class TimelineTestHelper; | 680 friend class TimelineTestHelper; |
690 friend class Timeline; | 681 friend class Timeline; |
691 | 682 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 | 794 |
804 private: | 795 private: |
805 TimelineEventBlock* current_; | 796 TimelineEventBlock* current_; |
806 TimelineEventRecorder* recorder_; | 797 TimelineEventRecorder* recorder_; |
807 }; | 798 }; |
808 | 799 |
809 | 800 |
810 } // namespace dart | 801 } // namespace dart |
811 | 802 |
812 #endif // VM_TIMELINE_H_ | 803 #endif // VM_TIMELINE_H_ |
OLD | NEW |