| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef BASE_METRICS_STATS_COUNTERS_H_ | 5 #ifndef BASE_METRICS_STATS_COUNTERS_H_ |
| 6 #define BASE_METRICS_STATS_COUNTERS_H_ | 6 #define BASE_METRICS_STATS_COUNTERS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 | 128 |
| 129 // A StatsCounterTimer is a StatsCounter which keeps a timer during | 129 // A StatsCounterTimer is a StatsCounter which keeps a timer during |
| 130 // the scope of the StatsCounterTimer. On destruction, it will record | 130 // the scope of the StatsCounterTimer. On destruction, it will record |
| 131 // its time measurement. | 131 // its time measurement. |
| 132 class BASE_EXPORT StatsCounterTimer : protected StatsCounter { | 132 class BASE_EXPORT StatsCounterTimer : protected StatsCounter { |
| 133 public: | 133 public: |
| 134 // Constructs and starts the timer. | 134 // Constructs and starts the timer. |
| 135 explicit StatsCounterTimer(const std::string& name); | 135 explicit StatsCounterTimer(const std::string& name); |
| 136 virtual ~StatsCounterTimer(); | 136 ~StatsCounterTimer() override; |
| 137 | 137 |
| 138 // Start the timer. | 138 // Start the timer. |
| 139 void Start(); | 139 void Start(); |
| 140 | 140 |
| 141 // Stop the timer and record the results. | 141 // Stop the timer and record the results. |
| 142 void Stop(); | 142 void Stop(); |
| 143 | 143 |
| 144 // Returns true if the timer is running. | 144 // Returns true if the timer is running. |
| 145 bool Running(); | 145 bool Running(); |
| 146 | 146 |
| 147 // Accept a TimeDelta to increment. | 147 // Accept a TimeDelta to increment. |
| 148 virtual void AddTime(TimeDelta time); | 148 virtual void AddTime(TimeDelta time); |
| 149 | 149 |
| 150 protected: | 150 protected: |
| 151 // Compute the delta between start and stop, in milliseconds. | 151 // Compute the delta between start and stop, in milliseconds. |
| 152 void Record(); | 152 void Record(); |
| 153 | 153 |
| 154 TimeTicks start_time_; | 154 TimeTicks start_time_; |
| 155 TimeTicks stop_time_; | 155 TimeTicks stop_time_; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 // A StatsRate is a timer that keeps a count of the number of intervals added so | 158 // A StatsRate is a timer that keeps a count of the number of intervals added so |
| 159 // that several statistics can be produced: | 159 // that several statistics can be produced: |
| 160 // min, max, avg, count, total | 160 // min, max, avg, count, total |
| 161 class BASE_EXPORT StatsRate : public StatsCounterTimer { | 161 class BASE_EXPORT StatsRate : public StatsCounterTimer { |
| 162 public: | 162 public: |
| 163 // Constructs and starts the timer. | 163 // Constructs and starts the timer. |
| 164 explicit StatsRate(const std::string& name); | 164 explicit StatsRate(const std::string& name); |
| 165 virtual ~StatsRate(); | 165 ~StatsRate() override; |
| 166 | 166 |
| 167 virtual void Add(int value) override; | 167 void Add(int value) override; |
| 168 | 168 |
| 169 private: | 169 private: |
| 170 StatsCounter counter_; | 170 StatsCounter counter_; |
| 171 StatsCounter largest_add_; | 171 StatsCounter largest_add_; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 | 174 |
| 175 // Helper class for scoping a timer or rate. | 175 // Helper class for scoping a timer or rate. |
| 176 template<class T> class StatsScope { | 176 template<class T> class StatsScope { |
| 177 public: | 177 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 timer_.Stop(); | 188 timer_.Stop(); |
| 189 } | 189 } |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 T& timer_; | 192 T& timer_; |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 } // namespace base | 195 } // namespace base |
| 196 | 196 |
| 197 #endif // BASE_METRICS_STATS_COUNTERS_H_ | 197 #endif // BASE_METRICS_STATS_COUNTERS_H_ |
| OLD | NEW |