Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: runtime/vm/timer.h

Issue 196413011: - Implement a PauseTimerScope so that we can properly exclude (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/timer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/timer.h
===================================================================
--- runtime/vm/timer.h (revision 33660)
+++ 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.
// ....
@@ -146,16 +138,60 @@
}
private:
- bool flag_;
+ const bool flag_;
bool nested_;
- Timer* timer_;
+ Timer* const timer_;
+
+ DISALLOW_ALLOCATION();
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) {
+ if (flag_) {
+ if (timer_->running()) {
+ timer_->Stop();
+ } else {
+ nested_ = true;
+ }
+ }
+ }
+ ~PauseTimerScope() {
+ if (flag_) {
+ if (!nested_) {
+ timer_->Start();
+ }
+ }
+ }
+
+ private:
+ const bool flag_;
+ bool nested_;
+ Timer* const timer_;
+
+ DISALLOW_ALLOCATION();
+ 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_
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698