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

Side by Side Diff: base/stats_counters.h

Issue 11544: Remove use of wide characters in stats table identifiers. (Closed)
Patch Set: Created 12 years, 1 month 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
« no previous file with comments | « base/histogram.cc ('k') | base/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) 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #define DSIMPLE_STATS_COUNTER(name) do {} while (0) 67 #define DSIMPLE_STATS_COUNTER(name) do {} while (0)
68 #define DRATE_COUNTER(name, duration) do {} while (0) 68 #define DRATE_COUNTER(name, duration) do {} while (0)
69 69
70 #endif // NDEBUG 70 #endif // NDEBUG
71 71
72 //------------------------------------------------------------------------------ 72 //------------------------------------------------------------------------------
73 // StatsCounter represents a counter in the StatsTable class. 73 // StatsCounter represents a counter in the StatsTable class.
74 class StatsCounter { 74 class StatsCounter {
75 public: 75 public:
76 // Create a StatsCounter object. 76 // Create a StatsCounter object.
77 explicit StatsCounter(const std::wstring& name) 77 explicit StatsCounter(const std::string& name)
78 : counter_id_(-1) { 78 : counter_id_(-1) {
79 // We prepend the name with 'c:' to indicate that it is a counter. 79 // We prepend the name with 'c:' to indicate that it is a counter.
80 name_ = L"c:"; 80 name_ = "c:";
81 name_.append(name); 81 name_.append(name);
82 }; 82 };
83 83
84 virtual ~StatsCounter() {} 84 virtual ~StatsCounter() {}
85 85
86 // Sets the counter to a specific value. 86 // Sets the counter to a specific value.
87 void Set(int value) { 87 void Set(int value) {
88 int* loc = GetPtr(); 88 int* loc = GetPtr();
89 if (loc) *loc = value; 89 if (loc) *loc = value;
90 } 90 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Returns the cached address of this counter location. 139 // Returns the cached address of this counter location.
140 int* GetPtr() { 140 int* GetPtr() {
141 StatsTable* table = StatsTable::current(); 141 StatsTable* table = StatsTable::current();
142 if (!table) 142 if (!table)
143 return NULL; 143 return NULL;
144 144
145 // If counter_id_ is -1, then we haven't looked it up yet. 145 // If counter_id_ is -1, then we haven't looked it up yet.
146 if (counter_id_ == -1) { 146 if (counter_id_ == -1) {
147 counter_id_ = table->FindCounter(name_); 147 counter_id_ = table->FindCounter(name_);
148 if (table->GetSlot() == 0) { 148 if (table->GetSlot() == 0) {
149 if (!table->RegisterThread(L"")) { 149 if (!table->RegisterThread("")) {
150 // There is no room for this thread. This thread 150 // There is no room for this thread. This thread
151 // cannot use counters. 151 // cannot use counters.
152 counter_id_ = 0; 152 counter_id_ = 0;
153 return NULL; 153 return NULL;
154 } 154 }
155 } 155 }
156 } 156 }
157 157
158 // If counter_id_ is > 0, then we have a valid counter. 158 // If counter_id_ is > 0, then we have a valid counter.
159 if (counter_id_ > 0) 159 if (counter_id_ > 0)
160 return table->GetLocation(counter_id_, table->GetSlot()); 160 return table->GetLocation(counter_id_, table->GetSlot());
161 161
162 // counter_id_ was zero, which means the table is full. 162 // counter_id_ was zero, which means the table is full.
163 return NULL; 163 return NULL;
164 } 164 }
165 165
166 std::wstring name_; 166 std::string name_;
167 // The counter id in the table. We initialize to -1 (an invalid value) 167 // The counter id in the table. We initialize to -1 (an invalid value)
168 // and then cache it once it has been looked up. The counter_id is 168 // and then cache it once it has been looked up. The counter_id is
169 // valid across all threads and processes. 169 // valid across all threads and processes.
170 int32 counter_id_; 170 int32 counter_id_;
171 }; 171 };
172 172
173 173
174 // A StatsCounterTimer is a StatsCounter which keeps a timer during 174 // A StatsCounterTimer is a StatsCounter which keeps a timer during
175 // the scope of the StatsCounterTimer. On destruction, it will record 175 // the scope of the StatsCounterTimer. On destruction, it will record
176 // its time measurement. 176 // its time measurement.
177 class StatsCounterTimer : protected StatsCounter { 177 class StatsCounterTimer : protected StatsCounter {
178 public: 178 public:
179 // Constructs and starts the timer. 179 // Constructs and starts the timer.
180 explicit StatsCounterTimer(const std::wstring& name) { 180 explicit StatsCounterTimer(const std::string& 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_ = "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_ = base::TimeTicks::Now(); 190 start_time_ = base::TimeTicks::Now();
191 stop_time_ = base::TimeTicks(); 191 stop_time_ = base::TimeTicks();
192 } 192 }
(...skipping 30 matching lines...) Expand all
223 base::TimeTicks start_time_; 223 base::TimeTicks start_time_;
224 base::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 char* name)
234 : StatsCounterTimer(name), 234 : StatsCounterTimer(name),
235 counter_(name), 235 counter_(name),
236 largest_add_(std::wstring(L" ").append(name).append(L"MAX").c_str()) { 236 largest_add_(std::string(" ").append(name).append("MAX").c_str()) {
237 } 237 }
238 238
239 virtual void Add(int value) { 239 virtual void Add(int value) {
240 counter_.Increment(); 240 counter_.Increment();
241 StatsCounterTimer::Add(value); 241 StatsCounterTimer::Add(value);
242 if (value > largest_add_.value()) 242 if (value > largest_add_.value())
243 largest_add_.Set(value); 243 largest_add_.Set(value);
244 } 244 }
245 245
246 private: 246 private:
(...skipping 17 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « base/histogram.cc ('k') | base/stats_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698