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

Side by Side Diff: base/metrics/stats_counters.h

Issue 6736019: Base: A few more files using BASE_API (for base.dll) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | « base/metrics/histogram.h ('k') | base/metrics/stats_table.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/base_api.h"
11 #include "base/metrics/stats_table.h" 12 #include "base/metrics/stats_table.h"
12 #include "base/time.h" 13 #include "base/time.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 // StatsCounters are dynamically created values which can be tracked in 17 // StatsCounters are dynamically created values which can be tracked in
17 // the StatsTable. They are designed to be lightweight to create and 18 // the StatsTable. They are designed to be lightweight to create and
18 // easy to use. 19 // easy to use.
19 // 20 //
20 // Since StatsCounters can be created dynamically by name, there is 21 // Since StatsCounters can be created dynamically by name, there is
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #else // NDEBUG 68 #else // NDEBUG
68 69
69 #define DSTATS_COUNTER(name, delta) do {} while (0) 70 #define DSTATS_COUNTER(name, delta) do {} while (0)
70 #define DSIMPLE_STATS_COUNTER(name) do {} while (0) 71 #define DSIMPLE_STATS_COUNTER(name) do {} while (0)
71 #define DRATE_COUNTER(name, duration) do {} while (0) 72 #define DRATE_COUNTER(name, duration) do {} while (0)
72 73
73 #endif // NDEBUG 74 #endif // NDEBUG
74 75
75 //------------------------------------------------------------------------------ 76 //------------------------------------------------------------------------------
76 // StatsCounter represents a counter in the StatsTable class. 77 // StatsCounter represents a counter in the StatsTable class.
77 class StatsCounter { 78 class BASE_API StatsCounter {
78 public: 79 public:
79 // Create a StatsCounter object. 80 // Create a StatsCounter object.
80 explicit StatsCounter(const std::string& name); 81 explicit StatsCounter(const std::string& name);
81 virtual ~StatsCounter(); 82 virtual ~StatsCounter();
82 83
83 // Sets the counter to a specific value. 84 // Sets the counter to a specific value.
84 void Set(int value); 85 void Set(int value);
85 86
86 // Increments the counter. 87 // Increments the counter.
87 void Increment() { 88 void Increment() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // The counter id in the table. We initialize to -1 (an invalid value) 122 // The counter id in the table. We initialize to -1 (an invalid value)
122 // and then cache it once it has been looked up. The counter_id is 123 // and then cache it once it has been looked up. The counter_id is
123 // valid across all threads and processes. 124 // valid across all threads and processes.
124 int32 counter_id_; 125 int32 counter_id_;
125 }; 126 };
126 127
127 128
128 // A StatsCounterTimer is a StatsCounter which keeps a timer during 129 // A StatsCounterTimer is a StatsCounter which keeps a timer during
129 // the scope of the StatsCounterTimer. On destruction, it will record 130 // the scope of the StatsCounterTimer. On destruction, it will record
130 // its time measurement. 131 // its time measurement.
131 class StatsCounterTimer : protected StatsCounter { 132 class BASE_API StatsCounterTimer : protected StatsCounter {
132 public: 133 public:
133 // Constructs and starts the timer. 134 // Constructs and starts the timer.
134 explicit StatsCounterTimer(const std::string& name); 135 explicit StatsCounterTimer(const std::string& name);
135 virtual ~StatsCounterTimer(); 136 virtual ~StatsCounterTimer();
136 137
137 // Start the timer. 138 // Start the timer.
138 void Start(); 139 void Start();
139 140
140 // Stop the timer and record the results. 141 // Stop the timer and record the results.
141 void Stop(); 142 void Stop();
142 143
143 // Returns true if the timer is running. 144 // Returns true if the timer is running.
144 bool Running(); 145 bool Running();
145 146
146 // Accept a TimeDelta to increment. 147 // Accept a TimeDelta to increment.
147 virtual void AddTime(TimeDelta time); 148 virtual void AddTime(TimeDelta time);
148 149
149 protected: 150 protected:
150 // Compute the delta between start and stop, in milliseconds. 151 // Compute the delta between start and stop, in milliseconds.
151 void Record(); 152 void Record();
152 153
153 TimeTicks start_time_; 154 TimeTicks start_time_;
154 TimeTicks stop_time_; 155 TimeTicks stop_time_;
155 }; 156 };
156 157
157 // 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
158 // that several statistics can be produced: 159 // that several statistics can be produced:
159 // min, max, avg, count, total 160 // min, max, avg, count, total
160 class StatsRate : public StatsCounterTimer { 161 class BASE_API StatsRate : public StatsCounterTimer {
161 public: 162 public:
162 // Constructs and starts the timer. 163 // Constructs and starts the timer.
163 explicit StatsRate(const std::string& name); 164 explicit StatsRate(const std::string& name);
164 virtual ~StatsRate(); 165 virtual ~StatsRate();
165 166
166 virtual void Add(int value); 167 virtual void Add(int value);
167 168
168 private: 169 private:
169 StatsCounter counter_; 170 StatsCounter counter_;
170 StatsCounter largest_add_; 171 StatsCounter largest_add_;
(...skipping 16 matching lines...) Expand all
187 timer_.Stop(); 188 timer_.Stop();
188 } 189 }
189 190
190 private: 191 private:
191 T& timer_; 192 T& timer_;
192 }; 193 };
193 194
194 } // namespace base 195 } // namespace base
195 196
196 #endif // BASE_METRICS_STATS_COUNTERS_H_ 197 #endif // BASE_METRICS_STATS_COUNTERS_H_
OLDNEW
« no previous file with comments | « base/metrics/histogram.h ('k') | base/metrics/stats_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698