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

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

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 years, 3 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
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('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) 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 8
9 // It supports calls to accumulate either time intervals (which are processed 9 // It supports calls to accumulate either time intervals (which are processed
10 // as integral number of milliseconds), or arbitrary integral units. 10 // as integral number of milliseconds), or arbitrary integral units.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include <vector> 73 #include <vector>
74 74
75 #include "base/base_export.h" 75 #include "base/base_export.h"
76 #include "base/compiler_specific.h" 76 #include "base/compiler_specific.h"
77 #include "base/gtest_prod_util.h" 77 #include "base/gtest_prod_util.h"
78 #include "base/logging.h" 78 #include "base/logging.h"
79 #include "base/macros.h" 79 #include "base/macros.h"
80 #include "base/metrics/bucket_ranges.h" 80 #include "base/metrics/bucket_ranges.h"
81 #include "base/metrics/histogram_base.h" 81 #include "base/metrics/histogram_base.h"
82 #include "base/metrics/histogram_samples.h" 82 #include "base/metrics/histogram_samples.h"
83 #include "base/strings/string_piece.h"
83 #include "base/time/time.h" 84 #include "base/time/time.h"
84 85
85 namespace base { 86 namespace base {
86 87
87 class BooleanHistogram; 88 class BooleanHistogram;
88 class CustomHistogram; 89 class CustomHistogram;
89 class DelayedPersistentAllocation; 90 class DelayedPersistentAllocation;
90 class Histogram; 91 class Histogram;
91 class LinearHistogram; 92 class LinearHistogram;
92 class Pickle; 93 class Pickle;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 uint32_t bucket_count, 134 uint32_t bucket_count,
134 int32_t flags); 135 int32_t flags);
135 static HistogramBase* FactoryTimeGet(const char* name, 136 static HistogramBase* FactoryTimeGet(const char* name,
136 base::TimeDelta minimum, 137 base::TimeDelta minimum,
137 base::TimeDelta maximum, 138 base::TimeDelta maximum,
138 uint32_t bucket_count, 139 uint32_t bucket_count,
139 int32_t flags); 140 int32_t flags);
140 141
141 // Create a histogram using data in persistent storage. 142 // Create a histogram using data in persistent storage.
142 static std::unique_ptr<HistogramBase> PersistentCreate( 143 static std::unique_ptr<HistogramBase> PersistentCreate(
143 const std::string& name, 144 const char* name,
144 Sample minimum, 145 Sample minimum,
145 Sample maximum, 146 Sample maximum,
146 const BucketRanges* ranges, 147 const BucketRanges* ranges,
147 const DelayedPersistentAllocation& counts, 148 const DelayedPersistentAllocation& counts,
148 const DelayedPersistentAllocation& logged_counts, 149 const DelayedPersistentAllocation& logged_counts,
149 HistogramSamples::Metadata* meta, 150 HistogramSamples::Metadata* meta,
150 HistogramSamples::Metadata* logged_meta); 151 HistogramSamples::Metadata* logged_meta);
151 152
152 static void InitializeBucketRanges(Sample minimum, 153 static void InitializeBucketRanges(Sample minimum,
153 Sample maximum, 154 Sample maximum,
(...skipping 25 matching lines...) Expand all
179 virtual Sample ranges(uint32_t i) const; 180 virtual Sample ranges(uint32_t i) const;
180 virtual uint32_t bucket_count() const; 181 virtual uint32_t bucket_count() const;
181 182
182 // This function validates histogram construction arguments. It returns false 183 // This function validates histogram construction arguments. It returns false
183 // if some of the arguments are bad but also corrects them so they should 184 // if some of the arguments are bad but also corrects them so they should
184 // function on non-dcheck builds without crashing. 185 // function on non-dcheck builds without crashing.
185 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently 186 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently
186 // converts it to good input: 1. 187 // converts it to good input: 1.
187 // TODO(bcwhite): Use false returns to create "sink" histograms so that bad 188 // TODO(bcwhite): Use false returns to create "sink" histograms so that bad
188 // data doesn't create confusion on the servers. 189 // data doesn't create confusion on the servers.
189 static bool InspectConstructionArguments(const std::string& name, 190 static bool InspectConstructionArguments(StringPiece name,
190 Sample* minimum, 191 Sample* minimum,
191 Sample* maximum, 192 Sample* maximum,
192 uint32_t* bucket_count); 193 uint32_t* bucket_count);
193 194
194 // HistogramBase implementation: 195 // HistogramBase implementation:
195 uint64_t name_hash() const override; 196 uint64_t name_hash() const override;
196 HistogramType GetHistogramType() const override; 197 HistogramType GetHistogramType() const override;
197 bool HasConstructionArguments(Sample expected_minimum, 198 bool HasConstructionArguments(Sample expected_minimum,
198 Sample expected_maximum, 199 Sample expected_maximum,
199 uint32_t expected_bucket_count) const override; 200 uint32_t expected_bucket_count) const override;
(...skipping 19 matching lines...) Expand all
219 protected: 220 protected:
220 // This class, defined entirely within the .cc file, contains all the 221 // This class, defined entirely within the .cc file, contains all the
221 // common logic for building a Histogram and can be overridden by more 222 // common logic for building a Histogram and can be overridden by more
222 // specific types to alter details of how the creation is done. It is 223 // specific types to alter details of how the creation is done. It is
223 // defined as an embedded class (rather than an anonymous one) so it 224 // defined as an embedded class (rather than an anonymous one) so it
224 // can access the protected constructors. 225 // can access the protected constructors.
225 class Factory; 226 class Factory;
226 227
227 // |ranges| should contain the underflow and overflow buckets. See top 228 // |ranges| should contain the underflow and overflow buckets. See top
228 // comments for example. 229 // comments for example.
229 Histogram(const std::string& name, 230 Histogram(const char* name,
230 Sample minimum, 231 Sample minimum,
231 Sample maximum, 232 Sample maximum,
232 const BucketRanges* ranges); 233 const BucketRanges* ranges);
233 234
234 // Traditionally, histograms allocate their own memory for the bucket 235 // Traditionally, histograms allocate their own memory for the bucket
235 // vector but "shared" histograms use memory regions allocated from a 236 // vector but "shared" histograms use memory regions allocated from a
236 // special memory segment that is passed in here. It is assumed that 237 // special memory segment that is passed in here. It is assumed that
237 // the life of this memory is managed externally and exceeds the lifetime 238 // the life of this memory is managed externally and exceeds the lifetime
238 // of this object. Practically, this memory is never released until the 239 // of this object. Practically, this memory is never released until the
239 // process exits and the OS cleans it up. 240 // process exits and the OS cleans it up.
240 Histogram(const std::string& name, 241 Histogram(const char* name,
241 Sample minimum, 242 Sample minimum,
242 Sample maximum, 243 Sample maximum,
243 const BucketRanges* ranges, 244 const BucketRanges* ranges,
244 const DelayedPersistentAllocation& counts, 245 const DelayedPersistentAllocation& counts,
245 const DelayedPersistentAllocation& logged_counts, 246 const DelayedPersistentAllocation& logged_counts,
246 HistogramSamples::Metadata* meta, 247 HistogramSamples::Metadata* meta,
247 HistogramSamples::Metadata* logged_meta); 248 HistogramSamples::Metadata* logged_meta);
248 249
249 // HistogramBase implementation: 250 // HistogramBase implementation:
250 bool SerializeInfoImpl(base::Pickle* pickle) const override; 251 bool SerializeInfoImpl(base::Pickle* pickle) const override;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 uint32_t bucket_count, 364 uint32_t bucket_count,
364 int32_t flags); 365 int32_t flags);
365 static HistogramBase* FactoryTimeGet(const char* name, 366 static HistogramBase* FactoryTimeGet(const char* name,
366 TimeDelta minimum, 367 TimeDelta minimum,
367 TimeDelta maximum, 368 TimeDelta maximum,
368 uint32_t bucket_count, 369 uint32_t bucket_count,
369 int32_t flags); 370 int32_t flags);
370 371
371 // Create a histogram using data in persistent storage. 372 // Create a histogram using data in persistent storage.
372 static std::unique_ptr<HistogramBase> PersistentCreate( 373 static std::unique_ptr<HistogramBase> PersistentCreate(
373 const std::string& name, 374 const char* name,
374 Sample minimum, 375 Sample minimum,
375 Sample maximum, 376 Sample maximum,
376 const BucketRanges* ranges, 377 const BucketRanges* ranges,
377 const DelayedPersistentAllocation& counts, 378 const DelayedPersistentAllocation& counts,
378 const DelayedPersistentAllocation& logged_counts, 379 const DelayedPersistentAllocation& logged_counts,
379 HistogramSamples::Metadata* meta, 380 HistogramSamples::Metadata* meta,
380 HistogramSamples::Metadata* logged_meta); 381 HistogramSamples::Metadata* logged_meta);
381 382
382 struct DescriptionPair { 383 struct DescriptionPair {
383 Sample sample; 384 Sample sample;
(...skipping 16 matching lines...) Expand all
400 static void InitializeBucketRanges(Sample minimum, 401 static void InitializeBucketRanges(Sample minimum,
401 Sample maximum, 402 Sample maximum,
402 BucketRanges* ranges); 403 BucketRanges* ranges);
403 404
404 // Overridden from Histogram: 405 // Overridden from Histogram:
405 HistogramType GetHistogramType() const override; 406 HistogramType GetHistogramType() const override;
406 407
407 protected: 408 protected:
408 class Factory; 409 class Factory;
409 410
410 LinearHistogram(const std::string& name, 411 LinearHistogram(const char* name,
411 Sample minimum, 412 Sample minimum,
412 Sample maximum, 413 Sample maximum,
413 const BucketRanges* ranges); 414 const BucketRanges* ranges);
414 415
415 LinearHistogram(const std::string& name, 416 LinearHistogram(const char* name,
416 Sample minimum, 417 Sample minimum,
417 Sample maximum, 418 Sample maximum,
418 const BucketRanges* ranges, 419 const BucketRanges* ranges,
419 const DelayedPersistentAllocation& counts, 420 const DelayedPersistentAllocation& counts,
420 const DelayedPersistentAllocation& logged_counts, 421 const DelayedPersistentAllocation& logged_counts,
421 HistogramSamples::Metadata* meta, 422 HistogramSamples::Metadata* meta,
422 HistogramSamples::Metadata* logged_meta); 423 HistogramSamples::Metadata* logged_meta);
423 424
424 double GetBucketSize(Count current, uint32_t i) const override; 425 double GetBucketSize(Count current, uint32_t i) const override;
425 426
(...skipping 26 matching lines...) Expand all
452 public: 453 public:
453 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); 454 static HistogramBase* FactoryGet(const std::string& name, int32_t flags);
454 455
455 // Overload of the above function that takes a const char* |name| param, 456 // Overload of the above function that takes a const char* |name| param,
456 // to avoid code bloat from the std::string constructor being inlined into 457 // to avoid code bloat from the std::string constructor being inlined into
457 // call sites. 458 // call sites.
458 static HistogramBase* FactoryGet(const char* name, int32_t flags); 459 static HistogramBase* FactoryGet(const char* name, int32_t flags);
459 460
460 // Create a histogram using data in persistent storage. 461 // Create a histogram using data in persistent storage.
461 static std::unique_ptr<HistogramBase> PersistentCreate( 462 static std::unique_ptr<HistogramBase> PersistentCreate(
462 const std::string& name, 463 const char* name,
463 const BucketRanges* ranges, 464 const BucketRanges* ranges,
464 const DelayedPersistentAllocation& counts, 465 const DelayedPersistentAllocation& counts,
465 const DelayedPersistentAllocation& logged_counts, 466 const DelayedPersistentAllocation& logged_counts,
466 HistogramSamples::Metadata* meta, 467 HistogramSamples::Metadata* meta,
467 HistogramSamples::Metadata* logged_meta); 468 HistogramSamples::Metadata* logged_meta);
468 469
469 HistogramType GetHistogramType() const override; 470 HistogramType GetHistogramType() const override;
470 471
471 protected: 472 protected:
472 class Factory; 473 class Factory;
473 474
474 private: 475 private:
475 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 476 BooleanHistogram(const char* name, const BucketRanges* ranges);
476 BooleanHistogram(const std::string& name, 477 BooleanHistogram(const char* name,
477 const BucketRanges* ranges, 478 const BucketRanges* ranges,
478 const DelayedPersistentAllocation& counts, 479 const DelayedPersistentAllocation& counts,
479 const DelayedPersistentAllocation& logged_counts, 480 const DelayedPersistentAllocation& logged_counts,
480 HistogramSamples::Metadata* meta, 481 HistogramSamples::Metadata* meta,
481 HistogramSamples::Metadata* logged_meta); 482 HistogramSamples::Metadata* logged_meta);
482 483
483 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 484 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
484 base::PickleIterator* iter); 485 base::PickleIterator* iter);
485 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 486 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
486 487
(...skipping 15 matching lines...) Expand all
502 503
503 // Overload of the above function that takes a const char* |name| param, 504 // Overload of the above function that takes a const char* |name| param,
504 // to avoid code bloat from the std::string constructor being inlined into 505 // to avoid code bloat from the std::string constructor being inlined into
505 // call sites. 506 // call sites.
506 static HistogramBase* FactoryGet(const char* name, 507 static HistogramBase* FactoryGet(const char* name,
507 const std::vector<Sample>& custom_ranges, 508 const std::vector<Sample>& custom_ranges,
508 int32_t flags); 509 int32_t flags);
509 510
510 // Create a histogram using data in persistent storage. 511 // Create a histogram using data in persistent storage.
511 static std::unique_ptr<HistogramBase> PersistentCreate( 512 static std::unique_ptr<HistogramBase> PersistentCreate(
512 const std::string& name, 513 const char* name,
513 const BucketRanges* ranges, 514 const BucketRanges* ranges,
514 const DelayedPersistentAllocation& counts, 515 const DelayedPersistentAllocation& counts,
515 const DelayedPersistentAllocation& logged_counts, 516 const DelayedPersistentAllocation& logged_counts,
516 HistogramSamples::Metadata* meta, 517 HistogramSamples::Metadata* meta,
517 HistogramSamples::Metadata* logged_meta); 518 HistogramSamples::Metadata* logged_meta);
518 519
519 // Overridden from Histogram: 520 // Overridden from Histogram:
520 HistogramType GetHistogramType() const override; 521 HistogramType GetHistogramType() const override;
521 522
522 // Helper method for transforming an array of valid enumeration values 523 // Helper method for transforming an array of valid enumeration values
523 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. 524 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION.
524 // This function ensures that a guard bucket exists right after any 525 // This function ensures that a guard bucket exists right after any
525 // valid sample value (unless the next higher sample is also a valid value), 526 // valid sample value (unless the next higher sample is also a valid value),
526 // so that invalid samples never fall into the same bucket as valid samples. 527 // so that invalid samples never fall into the same bucket as valid samples.
527 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 528 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
528 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 529 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
529 uint32_t num_values); 530 uint32_t num_values);
530 protected: 531 protected:
531 class Factory; 532 class Factory;
532 533
533 CustomHistogram(const std::string& name, 534 CustomHistogram(const char* name, const BucketRanges* ranges);
534 const BucketRanges* ranges);
535 535
536 CustomHistogram(const std::string& name, 536 CustomHistogram(const char* name,
537 const BucketRanges* ranges, 537 const BucketRanges* ranges,
538 const DelayedPersistentAllocation& counts, 538 const DelayedPersistentAllocation& counts,
539 const DelayedPersistentAllocation& logged_counts, 539 const DelayedPersistentAllocation& logged_counts,
540 HistogramSamples::Metadata* meta, 540 HistogramSamples::Metadata* meta,
541 HistogramSamples::Metadata* logged_meta); 541 HistogramSamples::Metadata* logged_meta);
542 542
543 // HistogramBase implementation: 543 // HistogramBase implementation:
544 bool SerializeInfoImpl(base::Pickle* pickle) const override; 544 bool SerializeInfoImpl(base::Pickle* pickle) const override;
545 545
546 double GetBucketSize(Count current, uint32_t i) const override; 546 double GetBucketSize(Count current, uint32_t i) const override;
547 547
548 private: 548 private:
549 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 549 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
550 base::PickleIterator* iter); 550 base::PickleIterator* iter);
551 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 551 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
552 552
553 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 553 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
554 554
555 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 555 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
556 }; 556 };
557 557
558 } // namespace base 558 } // namespace base
559 559
560 #endif // BASE_METRICS_HISTOGRAM_H_ 560 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698