Chromium Code Reviews| 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()) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 145 } | 137 } |
| 146 } | 138 } |
| 147 | 139 |
| 148 private: | 140 private: |
| 149 bool flag_; | 141 bool flag_; |
| 150 bool nested_; | 142 bool nested_; |
| 151 Timer* timer_; | 143 Timer* timer_; |
| 152 DISALLOW_COPY_AND_ASSIGN(TimerScope); | 144 DISALLOW_COPY_AND_ASSIGN(TimerScope); |
| 153 }; | 145 }; |
| 154 | 146 |
| 155 #define TIMERSCOPE(name) \ | 147 |
| 156 TimerScope vm_internal_timer_(true, \ | 148 class PauseTimerScope : public StackResource { |
| 157 &(Isolate::Current()->timer_list().name())) | 149 public: |
| 150 PauseTimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) | |
| 151 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { | |
|
srdjan
2014/03/13 20:03:09
indent
Ivan Posva
2014/03/13 20:36:18
Done.
| |
| 152 if (flag_) { | |
| 153 if (timer_->running()) { | |
| 154 timer_->Stop(); | |
| 155 } else { | |
| 156 nested_ = true; | |
| 157 } | |
| 158 } | |
| 159 } | |
| 160 ~PauseTimerScope() { | |
| 161 if (flag_) { | |
| 162 if (!nested_) { | |
| 163 timer_->Start(); | |
| 164 } | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 private: | |
| 169 bool flag_; | |
|
srdjan
2014/03/13 20:03:09
const
Ivan Posva
2014/03/13 20:36:18
Done.
| |
| 170 bool nested_; | |
| 171 Timer* timer_; | |
| 172 DISALLOW_COPY_AND_ASSIGN(PauseTimerScope); | |
| 173 }; | |
| 174 | |
| 175 | |
| 176 // Macros to deal with named timers in the isolate. | |
| 177 #define START_TIMER(isolate, name) \ | |
| 178 isolate->timer_list().name().Start(); | |
| 179 | |
| 180 #define STOP_TIMER(isolate, name) \ | |
| 181 isolate->timer_list().name().Stop(); | |
| 182 | |
| 183 #define TIMERSCOPE(isolate, name) \ | |
| 184 TimerScope vm_internal_timer_(true, &(isolate->timer_list().name()), isolate) | |
| 185 | |
| 186 #define PAUSETIMERSCOPE(isolate, name) \ | |
| 187 PauseTimerScope vm_internal_timer_(true, \ | |
| 188 &(isolate->timer_list().name()), \ | |
| 189 isolate) | |
| 158 | 190 |
| 159 } // namespace dart | 191 } // namespace dart |
| 160 | 192 |
| 161 #endif // VM_TIMER_H_ | 193 #endif // VM_TIMER_H_ |
| OLD | NEW |