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

Side by Side Diff: runtime/vm/timer_scope.h

Issue 177733002: Revert r32930 (Add more timing information in the VM to track time...) (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/timer.cc ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 #ifndef VM_TIMER_SCOPE_H_
6 #define VM_TIMER_SCOPE_H_
7
8 #include "vm/allocation.h"
9 #include "vm/flags.h"
10 #include "vm/os.h"
11 #include "vm/timer.h"
12
13 namespace dart {
14
15 // Transition from executing VM code to executing Native code.
16 class VmToNativeTimerScope : public ValueObject {
17 public:
18 explicit VmToNativeTimerScope(Isolate* isolate) {
19 native_timer_ = &(isolate->timer_list().time_native_execution());
20 native_timer_->Start();
21 }
22 ~VmToNativeTimerScope() {
23 native_timer_->Stop();
24 }
25
26 private:
27 Timer* native_timer_;
28 DISALLOW_COPY_AND_ASSIGN(VmToNativeTimerScope);
29 };
30
31 // Transition from executing Native code to executing VM code.
32 class NativeToVmTimerScope : public ValueObject {
33 public:
34 explicit NativeToVmTimerScope(Isolate* isolate)
35 : dart_running_(false),
36 timer_list_(&(isolate->timer_list())) {
37 Timer* dart_timer = &(timer_list_->time_dart_execution());
38 // Currently when a native function is setup without the auto scope
39 // setup parameter (leaf function) we would have the dart timer still
40 // running as we have not done any transitioning. If for some reason
41 // such a native function makes API call backs we should account for
42 // that.
43 if (dart_timer->running()) {
44 dart_running_ = true;
45 dart_timer->Stop();
46 } else {
47 Timer* native_timer = &(timer_list_->time_native_execution());
48 native_timer->Stop();
49 }
50 }
51 ~NativeToVmTimerScope() {
52 if (dart_running_) {
53 Timer* dart_timer = &(timer_list_->time_dart_execution());
54 dart_timer->Start();
55 } else {
56 Timer* native_timer = &(timer_list_->time_native_execution());
57 native_timer->Start();
58 }
59 }
60
61 private:
62 bool dart_running_;
63 TimerList* timer_list_;
64 DISALLOW_COPY_AND_ASSIGN(NativeToVmTimerScope);
65 };
66
67 // Transition from executing Dart code to executing Native code.
68 class DartToNativeTimerScope : public ValueObject {
69 public:
70 explicit DartToNativeTimerScope(Isolate* isolate) {
71 dart_timer_ = &(isolate->timer_list().time_dart_execution());
72 native_timer_ = &(isolate->timer_list().time_native_execution());
73 dart_timer_->Stop();
74 native_timer_->Start();
75 }
76 ~DartToNativeTimerScope() {
77 native_timer_->Stop();
78 dart_timer_->Start();
79 }
80
81 private:
82 Timer* native_timer_;
83 Timer* dart_timer_;
84 DISALLOW_COPY_AND_ASSIGN(DartToNativeTimerScope);
85 };
86
87 // Transition from executing Dart code to executing VM code.
88 class DartToVmTimerScope : public ValueObject {
89 public:
90 explicit DartToVmTimerScope(Isolate* isolate) {
91 dart_timer_ = &(isolate->timer_list().time_dart_execution());
92 dart_timer_->Stop();
93 }
94 ~DartToVmTimerScope() {
95 dart_timer_->Start();
96 }
97
98 private:
99 Timer* dart_timer_;
100 DISALLOW_COPY_AND_ASSIGN(DartToVmTimerScope);
101 };
102
103 // The class TimerScope is used to start and stop a timer within a scope.
104 // It is used as follows:
105 // {
106 // TIMERSCOPE(name_of_timer);
107 // ....
108 // .....
109 // code that needs to be timed.
110 // ....
111 // }
112 class TimerScope : public StackResource {
113 public:
114 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate)
115 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) {
116 if (flag_) {
117 if (!timer_->running()) {
118 timer_->Start();
119 } else {
120 nested_ = true;
121 }
122 }
123 }
124 ~TimerScope() {
125 if (flag_) {
126 if (!nested_) {
127 timer_->Stop();
128 }
129 }
130 }
131
132 private:
133 bool flag_;
134 bool nested_;
135 Timer* timer_;
136 DISALLOW_COPY_AND_ASSIGN(TimerScope);
137 };
138
139 #define TIMERSCOPE(isolate, name) \
140 TimerScope vm_internal_timer_(true, &(isolate->timer_list().name()), isolate)
141
142 } // namespace dart
143
144 #endif // VM_TIMER_SCOPE_H_
OLDNEW
« no previous file with comments | « runtime/vm/timer.cc ('k') | runtime/vm/unit_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698