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 20 matching lines...) Expand all Loading... |
31 #define 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 V(VM, false) |
40 | 40 |
| 41 // A stream of timeline events. A stream has a name and can be enabled or |
| 42 // disabled (globally and per isolate). |
| 43 class TimelineStream { |
| 44 public: |
| 45 TimelineStream(); |
| 46 |
| 47 void Init(const char* name, |
| 48 bool enabled); |
| 49 |
| 50 const char* name() const { |
| 51 return name_; |
| 52 } |
| 53 |
| 54 bool enabled() const { |
| 55 return enabled_ != 0; |
| 56 } |
| 57 |
| 58 void set_enabled(bool enabled) { |
| 59 enabled_ = enabled ? 1 : 0; |
| 60 } |
| 61 |
| 62 // Records an event. Will return |NULL| if not enabled. The returned |
| 63 // |TimelineEvent| is in an undefined state and must be initialized. |
| 64 // NOTE: It is not allowed to call StartEvent again without completing |
| 65 // the first event. |
| 66 TimelineEvent* StartEvent(); |
| 67 |
| 68 static intptr_t enabled_offset() { |
| 69 return OFFSET_OF(TimelineStream, enabled_); |
| 70 } |
| 71 |
| 72 private: |
| 73 const char* name_; |
| 74 uintptr_t enabled_; |
| 75 }; |
| 76 |
41 class Timeline : public AllStatic { | 77 class Timeline : public AllStatic { |
42 public: | 78 public: |
43 // Initialize timeline system. Not thread safe. | 79 // Initialize timeline system. Not thread safe. |
44 static void InitOnce(); | 80 static void InitOnce(); |
45 | 81 |
46 // Shutdown timeline system. Not thread safe. | 82 // Shutdown timeline system. Not thread safe. |
47 static void Shutdown(); | 83 static void Shutdown(); |
48 | 84 |
49 // Access the global recorder. Not thread safe. | 85 // Access the global recorder. Not thread safe. |
50 static TimelineEventRecorder* recorder(); | 86 static TimelineEventRecorder* recorder(); |
51 | 87 |
52 // Reclaim all |TimelineEventBlocks|s that are cached by threads. | 88 // Reclaim all |TimelineEventBlocks|s that are cached by threads. |
53 static void ReclaimCachedBlocksFromThreads(); | 89 static void ReclaimCachedBlocksFromThreads(); |
54 | 90 |
55 static void Clear(); | 91 static void Clear(); |
56 | 92 |
57 // Print information about streams to JSON. | 93 // Print information about streams to JSON. |
58 static void PrintFlagsToJSON(JSONStream* json); | 94 static void PrintFlagsToJSON(JSONStream* json); |
59 | 95 |
60 #define TIMELINE_STREAM_ACCESSOR(name, not_used) \ | 96 #define TIMELINE_STREAM_ACCESSOR(name, not_used) \ |
61 static TimelineStream* Get##name##Stream() { return &stream_##name##_; } | 97 static TimelineStream* Get##name##Stream() { return &stream_##name##_; } |
62 TIMELINE_STREAM_LIST(TIMELINE_STREAM_ACCESSOR) | 98 TIMELINE_STREAM_LIST(TIMELINE_STREAM_ACCESSOR) |
63 #undef TIMELINE_STREAM_ACCESSOR | 99 #undef TIMELINE_STREAM_ACCESSOR |
64 | 100 |
65 #define TIMELINE_STREAM_FLAGS(name, not_used) \ | 101 #define TIMELINE_STREAM_FLAGS(name, not_used) \ |
66 static const bool* Stream##name##EnabledFlag() { \ | |
67 return &stream_##name##_enabled_; \ | |
68 } \ | |
69 static void SetStream##name##Enabled(bool enabled) { \ | 102 static void SetStream##name##Enabled(bool enabled) { \ |
70 StreamStateChange(#name, stream_##name##_enabled_, enabled); \ | 103 StreamStateChange(#name, stream_##name##_.enabled(), enabled); \ |
71 stream_##name##_enabled_ = enabled; \ | 104 stream_##name##_.set_enabled(enabled); \ |
72 } | 105 } |
73 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAGS) | 106 TIMELINE_STREAM_LIST(TIMELINE_STREAM_FLAGS) |
74 #undef TIMELINE_STREAM_FLAGS | 107 #undef TIMELINE_STREAM_FLAGS |
75 | 108 |
76 static void set_start_recording_cb( | 109 static void set_start_recording_cb( |
77 Dart_EmbedderTimelineStartRecording start_recording_cb) { | 110 Dart_EmbedderTimelineStartRecording start_recording_cb) { |
78 start_recording_cb_ = start_recording_cb; | 111 start_recording_cb_ = start_recording_cb; |
79 } | 112 } |
80 | 113 |
81 static Dart_EmbedderTimelineStartRecording get_start_recording_cb() { | 114 static Dart_EmbedderTimelineStartRecording get_start_recording_cb() { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 friend class TimelineEventRecorder; | 409 friend class TimelineEventRecorder; |
377 friend class TimelineEventEndlessRecorder; | 410 friend class TimelineEventEndlessRecorder; |
378 friend class TimelineEventRingRecorder; | 411 friend class TimelineEventRingRecorder; |
379 friend class TimelineEventStartupRecorder; | 412 friend class TimelineEventStartupRecorder; |
380 friend class TimelineStream; | 413 friend class TimelineStream; |
381 friend class TimelineTestHelper; | 414 friend class TimelineTestHelper; |
382 DISALLOW_COPY_AND_ASSIGN(TimelineEvent); | 415 DISALLOW_COPY_AND_ASSIGN(TimelineEvent); |
383 }; | 416 }; |
384 | 417 |
385 | 418 |
386 // A stream of timeline events. A stream has a name and can be enabled or | |
387 // disabled (globally and per isolate). | |
388 class TimelineStream { | |
389 public: | |
390 TimelineStream(); | |
391 | |
392 void Init(const char* name, | |
393 bool enabled, | |
394 const bool* globally_enabled = NULL); | |
395 | |
396 const char* name() const { | |
397 return name_; | |
398 } | |
399 | |
400 bool Enabled() const { | |
401 return ((globally_enabled_ != NULL) && *globally_enabled_) || | |
402 enabled(); | |
403 } | |
404 | |
405 bool enabled() const { | |
406 return enabled_; | |
407 } | |
408 | |
409 void set_enabled(bool enabled) { | |
410 enabled_ = enabled; | |
411 } | |
412 | |
413 // Records an event. Will return |NULL| if not enabled. The returned | |
414 // |TimelineEvent| is in an undefined state and must be initialized. | |
415 // NOTE: It is not allowed to call StartEvent again without completing | |
416 // the first event. | |
417 TimelineEvent* StartEvent(); | |
418 | |
419 private: | |
420 const char* name_; | |
421 bool enabled_; | |
422 const bool* globally_enabled_; | |
423 }; | |
424 | |
425 #ifndef PRODUCT | 419 #ifndef PRODUCT |
426 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, name, function) \ | 420 #define TIMELINE_FUNCTION_COMPILATION_DURATION(thread, name, function) \ |
427 TimelineDurationScope tds(thread, \ | 421 TimelineDurationScope tds(thread, \ |
428 Timeline::GetCompilerStream(), \ | 422 Timeline::GetCompilerStream(), \ |
429 name); \ | 423 name); \ |
430 if (tds.enabled()) { \ | 424 if (tds.enabled()) { \ |
431 tds.SetNumArguments(1); \ | 425 tds.SetNumArguments(1); \ |
432 tds.CopyArgument( \ | 426 tds.CopyArgument( \ |
433 0, \ | 427 0, \ |
434 "function", \ | 428 "function", \ |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 | 878 |
885 private: | 879 private: |
886 TimelineEventBlock* current_; | 880 TimelineEventBlock* current_; |
887 TimelineEventRecorder* recorder_; | 881 TimelineEventRecorder* recorder_; |
888 }; | 882 }; |
889 | 883 |
890 | 884 |
891 } // namespace dart | 885 } // namespace dart |
892 | 886 |
893 #endif // VM_TIMELINE_H_ | 887 #endif // VM_TIMELINE_H_ |
OLD | NEW |