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

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

Issue 1471073007: Reorganize histograms for persistence. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: extra parameter no longer necessary in some files Created 5 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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"
11 11
12 #include <math.h> 12 #include <math.h>
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <string> 15 #include <string>
16 16
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/debug/alias.h" 18 #include "base/debug/alias.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/metrics/metrics_hashes.h"
21 #include "base/metrics/sample_vector.h" 22 #include "base/metrics/sample_vector.h"
22 #include "base/metrics/statistics_recorder.h" 23 #include "base/metrics/statistics_recorder.h"
23 #include "base/pickle.h" 24 #include "base/pickle.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
26 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 29
29 namespace base { 30 namespace base {
30 31
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 253
253 if (*minimum >= *maximum) 254 if (*minimum >= *maximum)
254 return false; 255 return false;
255 if (*bucket_count < 3) 256 if (*bucket_count < 3)
256 return false; 257 return false;
257 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) 258 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2))
258 return false; 259 return false;
259 return true; 260 return true;
260 } 261 }
261 262
263 uint64_t Histogram::name_hash() const {
264 return samples_->id();
265 }
266
262 HistogramType Histogram::GetHistogramType() const { 267 HistogramType Histogram::GetHistogramType() const {
263 return HISTOGRAM; 268 return HISTOGRAM;
264 } 269 }
265 270
266 bool Histogram::HasConstructionArguments(Sample expected_minimum, 271 bool Histogram::HasConstructionArguments(Sample expected_minimum,
267 Sample expected_maximum, 272 Sample expected_maximum,
268 size_t expected_bucket_count) const { 273 size_t expected_bucket_count) const {
269 return ((expected_minimum == declared_min_) && 274 return ((expected_minimum == declared_min_) &&
270 (expected_maximum == declared_max_) && 275 (expected_maximum == declared_max_) &&
271 (expected_bucket_count == bucket_count())); 276 (expected_bucket_count == bucket_count()));
(...skipping 18 matching lines...) Expand all
290 samples_->Accumulate(value, count); 295 samples_->Accumulate(value, count);
291 296
292 FindAndRunCallback(value); 297 FindAndRunCallback(value);
293 } 298 }
294 299
295 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { 300 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const {
296 return SnapshotSampleVector(); 301 return SnapshotSampleVector();
297 } 302 }
298 303
299 void Histogram::AddSamples(const HistogramSamples& samples) { 304 void Histogram::AddSamples(const HistogramSamples& samples) {
305 DCHECK(samples.id() == 0 || samples.id() == samples_->id());
Alexei Svitkine (slow) 2015/12/01 16:32:14 This seems to be adding an implicit requirement to
bcwhite 2015/12/01 18:12:15 I always imagined that "id" (if present, that is n
Alexei Svitkine (slow) 2015/12/01 18:27:14 Well, my mental model is this method is just "add
bcwhite 2015/12/01 19:33:44 Okay, I can move the DCHECK no problem.
300 samples_->Add(samples); 306 samples_->Add(samples);
301 } 307 }
302 308
303 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { 309 bool Histogram::AddSamplesFromPickle(PickleIterator* iter) {
304 return samples_->AddFromPickle(iter); 310 return samples_->AddFromPickle(iter);
305 } 311 }
306 312
307 // The following methods provide a graphical histogram display. 313 // The following methods provide a graphical histogram display.
308 void Histogram::WriteHTMLGraph(std::string* output) const { 314 void Histogram::WriteHTMLGraph(std::string* output) const {
309 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc. 315 // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc.
(...skipping 18 matching lines...) Expand all
328 334
329 Histogram::Histogram(const std::string& name, 335 Histogram::Histogram(const std::string& name,
330 Sample minimum, 336 Sample minimum,
331 Sample maximum, 337 Sample maximum,
332 const BucketRanges* ranges) 338 const BucketRanges* ranges)
333 : HistogramBase(name), 339 : HistogramBase(name),
334 bucket_ranges_(ranges), 340 bucket_ranges_(ranges),
335 declared_min_(minimum), 341 declared_min_(minimum),
336 declared_max_(maximum) { 342 declared_max_(maximum) {
337 if (ranges) 343 if (ranges)
338 samples_.reset(new SampleVector(ranges)); 344 samples_.reset(new SampleVector(HashMetricName(name), ranges));
339 } 345 }
340 346
341 Histogram::~Histogram() { 347 Histogram::~Histogram() {
342 } 348 }
343 349
344 bool Histogram::PrintEmptyBucket(size_t index) const { 350 bool Histogram::PrintEmptyBucket(size_t index) const {
345 return true; 351 return true;
346 } 352 }
347 353
348 // Use the actual bucket widths (like a linear histogram) until the widths get 354 // Use the actual bucket widths (like a linear histogram) until the widths get
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 histogram_name, declared_min, declared_max, bucket_count, flags); 391 histogram_name, declared_min, declared_max, bucket_count, flags);
386 392
387 if (!ValidateRangeChecksum(*histogram, range_checksum)) { 393 if (!ValidateRangeChecksum(*histogram, range_checksum)) {
388 // The serialized histogram might be corrupted. 394 // The serialized histogram might be corrupted.
389 return NULL; 395 return NULL;
390 } 396 }
391 return histogram; 397 return histogram;
392 } 398 }
393 399
394 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { 400 scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const {
395 scoped_ptr<SampleVector> samples(new SampleVector(bucket_ranges())); 401 scoped_ptr<SampleVector> samples(
402 new SampleVector(HashMetricName(histogram_name()), bucket_ranges()));
Alexei Svitkine (slow) 2015/12/01 16:32:14 Can this use the id from samples_ instead of re-co
bcwhite 2015/12/01 18:12:15 Done.
Alexei Svitkine (slow) 2015/12/01 18:27:14 Doesn't seem like you uploaded a new patch set?
bcwhite 2015/12/01 19:33:44 Not yet. So far all the changes have been cosmeti
396 samples->Add(*samples_); 403 samples->Add(*samples_);
397 return samples; 404 return samples;
398 } 405 }
399 406
400 void Histogram::WriteAsciiImpl(bool graph_it, 407 void Histogram::WriteAsciiImpl(bool graph_it,
401 const std::string& newline, 408 const std::string& newline,
402 std::string* output) const { 409 std::string* output) const {
403 // Get local (stack) copies of all effectively volatile class data so that we 410 // Get local (stack) copies of all effectively volatile class data so that we
404 // are consistent across our output activities. 411 // are consistent across our output activities.
405 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); 412 scoped_ptr<SampleVector> snapshot = SnapshotSampleVector();
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 899
893 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); 900 BucketRanges* bucket_ranges = new BucketRanges(ranges.size());
894 for (size_t i = 0; i < ranges.size(); i++) { 901 for (size_t i = 0; i < ranges.size(); i++) {
895 bucket_ranges->set_range(i, ranges[i]); 902 bucket_ranges->set_range(i, ranges[i]);
896 } 903 }
897 bucket_ranges->ResetChecksum(); 904 bucket_ranges->ResetChecksum();
898 return bucket_ranges; 905 return bucket_ranges;
899 } 906 }
900 907
901 } // namespace base 908 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698