Index: runtime/vm/timer.h |
=================================================================== |
--- runtime/vm/timer.h (revision 33652) |
+++ runtime/vm/timer.h (working copy) |
@@ -109,18 +109,10 @@ |
DISALLOW_COPY_AND_ASSIGN(TimerList); |
}; |
-// Timer Usage. |
-#define START_TIMER(name) \ |
- Isolate::Current()->timer_list().name().Start(); |
- |
-#define STOP_TIMER(name) \ |
- Isolate::Current()->timer_list().name().Stop(); |
- |
// The class TimerScope is used to start and stop a timer within a scope. |
// It is used as follows: |
// { |
-// TIMERSCOPE(name_of_timer); |
-// .... |
+// TimerScope timer(FLAG_name_of_flag, timer, isolate); |
// ..... |
// code that needs to be timed. |
// .... |
@@ -152,10 +144,50 @@ |
DISALLOW_COPY_AND_ASSIGN(TimerScope); |
}; |
-#define TIMERSCOPE(name) \ |
- TimerScope vm_internal_timer_(true, \ |
- &(Isolate::Current()->timer_list().name())) |
+class PauseTimerScope : public StackResource { |
+ public: |
+ PauseTimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) |
+ : 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.
|
+ if (flag_) { |
+ if (timer_->running()) { |
+ timer_->Stop(); |
+ } else { |
+ nested_ = true; |
+ } |
+ } |
+ } |
+ ~PauseTimerScope() { |
+ if (flag_) { |
+ if (!nested_) { |
+ timer_->Start(); |
+ } |
+ } |
+ } |
+ |
+ private: |
+ bool flag_; |
srdjan
2014/03/13 20:03:09
const
Ivan Posva
2014/03/13 20:36:18
Done.
|
+ bool nested_; |
+ Timer* timer_; |
+ DISALLOW_COPY_AND_ASSIGN(PauseTimerScope); |
+}; |
+ |
+ |
+// Macros to deal with named timers in the isolate. |
+#define START_TIMER(isolate, name) \ |
+isolate->timer_list().name().Start(); |
+ |
+#define STOP_TIMER(isolate, name) \ |
+isolate->timer_list().name().Stop(); |
+ |
+#define TIMERSCOPE(isolate, name) \ |
+ TimerScope vm_internal_timer_(true, &(isolate->timer_list().name()), isolate) |
+ |
+#define PAUSETIMERSCOPE(isolate, name) \ |
+PauseTimerScope vm_internal_timer_(true, \ |
+ &(isolate->timer_list().name()), \ |
+ isolate) |
+ |
} // namespace dart |
#endif // VM_TIMER_H_ |