| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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_TIMER_H_ | 5 #ifndef VM_TIMER_H_ |
| 6 #define VM_TIMER_H_ | 6 #define VM_TIMER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/flags.h" | 9 #include "vm/flags.h" |
| 10 #include "vm/os.h" | 10 #include "vm/os.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // List of per isolate timers. | 78 // List of per isolate timers. |
| 79 #define TIMER_LIST(V) \ | 79 #define TIMER_LIST(V) \ |
| 80 V(time_script_loading, "Script Loading") \ | 80 V(time_script_loading, "Script Loading") \ |
| 81 V(time_creating_snapshot, "Snapshot Creation") \ | 81 V(time_creating_snapshot, "Snapshot Creation") \ |
| 82 V(time_isolate_initialization, "Isolate initialization") \ | 82 V(time_isolate_initialization, "Isolate initialization") \ |
| 83 V(time_compilation, "Function compilation") \ | 83 V(time_compilation, "Function compilation") \ |
| 84 V(time_bootstrap, "Bootstrap of core classes") \ | 84 V(time_bootstrap, "Bootstrap of core classes") \ |
| 85 V(time_dart_execution, "Dart execution") \ | 85 V(time_dart_execution, "Dart execution") \ |
| 86 V(time_native_execution, "Native code execution") \ | |
| 87 V(time_total_runtime, "Total runtime for isolate") \ | 86 V(time_total_runtime, "Total runtime for isolate") \ |
| 88 | 87 |
| 89 // Maintains a list of timers per isolate. | 88 // Maintains a list of timers per isolate. |
| 90 class TimerList : public ValueObject { | 89 class TimerList : public ValueObject { |
| 91 public: | 90 public: |
| 92 TimerList(); | 91 TimerList(); |
| 93 ~TimerList() {} | 92 ~TimerList() {} |
| 94 | 93 |
| 95 // Accessors. | 94 // Accessors. |
| 96 #define TIMER_FIELD_ACCESSOR(name, msg) \ | 95 #define TIMER_FIELD_ACCESSOR(name, msg) \ |
| 97 Timer& name() { return name##_; } | 96 Timer& name() { return name##_; } |
| 98 TIMER_LIST(TIMER_FIELD_ACCESSOR) | 97 TIMER_LIST(TIMER_FIELD_ACCESSOR) |
| 99 #undef TIMER_FIELD_ACCESSOR | 98 #undef TIMER_FIELD_ACCESSOR |
| 100 | 99 |
| 101 void ReportTimers(); | 100 void ReportTimers(); |
| 102 void ReportTimerState(const char* prefix); | |
| 103 | 101 |
| 104 void PrintTimersToJSONProperty(JSONObject* jsobj); | 102 void PrintTimersToJSONProperty(JSONObject* jsobj); |
| 105 | 103 |
| 106 private: | 104 private: |
| 107 #define TIMER_FIELD(name, msg) Timer name##_; | 105 #define TIMER_FIELD(name, msg) Timer name##_; |
| 108 TIMER_LIST(TIMER_FIELD) | 106 TIMER_LIST(TIMER_FIELD) |
| 109 #undef TIMER_FIELD | 107 #undef TIMER_FIELD |
| 110 bool padding_; | 108 bool padding_; |
| 111 DISALLOW_COPY_AND_ASSIGN(TimerList); | 109 DISALLOW_COPY_AND_ASSIGN(TimerList); |
| 112 }; | 110 }; |
| 113 | 111 |
| 114 // Timer Usage. | 112 // Timer Usage. |
| 115 #define START_TIMER(isolate, name) \ | 113 #define START_TIMER(name) \ |
| 116 isolate->timer_list().name().Start(); | 114 Isolate::Current()->timer_list().name().Start(); |
| 117 | 115 |
| 118 #define STOP_TIMER(isolate, name) \ | 116 #define STOP_TIMER(name) \ |
| 119 isolate->timer_list().name().Stop(); | 117 Isolate::Current()->timer_list().name().Stop(); |
| 120 | 118 |
| 121 #define TIMER_STATE(isolate, prefix) \ | 119 // The class TimerScope is used to start and stop a timer within a scope. |
| 122 isolate->timer_list().ReportTimerState(prefix); | 120 // It is used as follows: |
| 121 // { |
| 122 // TIMERSCOPE(name_of_timer); |
| 123 // .... |
| 124 // ..... |
| 125 // code that needs to be timed. |
| 126 // .... |
| 127 // } |
| 128 class TimerScope : public StackResource { |
| 129 public: |
| 130 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) |
| 131 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { |
| 132 if (flag_) { |
| 133 if (!timer_->running()) { |
| 134 timer_->Start(); |
| 135 } else { |
| 136 nested_ = true; |
| 137 } |
| 138 } |
| 139 } |
| 140 ~TimerScope() { |
| 141 if (flag_) { |
| 142 if (!nested_) { |
| 143 timer_->Stop(); |
| 144 } |
| 145 } |
| 146 } |
| 147 |
| 148 private: |
| 149 bool flag_; |
| 150 bool nested_; |
| 151 Timer* timer_; |
| 152 DISALLOW_COPY_AND_ASSIGN(TimerScope); |
| 153 }; |
| 154 |
| 155 #define TIMERSCOPE(name) \ |
| 156 TimerScope vm_internal_timer_(true, \ |
| 157 &(Isolate::Current()->timer_list().name())) |
| 123 | 158 |
| 124 } // namespace dart | 159 } // namespace dart |
| 125 | 160 |
| 126 #endif // VM_TIMER_H_ | 161 #endif // VM_TIMER_H_ |
| OLD | NEW |