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

Side by Side Diff: base/metrics/histogram.cc

Issue 8506038: Support using UMA_HISTOGRAM_CUSTOM_ENUMERATION from the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 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 | Annotate | Revision Log
« no previous file with comments | « base/metrics/histogram.h ('k') | no next file » | 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) 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 // Histogram is an object that aggregates statistics, and can summarize them in 5 // Histogram is an object that aggregates statistics, and can summarize them in
6 // various forms, including ASCII graphical, HTML, and numerically (as a 6 // various forms, including ASCII graphical, HTML, and numerically (as a
7 // vector of numbers corresponding to each of the aggregating buckets). 7 // vector of numbers corresponding to each of the aggregating buckets).
8 // See header file for details and examples. 8 // See header file for details and examples.
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 Pickle pickle; 232 Pickle pickle;
233 pickle.WriteString(histogram.histogram_name()); 233 pickle.WriteString(histogram.histogram_name());
234 pickle.WriteInt(histogram.declared_min()); 234 pickle.WriteInt(histogram.declared_min());
235 pickle.WriteInt(histogram.declared_max()); 235 pickle.WriteInt(histogram.declared_max());
236 pickle.WriteSize(histogram.bucket_count()); 236 pickle.WriteSize(histogram.bucket_count());
237 pickle.WriteUInt32(histogram.range_checksum()); 237 pickle.WriteUInt32(histogram.range_checksum());
238 pickle.WriteInt(histogram.histogram_type()); 238 pickle.WriteInt(histogram.histogram_type());
239 pickle.WriteInt(histogram.flags()); 239 pickle.WriteInt(histogram.flags());
240 240
241 snapshot.Serialize(&pickle); 241 snapshot.Serialize(&pickle);
242
243 if (histogram.histogram_type() == CUSTOM_HISTOGRAM)
244 histogram.cached_ranges()->Serialize(&pickle);
jar (doing other things) 2011/11/11 19:43:38 Maybe this should be a call to a base class method
Ami GONE FROM CHROMIUM 2011/11/11 22:44:48 I think having Histogram have two methods, a stati
245
242 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); 246 return std::string(static_cast<const char*>(pickle.data()), pickle.size());
243 } 247 }
244 248
245 // static 249 // static
246 bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) { 250 bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
247 if (histogram_info.empty()) { 251 if (histogram_info.empty()) {
248 return false; 252 return false;
249 } 253 }
250 254
251 Pickle pickle(histogram_info.data(), 255 Pickle pickle(histogram_info.data(),
252 static_cast<int>(histogram_info.size())); 256 static_cast<int>(histogram_info.size()));
253 std::string histogram_name; 257 std::string histogram_name;
254 int declared_min; 258 int declared_min;
255 int declared_max; 259 int declared_max;
256 size_t bucket_count; 260 size_t bucket_count;
257 uint32 range_checksum; 261 uint32 range_checksum;
258 int histogram_type; 262 int histogram_type;
259 int pickle_flags; 263 int pickle_flags;
260 SampleSet sample; 264 SampleSet sample;
261 265
262 void* iter = NULL; 266 void* iter = NULL;
263 if (!pickle.ReadString(&iter, &histogram_name) || 267 if (!pickle.ReadString(&iter, &histogram_name) ||
264 !pickle.ReadInt(&iter, &declared_min) || 268 !pickle.ReadInt(&iter, &declared_min) ||
265 !pickle.ReadInt(&iter, &declared_max) || 269 !pickle.ReadInt(&iter, &declared_max) ||
266 !pickle.ReadSize(&iter, &bucket_count) || 270 !pickle.ReadSize(&iter, &bucket_count) ||
267 !pickle.ReadUInt32(&iter, &range_checksum) || 271 !pickle.ReadUInt32(&iter, &range_checksum) ||
268 !pickle.ReadInt(&iter, &histogram_type) || 272 !pickle.ReadInt(&iter, &histogram_type) ||
269 !pickle.ReadInt(&iter, &pickle_flags) || 273 !pickle.ReadInt(&iter, &pickle_flags) ||
270 !sample.Histogram::SampleSet::Deserialize(&iter, pickle)) { 274 !sample.Histogram::SampleSet::Deserialize(&iter, pickle)) {
271 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; 275 DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name;
272 return false; 276 return false;
273 } 277 }
278
279 std::vector<Histogram::Sample> sample_ranges;
280 if (histogram_type == CUSTOM_HISTOGRAM) {
281 CachedRanges ranges(bucket_count, 0);
282 if (!ranges.Deserialize(&iter, pickle) ||
283 ranges.size() != bucket_count) {
284 DLOG(ERROR) << "Pickle error decoding ranges: " << histogram_name;
285 return false;
286 }
287 for (size_t i = 0; i < bucket_count; ++i)
288 sample_ranges.push_back(ranges.ranges(i));
289 }
290
274 DCHECK(pickle_flags & kIPCSerializationSourceFlag); 291 DCHECK(pickle_flags & kIPCSerializationSourceFlag);
275 // Since these fields may have come from an untrusted renderer, do additional 292 // Since these fields may have come from an untrusted renderer, do additional
276 // checks above and beyond those in Histogram::Initialize() 293 // checks above and beyond those in Histogram::Initialize()
277 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min || 294 if (declared_max <= 0 || declared_min <= 0 || declared_max < declared_min ||
278 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) { 295 INT_MAX / sizeof(Count) <= bucket_count || bucket_count < 2) {
279 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name; 296 DLOG(ERROR) << "Values error decoding Histogram: " << histogram_name;
280 return false; 297 return false;
281 } 298 }
282 299
283 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag); 300 Flags flags = static_cast<Flags>(pickle_flags & ~kIPCSerializationSourceFlag);
284 301
285 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type); 302 DCHECK_NE(NOT_VALID_IN_RENDERER, histogram_type);
286 303
287 Histogram* render_histogram(NULL); 304 Histogram* render_histogram(NULL);
288 305
289 if (histogram_type == HISTOGRAM) { 306 if (histogram_type == HISTOGRAM) {
290 render_histogram = Histogram::FactoryGet( 307 render_histogram = Histogram::FactoryGet(
291 histogram_name, declared_min, declared_max, bucket_count, flags); 308 histogram_name, declared_min, declared_max, bucket_count, flags);
292 } else if (histogram_type == LINEAR_HISTOGRAM) { 309 } else if (histogram_type == LINEAR_HISTOGRAM) {
293 render_histogram = LinearHistogram::FactoryGet( 310 render_histogram = LinearHistogram::FactoryGet(
294 histogram_name, declared_min, declared_max, bucket_count, flags); 311 histogram_name, declared_min, declared_max, bucket_count, flags);
295 } else if (histogram_type == BOOLEAN_HISTOGRAM) { 312 } else if (histogram_type == BOOLEAN_HISTOGRAM) {
296 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags); 313 render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags);
314 } else if (histogram_type == CUSTOM_HISTOGRAM) {
315 render_histogram =
316 CustomHistogram::FactoryGet(histogram_name, sample_ranges, flags);
297 } else { 317 } else {
298 DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " 318 DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: "
299 << histogram_type; 319 << histogram_type;
300 return false; 320 return false;
301 } 321 }
302 322
303 DCHECK_EQ(render_histogram->declared_min(), declared_min); 323 DCHECK_EQ(render_histogram->declared_min(), declared_min);
304 DCHECK_EQ(render_histogram->declared_max(), declared_max); 324 DCHECK_EQ(render_histogram->declared_max(), declared_max);
305 DCHECK_EQ(render_histogram->bucket_count(), bucket_count); 325 DCHECK_EQ(render_histogram->bucket_count(), bucket_count);
306 DCHECK_EQ(render_histogram->range_checksum(), range_checksum); 326 DCHECK_EQ(render_histogram->range_checksum(), range_checksum);
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 return false; 1293 return false;
1274 if (ranges_.size() != other->ranges_.size()) 1294 if (ranges_.size() != other->ranges_.size())
1275 return false; 1295 return false;
1276 for (size_t index = 0; index < ranges_.size(); ++index) { 1296 for (size_t index = 0; index < ranges_.size(); ++index) {
1277 if (ranges_[index] != other->ranges_[index]) 1297 if (ranges_[index] != other->ranges_[index])
1278 return false; 1298 return false;
1279 } 1299 }
1280 return true; 1300 return true;
1281 } 1301 }
1282 1302
1303
jar (doing other things) 2011/11/11 19:43:38 nit: remove extra blank line
Ami GONE FROM CHROMIUM 2011/11/11 22:44:48 Done.
1304 bool CachedRanges::Serialize(Pickle* pickle) const {
jar (doing other things) 2011/11/11 19:43:38 I *think* that if you want to put this method in a
Ami GONE FROM CHROMIUM 2011/11/11 22:44:48 I agree with your basic concern, which is that the
1305 for (size_t i = 0; i < ranges_.size(); ++i) {
1306 if (!pickle->WriteInt(ranges_[i]))
1307 return false;
1308 }
1309 return true;
1310 }
1311
1312 bool CachedRanges::Deserialize(void** iter, const Pickle& pickle) {
jar (doing other things) 2011/11/11 19:43:38 I'm not convinced that this method should be in th
Ami GONE FROM CHROMIUM 2011/11/11 22:44:48 See above.
1313 for (size_t i = 0; i < ranges_.size(); ++i) {
1314 if (!pickle.ReadInt(iter, &ranges_[i]))
1315 return false;
1316 }
1317 return true;
1318 }
1319
1283 // static 1320 // static
1284 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 1321 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
1285 // static 1322 // static
1286 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 1323 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
1287 // static 1324 // static
1288 base::Lock* StatisticsRecorder::lock_ = NULL; 1325 base::Lock* StatisticsRecorder::lock_ = NULL;
1289 // static 1326 // static
1290 bool StatisticsRecorder::dump_on_exit_ = false; 1327 bool StatisticsRecorder::dump_on_exit_ = false;
1291 } // namespace base 1328 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698