OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #ifndef BASE_STATS_COUNTERS_H__ | 6 #ifndef BASE_STATS_COUNTERS_H__ |
7 #define BASE_STATS_COUNTERS_H__ | 7 #define BASE_STATS_COUNTERS_H__ |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include "base/stats_table.h" | 10 #include "base/stats_table.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 explicit StatsCounterTimer(const std::wstring& name) { | 180 explicit StatsCounterTimer(const std::wstring& name) { |
181 // we prepend the name with 't:' to indicate that it is a timer. | 181 // we prepend the name with 't:' to indicate that it is a timer. |
182 name_ = L"t:"; | 182 name_ = L"t:"; |
183 name_.append(name); | 183 name_.append(name); |
184 } | 184 } |
185 | 185 |
186 // Start the timer. | 186 // Start the timer. |
187 void Start() { | 187 void Start() { |
188 if (!Enabled()) | 188 if (!Enabled()) |
189 return; | 189 return; |
190 start_time_ = TimeTicks::Now(); | 190 start_time_ = base::TimeTicks::Now(); |
191 stop_time_ = TimeTicks(); | 191 stop_time_ = base::TimeTicks(); |
192 } | 192 } |
193 | 193 |
194 // Stop the timer and record the results. | 194 // Stop the timer and record the results. |
195 void Stop() { | 195 void Stop() { |
196 if (!Enabled() || !Running()) | 196 if (!Enabled() || !Running()) |
197 return; | 197 return; |
198 stop_time_ = TimeTicks::Now(); | 198 stop_time_ = base::TimeTicks::Now(); |
199 Record(); | 199 Record(); |
200 } | 200 } |
201 | 201 |
202 // Returns true if the timer is running. | 202 // Returns true if the timer is running. |
203 bool Running() { | 203 bool Running() { |
204 return Enabled() && !start_time_.is_null() && stop_time_.is_null(); | 204 return Enabled() && !start_time_.is_null() && stop_time_.is_null(); |
205 } | 205 } |
206 | 206 |
207 // Accept a TimeDelta to increment. | 207 // Accept a TimeDelta to increment. |
208 virtual void AddTime(TimeDelta time) { | 208 virtual void AddTime(base::TimeDelta time) { |
209 Add(static_cast<int>(time.InMilliseconds())); | 209 Add(static_cast<int>(time.InMilliseconds())); |
210 } | 210 } |
211 | 211 |
212 // TODO(jar) temporary hack include method till base and chrome use new name. | 212 // TODO(jar) temporary hack include method till base and chrome use new name. |
213 void IncrementTimer(TimeDelta time) { | 213 void IncrementTimer(base::TimeDelta time) { |
214 AddTime(time); | 214 AddTime(time); |
215 } | 215 } |
216 | 216 |
217 protected: | 217 protected: |
218 // Compute the delta between start and stop, in milliseconds. | 218 // Compute the delta between start and stop, in milliseconds. |
219 void Record() { | 219 void Record() { |
220 AddTime(stop_time_ - start_time_); | 220 AddTime(stop_time_ - start_time_); |
221 } | 221 } |
222 | 222 |
223 TimeTicks start_time_; | 223 base::TimeTicks start_time_; |
224 TimeTicks stop_time_; | 224 base::TimeTicks stop_time_; |
225 }; | 225 }; |
226 | 226 |
227 // A StatsRate is a timer that keeps a count of the number of intervals added so | 227 // A StatsRate is a timer that keeps a count of the number of intervals added so |
228 // that several statistics can be produced: | 228 // that several statistics can be produced: |
229 // min, max, avg, count, total | 229 // min, max, avg, count, total |
230 class StatsRate : public StatsCounterTimer { | 230 class StatsRate : public StatsCounterTimer { |
231 public: | 231 public: |
232 // Constructs and starts the timer. | 232 // Constructs and starts the timer. |
233 explicit StatsRate(const wchar_t* name) | 233 explicit StatsRate(const wchar_t* name) |
234 : StatsCounterTimer(name), | 234 : StatsCounterTimer(name), |
(...skipping 29 matching lines...) Expand all Loading... |
264 void Stop() { | 264 void Stop() { |
265 timer_.Stop(); | 265 timer_.Stop(); |
266 } | 266 } |
267 | 267 |
268 private: | 268 private: |
269 T& timer_; | 269 T& timer_; |
270 }; | 270 }; |
271 | 271 |
272 #endif // BASE_STATS_COUNTERS_H__ | 272 #endif // BASE_STATS_COUNTERS_H__ |
273 | 273 |
OLD | NEW |