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 20 matching lines...) Expand all Loading... | |
31 void Stop() { | 31 void Stop() { |
32 if (enabled_) { | 32 if (enabled_) { |
33 ASSERT(start_ != 0); | 33 ASSERT(start_ != 0); |
34 ASSERT(running()); | 34 ASSERT(running()); |
35 stop_ = OS::GetCurrentTimeMicros(); | 35 stop_ = OS::GetCurrentTimeMicros(); |
36 total_ += ElapsedMicros(); | 36 total_ += ElapsedMicros(); |
37 running_ = false; | 37 running_ = false; |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 // Get total cummulative elapsed time in micros and reset the counters. | 41 // Get total cummulative elapsed time in micros and reset the counters. |
hausner
2012/05/08 21:41:01
Please adjust the comment. I think this was origin
srdjan
2012/05/08 21:51:31
Done.
| |
42 int64_t TotalElapsedTime() { | 42 int64_t TotalElapsedTime() const { |
43 if (enabled_) { | 43 if (enabled_) { |
44 int64_t result = total_; | 44 int64_t result = total_; |
45 Reset(); | |
46 return result; | 45 return result; |
47 } | 46 } |
48 return 0; | 47 return 0; |
49 } | 48 } |
50 | 49 |
51 // Accessors. | 50 // Accessors. |
52 bool enabled() const { return enabled_; } | 51 bool enabled() const { return enabled_; } |
53 bool running() const { return running_; } | 52 bool running() const { return running_; } |
54 const char* message() const { return message_; } | 53 const char* message() const { return message_; } |
55 | 54 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 | 132 |
134 // The class TimerScope is used to start and stop a timer within a scope. | 133 // The class TimerScope is used to start and stop a timer within a scope. |
135 // It is used as follows: | 134 // It is used as follows: |
136 // { | 135 // { |
137 // TIMERSCOPE(name_of_timer); | 136 // TIMERSCOPE(name_of_timer); |
138 // .... | 137 // .... |
139 // ..... | 138 // ..... |
140 // code that needs to be timed. | 139 // code that needs to be timed. |
141 // .... | 140 // .... |
142 // } | 141 // } |
143 class TimerScope : public ValueObject { | 142 class TimerScope : public StackResource { |
144 public: | 143 public: |
145 TimerScope(bool flag, Timer* timer) | 144 TimerScope(bool flag, Timer* timer, BaseIsolate* isolate = NULL) |
146 : flag_(flag), nested_(false), timer_(timer) { | 145 : StackResource(isolate), flag_(flag), nested_(false), timer_(timer) { |
147 if (flag_) { | 146 if (flag_) { |
148 if (!timer_->running()) { | 147 if (!timer_->running()) { |
149 timer_->Start(); | 148 timer_->Start(); |
150 } else { | 149 } else { |
151 nested_ = true; | 150 nested_ = true; |
152 } | 151 } |
153 } | 152 } |
154 } | 153 } |
155 ~TimerScope() { | 154 ~TimerScope() { |
156 if (flag_) { | 155 if (flag_) { |
(...skipping 10 matching lines...) Expand all Loading... | |
167 DISALLOW_COPY_AND_ASSIGN(TimerScope); | 166 DISALLOW_COPY_AND_ASSIGN(TimerScope); |
168 }; | 167 }; |
169 | 168 |
170 #define TIMERSCOPE(name) \ | 169 #define TIMERSCOPE(name) \ |
171 TimerScope vm_internal_timer_((FLAG_##name || FLAG_time_all), \ | 170 TimerScope vm_internal_timer_((FLAG_##name || FLAG_time_all), \ |
172 &(Isolate::Current()->timer_list().name())) | 171 &(Isolate::Current()->timer_list().name())) |
173 | 172 |
174 } // namespace dart | 173 } // namespace dart |
175 | 174 |
176 #endif // VM_TIMER_H_ | 175 #endif // VM_TIMER_H_ |
OLD | NEW |