| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 void PrintTimersToJSONProperty(JSONObject* jsobj); | 102 void PrintTimersToJSONProperty(JSONObject* jsobj); |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 #define TIMER_FIELD(name, msg) Timer name##_; | 105 #define TIMER_FIELD(name, msg) Timer name##_; |
| 106 TIMER_LIST(TIMER_FIELD) | 106 TIMER_LIST(TIMER_FIELD) |
| 107 #undef TIMER_FIELD | 107 #undef TIMER_FIELD |
| 108 bool padding_; | 108 bool padding_; |
| 109 DISALLOW_COPY_AND_ASSIGN(TimerList); | 109 DISALLOW_COPY_AND_ASSIGN(TimerList); |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // Timer Usage. | |
| 113 #define START_TIMER(name) \ | |
| 114 Isolate::Current()->timer_list().name().Start(); | |
| 115 | |
| 116 #define STOP_TIMER(name) \ | |
| 117 Isolate::Current()->timer_list().name().Stop(); | |
| 118 | |
| 119 // The class TimerScope is used to start and stop a timer within a scope. | 112 // The class TimerScope is used to start and stop a timer within a scope. |
| 120 // It is used as follows: | 113 // It is used as follows: |
| 121 // { | 114 // { |
| 122 // TIMERSCOPE(name_of_timer); | 115 // TimerScope timer(FLAG_name_of_flag, timer, isolate); |
| 123 // .... | |
| 124 // ..... | 116 // ..... |
| 125 // code that needs to be timed. | 117 // code that needs to be timed. |
| 126 // .... | 118 // .... |
| 127 // } | 119 // } |
| 128 class TimerScope : public StackResource { | 120 class TimerScope : public StackResource { |
| 129 public: | 121 public: |
| 130 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) | 122 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) |
| 131 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { | 123 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { |
| 132 if (flag_) { | 124 if (flag_) { |
| 133 if (!timer_->running()) { | 125 if (!timer_->running()) { |
| 134 timer_->Start(); | 126 timer_->Start(); |
| 135 } else { | 127 } else { |
| 136 nested_ = true; | 128 nested_ = true; |
| 137 } | 129 } |
| 138 } | 130 } |
| 139 } | 131 } |
| 140 ~TimerScope() { | 132 ~TimerScope() { |
| 141 if (flag_) { | 133 if (flag_) { |
| 142 if (!nested_) { | 134 if (!nested_) { |
| 143 timer_->Stop(); | 135 timer_->Stop(); |
| 144 } | 136 } |
| 145 } | 137 } |
| 146 } | 138 } |
| 147 | 139 |
| 148 private: | 140 private: |
| 149 bool flag_; | 141 const bool flag_; |
| 150 bool nested_; | 142 bool nested_; |
| 151 Timer* timer_; | 143 Timer* const timer_; |
| 144 |
| 145 DISALLOW_ALLOCATION(); |
| 152 DISALLOW_COPY_AND_ASSIGN(TimerScope); | 146 DISALLOW_COPY_AND_ASSIGN(TimerScope); |
| 153 }; | 147 }; |
| 154 | 148 |
| 155 #define TIMERSCOPE(name) \ | 149 |
| 156 TimerScope vm_internal_timer_(true, \ | 150 class PauseTimerScope : public StackResource { |
| 157 &(Isolate::Current()->timer_list().name())) | 151 public: |
| 152 PauseTimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) |
| 153 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { |
| 154 if (flag_) { |
| 155 if (timer_->running()) { |
| 156 timer_->Stop(); |
| 157 } else { |
| 158 nested_ = true; |
| 159 } |
| 160 } |
| 161 } |
| 162 ~PauseTimerScope() { |
| 163 if (flag_) { |
| 164 if (!nested_) { |
| 165 timer_->Start(); |
| 166 } |
| 167 } |
| 168 } |
| 169 |
| 170 private: |
| 171 const bool flag_; |
| 172 bool nested_; |
| 173 Timer* const timer_; |
| 174 |
| 175 DISALLOW_ALLOCATION(); |
| 176 DISALLOW_COPY_AND_ASSIGN(PauseTimerScope); |
| 177 }; |
| 178 |
| 179 |
| 180 // Macros to deal with named timers in the isolate. |
| 181 #define START_TIMER(isolate, name) \ |
| 182 isolate->timer_list().name().Start(); |
| 183 |
| 184 #define STOP_TIMER(isolate, name) \ |
| 185 isolate->timer_list().name().Stop(); |
| 186 |
| 187 #define TIMERSCOPE(isolate, name) \ |
| 188 TimerScope vm_internal_timer_(true, &(isolate->timer_list().name()), isolate) |
| 189 |
| 190 #define PAUSETIMERSCOPE(isolate, name) \ |
| 191 PauseTimerScope vm_internal_timer_(true, \ |
| 192 &(isolate->timer_list().name()), \ |
| 193 isolate) |
| 158 | 194 |
| 159 } // namespace dart | 195 } // namespace dart |
| 160 | 196 |
| 161 #endif // VM_TIMER_H_ | 197 #endif // VM_TIMER_H_ |
| OLD | NEW |