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. |
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 |
| 50 void Reset() { |
| 51 if (enabled_) { |
| 52 start_ = 0; |
| 53 stop_ = 0; |
| 54 total_ = 0; |
| 55 running_ = false; |
| 56 } |
| 57 } |
| 58 |
51 // Accessors. | 59 // Accessors. |
52 bool enabled() const { return enabled_; } | 60 bool enabled() const { return enabled_; } |
53 bool running() const { return running_; } | 61 bool running() const { return running_; } |
54 const char* message() const { return message_; } | 62 const char* message() const { return message_; } |
55 | 63 |
56 private: | 64 private: |
57 int64_t ElapsedMicros() const { | 65 int64_t ElapsedMicros() const { |
58 if (enabled_) { | 66 if (enabled_) { |
59 ASSERT(start_ != 0); | 67 ASSERT(start_ != 0); |
60 ASSERT(stop_ != 0); | 68 ASSERT(stop_ != 0); |
61 return stop_ - start_; | 69 return stop_ - start_; |
62 } | 70 } |
63 return 0; | 71 return 0; |
64 } | 72 } |
65 | 73 |
66 void Reset() { | |
67 if (enabled_) { | |
68 start_ = 0; | |
69 stop_ = 0; | |
70 total_ = 0; | |
71 running_ = false; | |
72 } | |
73 } | |
74 | |
75 int64_t start_; | 74 int64_t start_; |
76 int64_t stop_; | 75 int64_t stop_; |
77 int64_t total_; | 76 int64_t total_; |
78 bool enabled_; | 77 bool enabled_; |
79 bool running_; | 78 bool running_; |
80 const char* message_; | 79 const char* message_; |
81 | 80 |
82 DISALLOW_COPY_AND_ASSIGN(Timer); | 81 DISALLOW_COPY_AND_ASSIGN(Timer); |
83 }; | 82 }; |
84 | 83 |
(...skipping 48 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 |