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

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

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: never rely on outside string permanence Created 3 years, 5 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') | base/metrics/histogram_base.cc » ('J')
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 uint32_t bucket_count, 133 uint32_t bucket_count,
134 int32_t flags); 134 int32_t flags);
135 static HistogramBase* FactoryTimeGet(const char* name, 135 static HistogramBase* FactoryTimeGet(const char* name,
136 base::TimeDelta minimum, 136 base::TimeDelta minimum,
137 base::TimeDelta maximum, 137 base::TimeDelta maximum,
138 uint32_t bucket_count, 138 uint32_t bucket_count,
139 int32_t flags); 139 int32_t flags);
140 140
141 // Create a histogram using data in persistent storage. 141 // Create a histogram using data in persistent storage.
142 static std::unique_ptr<HistogramBase> PersistentCreate( 142 static std::unique_ptr<HistogramBase> PersistentCreate(
143 const std::string& name, 143 const char* name,
144 Sample minimum, 144 Sample minimum,
145 Sample maximum, 145 Sample maximum,
146 const BucketRanges* ranges, 146 const BucketRanges* ranges,
147 const DelayedPersistentAllocation& counts, 147 const DelayedPersistentAllocation& counts,
148 const DelayedPersistentAllocation& logged_counts, 148 const DelayedPersistentAllocation& logged_counts,
149 HistogramSamples::Metadata* meta, 149 HistogramSamples::Metadata* meta,
150 HistogramSamples::Metadata* logged_meta); 150 HistogramSamples::Metadata* logged_meta);
151 151
152 static void InitializeBucketRanges(Sample minimum, 152 static void InitializeBucketRanges(Sample minimum,
153 Sample maximum, 153 Sample maximum,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 protected: 210 protected:
211 // This class, defined entirely within the .cc file, contains all the 211 // This class, defined entirely within the .cc file, contains all the
212 // common logic for building a Histogram and can be overridden by more 212 // common logic for building a Histogram and can be overridden by more
213 // specific types to alter details of how the creation is done. It is 213 // specific types to alter details of how the creation is done. It is
214 // defined as an embedded class (rather than an anonymous one) so it 214 // defined as an embedded class (rather than an anonymous one) so it
215 // can access the protected constructors. 215 // can access the protected constructors.
216 class Factory; 216 class Factory;
217 217
218 // |ranges| should contain the underflow and overflow buckets. See top 218 // |ranges| should contain the underflow and overflow buckets. See top
219 // comments for example. 219 // comments for example.
220 Histogram(const std::string& name, 220 Histogram(const char* name,
221 Sample minimum, 221 Sample minimum,
222 Sample maximum, 222 Sample maximum,
223 const BucketRanges* ranges); 223 const BucketRanges* ranges);
224 224
225 // Traditionally, histograms allocate their own memory for the bucket 225 // Traditionally, histograms allocate their own memory for the bucket
226 // vector but "shared" histograms use memory regions allocated from a 226 // vector but "shared" histograms use memory regions allocated from a
227 // special memory segment that is passed in here. It is assumed that 227 // special memory segment that is passed in here. It is assumed that
228 // the life of this memory is managed externally and exceeds the lifetime 228 // the life of this memory is managed externally and exceeds the lifetime
229 // of this object. Practically, this memory is never released until the 229 // of this object. Practically, this memory is never released until the
230 // process exits and the OS cleans it up. 230 // process exits and the OS cleans it up.
231 Histogram(const std::string& name, 231 Histogram(const char* name,
232 Sample minimum, 232 Sample minimum,
233 Sample maximum, 233 Sample maximum,
234 const BucketRanges* ranges, 234 const BucketRanges* ranges,
235 const DelayedPersistentAllocation& counts, 235 const DelayedPersistentAllocation& counts,
236 const DelayedPersistentAllocation& logged_counts, 236 const DelayedPersistentAllocation& logged_counts,
237 HistogramSamples::Metadata* meta, 237 HistogramSamples::Metadata* meta,
238 HistogramSamples::Metadata* logged_meta); 238 HistogramSamples::Metadata* logged_meta);
239 239
240 // HistogramBase implementation: 240 // HistogramBase implementation:
241 bool SerializeInfoImpl(base::Pickle* pickle) const override; 241 bool SerializeInfoImpl(base::Pickle* pickle) const override;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 uint32_t bucket_count, 350 uint32_t bucket_count,
351 int32_t flags); 351 int32_t flags);
352 static HistogramBase* FactoryTimeGet(const char* name, 352 static HistogramBase* FactoryTimeGet(const char* name,
353 TimeDelta minimum, 353 TimeDelta minimum,
354 TimeDelta maximum, 354 TimeDelta maximum,
355 uint32_t bucket_count, 355 uint32_t bucket_count,
356 int32_t flags); 356 int32_t flags);
357 357
358 // Create a histogram using data in persistent storage. 358 // Create a histogram using data in persistent storage.
359 static std::unique_ptr<HistogramBase> PersistentCreate( 359 static std::unique_ptr<HistogramBase> PersistentCreate(
360 const std::string& name, 360 const char* name,
361 Sample minimum, 361 Sample minimum,
362 Sample maximum, 362 Sample maximum,
363 const BucketRanges* ranges, 363 const BucketRanges* ranges,
364 const DelayedPersistentAllocation& counts, 364 const DelayedPersistentAllocation& counts,
365 const DelayedPersistentAllocation& logged_counts, 365 const DelayedPersistentAllocation& logged_counts,
366 HistogramSamples::Metadata* meta, 366 HistogramSamples::Metadata* meta,
367 HistogramSamples::Metadata* logged_meta); 367 HistogramSamples::Metadata* logged_meta);
368 368
369 struct DescriptionPair { 369 struct DescriptionPair {
370 Sample sample; 370 Sample sample;
(...skipping 16 matching lines...) Expand all
387 static void InitializeBucketRanges(Sample minimum, 387 static void InitializeBucketRanges(Sample minimum,
388 Sample maximum, 388 Sample maximum,
389 BucketRanges* ranges); 389 BucketRanges* ranges);
390 390
391 // Overridden from Histogram: 391 // Overridden from Histogram:
392 HistogramType GetHistogramType() const override; 392 HistogramType GetHistogramType() const override;
393 393
394 protected: 394 protected:
395 class Factory; 395 class Factory;
396 396
397 LinearHistogram(const std::string& name, 397 LinearHistogram(const char* name,
398 Sample minimum, 398 Sample minimum,
399 Sample maximum, 399 Sample maximum,
400 const BucketRanges* ranges); 400 const BucketRanges* ranges);
401 401
402 LinearHistogram(const std::string& name, 402 LinearHistogram(const char* name,
403 Sample minimum, 403 Sample minimum,
404 Sample maximum, 404 Sample maximum,
405 const BucketRanges* ranges, 405 const BucketRanges* ranges,
406 const DelayedPersistentAllocation& counts, 406 const DelayedPersistentAllocation& counts,
407 const DelayedPersistentAllocation& logged_counts, 407 const DelayedPersistentAllocation& logged_counts,
408 HistogramSamples::Metadata* meta, 408 HistogramSamples::Metadata* meta,
409 HistogramSamples::Metadata* logged_meta); 409 HistogramSamples::Metadata* logged_meta);
410 410
411 double GetBucketSize(Count current, uint32_t i) const override; 411 double GetBucketSize(Count current, uint32_t i) const override;
412 412
(...skipping 26 matching lines...) Expand all
439 public: 439 public:
440 static HistogramBase* FactoryGet(const std::string& name, int32_t flags); 440 static HistogramBase* FactoryGet(const std::string& name, int32_t flags);
441 441
442 // Overload of the above function that takes a const char* |name| param, 442 // Overload of the above function that takes a const char* |name| param,
443 // to avoid code bloat from the std::string constructor being inlined into 443 // to avoid code bloat from the std::string constructor being inlined into
444 // call sites. 444 // call sites.
445 static HistogramBase* FactoryGet(const char* name, int32_t flags); 445 static HistogramBase* FactoryGet(const char* name, int32_t flags);
446 446
447 // Create a histogram using data in persistent storage. 447 // Create a histogram using data in persistent storage.
448 static std::unique_ptr<HistogramBase> PersistentCreate( 448 static std::unique_ptr<HistogramBase> PersistentCreate(
449 const std::string& name, 449 const char* name,
450 const BucketRanges* ranges, 450 const BucketRanges* ranges,
451 const DelayedPersistentAllocation& counts, 451 const DelayedPersistentAllocation& counts,
452 const DelayedPersistentAllocation& logged_counts, 452 const DelayedPersistentAllocation& logged_counts,
453 HistogramSamples::Metadata* meta, 453 HistogramSamples::Metadata* meta,
454 HistogramSamples::Metadata* logged_meta); 454 HistogramSamples::Metadata* logged_meta);
455 455
456 HistogramType GetHistogramType() const override; 456 HistogramType GetHistogramType() const override;
457 457
458 protected: 458 protected:
459 class Factory; 459 class Factory;
460 460
461 private: 461 private:
462 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 462 BooleanHistogram(const char* name, const BucketRanges* ranges);
463 BooleanHistogram(const std::string& name, 463 BooleanHistogram(const char* name,
464 const BucketRanges* ranges, 464 const BucketRanges* ranges,
465 const DelayedPersistentAllocation& counts, 465 const DelayedPersistentAllocation& counts,
466 const DelayedPersistentAllocation& logged_counts, 466 const DelayedPersistentAllocation& logged_counts,
467 HistogramSamples::Metadata* meta, 467 HistogramSamples::Metadata* meta,
468 HistogramSamples::Metadata* logged_meta); 468 HistogramSamples::Metadata* logged_meta);
469 469
470 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 470 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
471 base::PickleIterator* iter); 471 base::PickleIterator* iter);
472 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 472 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
473 473
(...skipping 15 matching lines...) Expand all
489 489
490 // Overload of the above function that takes a const char* |name| param, 490 // Overload of the above function that takes a const char* |name| param,
491 // to avoid code bloat from the std::string constructor being inlined into 491 // to avoid code bloat from the std::string constructor being inlined into
492 // call sites. 492 // call sites.
493 static HistogramBase* FactoryGet(const char* name, 493 static HistogramBase* FactoryGet(const char* name,
494 const std::vector<Sample>& custom_ranges, 494 const std::vector<Sample>& custom_ranges,
495 int32_t flags); 495 int32_t flags);
496 496
497 // Create a histogram using data in persistent storage. 497 // Create a histogram using data in persistent storage.
498 static std::unique_ptr<HistogramBase> PersistentCreate( 498 static std::unique_ptr<HistogramBase> PersistentCreate(
499 const std::string& name, 499 const char* name,
500 const BucketRanges* ranges, 500 const BucketRanges* ranges,
501 const DelayedPersistentAllocation& counts, 501 const DelayedPersistentAllocation& counts,
502 const DelayedPersistentAllocation& logged_counts, 502 const DelayedPersistentAllocation& logged_counts,
503 HistogramSamples::Metadata* meta, 503 HistogramSamples::Metadata* meta,
504 HistogramSamples::Metadata* logged_meta); 504 HistogramSamples::Metadata* logged_meta);
505 505
506 // Overridden from Histogram: 506 // Overridden from Histogram:
507 HistogramType GetHistogramType() const override; 507 HistogramType GetHistogramType() const override;
508 508
509 // Helper method for transforming an array of valid enumeration values 509 // Helper method for transforming an array of valid enumeration values
510 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. 510 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION.
511 // This function ensures that a guard bucket exists right after any 511 // This function ensures that a guard bucket exists right after any
512 // valid sample value (unless the next higher sample is also a valid value), 512 // valid sample value (unless the next higher sample is also a valid value),
513 // so that invalid samples never fall into the same bucket as valid samples. 513 // so that invalid samples never fall into the same bucket as valid samples.
514 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 514 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
515 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 515 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
516 uint32_t num_values); 516 uint32_t num_values);
517 protected: 517 protected:
518 class Factory; 518 class Factory;
519 519
520 CustomHistogram(const std::string& name, 520 CustomHistogram(const char* name, const BucketRanges* ranges);
521 const BucketRanges* ranges);
522 521
523 CustomHistogram(const std::string& name, 522 CustomHistogram(const char* name,
524 const BucketRanges* ranges, 523 const BucketRanges* ranges,
525 const DelayedPersistentAllocation& counts, 524 const DelayedPersistentAllocation& counts,
526 const DelayedPersistentAllocation& logged_counts, 525 const DelayedPersistentAllocation& logged_counts,
527 HistogramSamples::Metadata* meta, 526 HistogramSamples::Metadata* meta,
528 HistogramSamples::Metadata* logged_meta); 527 HistogramSamples::Metadata* logged_meta);
529 528
530 // HistogramBase implementation: 529 // HistogramBase implementation:
531 bool SerializeInfoImpl(base::Pickle* pickle) const override; 530 bool SerializeInfoImpl(base::Pickle* pickle) const override;
532 531
533 double GetBucketSize(Count current, uint32_t i) const override; 532 double GetBucketSize(Count current, uint32_t i) const override;
534 533
535 private: 534 private:
536 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo( 535 friend BASE_EXPORT HistogramBase* DeserializeHistogramInfo(
537 base::PickleIterator* iter); 536 base::PickleIterator* iter);
538 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter); 537 static HistogramBase* DeserializeInfoImpl(base::PickleIterator* iter);
539 538
540 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 539 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
541 540
542 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 541 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
543 }; 542 };
544 543
545 } // namespace base 544 } // namespace base
546 545
547 #endif // BASE_METRICS_HISTOGRAM_H_ 546 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/histogram.cc » ('j') | base/metrics/histogram_base.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698