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

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

Issue 11342060: Histogram type support in HistogramBase and remove SetRangeDescription function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove "using" from metrics.cc Created 8 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/message_loop.cc ('k') | 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 class Histogram; 354 class Histogram;
355 class LinearHistogram; 355 class LinearHistogram;
356 356
357 class BASE_EXPORT Histogram : public HistogramBase { 357 class BASE_EXPORT Histogram : public HistogramBase {
358 public: 358 public:
359 // Initialize maximum number of buckets in histograms as 16,384. 359 // Initialize maximum number of buckets in histograms as 16,384.
360 static const size_t kBucketCount_MAX; 360 static const size_t kBucketCount_MAX;
361 361
362 typedef std::vector<Count> Counts; 362 typedef std::vector<Count> Counts;
363 363
364 // These enums are used to facilitate deserialization of renderer histograms
365 // into the browser.
366 enum ClassType {
367 HISTOGRAM,
368 LINEAR_HISTOGRAM,
369 BOOLEAN_HISTOGRAM,
370 CUSTOM_HISTOGRAM,
371 NOT_VALID_IN_RENDERER,
372 };
373
374 enum BucketLayout {
375 EXPONENTIAL,
376 LINEAR,
377 CUSTOM,
378 };
379
380 enum Inconsistencies { 364 enum Inconsistencies {
381 NO_INCONSISTENCIES = 0x0, 365 NO_INCONSISTENCIES = 0x0,
382 RANGE_CHECKSUM_ERROR = 0x1, 366 RANGE_CHECKSUM_ERROR = 0x1,
383 BUCKET_ORDER_ERROR = 0x2, 367 BUCKET_ORDER_ERROR = 0x2,
384 COUNT_HIGH_ERROR = 0x4, 368 COUNT_HIGH_ERROR = 0x4,
385 COUNT_LOW_ERROR = 0x8, 369 COUNT_LOW_ERROR = 0x8,
386 370
387 NEVER_EXCEEDED_VALUE = 0x10 371 NEVER_EXCEEDED_VALUE = 0x10
388 }; 372 };
389 373
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 virtual void AddBoolean(bool value); 410 virtual void AddBoolean(bool value);
427 411
428 // Accept a TimeDelta to increment. 412 // Accept a TimeDelta to increment.
429 void AddTime(TimeDelta time) { 413 void AddTime(TimeDelta time) {
430 Add(static_cast<int>(time.InMilliseconds())); 414 Add(static_cast<int>(time.InMilliseconds()));
431 } 415 }
432 416
433 void AddSamples(const HistogramSamples& samples); 417 void AddSamples(const HistogramSamples& samples);
434 bool AddSamplesFromPickle(PickleIterator* iter); 418 bool AddSamplesFromPickle(PickleIterator* iter);
435 419
436 // This method is an interface, used only by LinearHistogram.
437 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]);
438
439 // Convenience methods for serializing/deserializing the histograms. 420 // Convenience methods for serializing/deserializing the histograms.
440 // Histograms from Renderer process are serialized and sent to the browser. 421 // Histograms from Renderer process are serialized and sent to the browser.
441 // Browser process reconstructs the histogram from the pickled version 422 // Browser process reconstructs the histogram from the pickled version
442 // accumulates the browser-side shadow copy of histograms (that mirror 423 // accumulates the browser-side shadow copy of histograms (that mirror
443 // histograms created in the renderer). 424 // histograms created in the renderer).
444 425
445 // Serialize the given snapshot of a Histogram into a String. Uses 426 // Serialize the given snapshot of a Histogram into a String. Uses
446 // Pickle class to flatten the object. 427 // Pickle class to flatten the object.
447 static std::string SerializeHistogramInfo(const Histogram& histogram, 428 static std::string SerializeHistogramInfo(const Histogram& histogram,
448 const HistogramSamples& snapshot); 429 const HistogramSamples& snapshot);
(...skipping 15 matching lines...) Expand all
464 // Check to see if bucket ranges, counts and tallies in the snapshot are 445 // Check to see if bucket ranges, counts and tallies in the snapshot are
465 // consistent with the bucket ranges and checksums in our histogram. This can 446 // consistent with the bucket ranges and checksums in our histogram. This can
466 // produce a false-alarm if a race occurred in the reading of the data during 447 // produce a false-alarm if a race occurred in the reading of the data during
467 // a SnapShot process, but should otherwise be false at all times (unless we 448 // a SnapShot process, but should otherwise be false at all times (unless we
468 // have memory over-writes, or DRAM failures). 449 // have memory over-writes, or DRAM failures).
469 virtual Inconsistencies FindCorruption(const HistogramSamples& samples) const; 450 virtual Inconsistencies FindCorruption(const HistogramSamples& samples) const;
470 451
471 //---------------------------------------------------------------------------- 452 //----------------------------------------------------------------------------
472 // Accessors for factory constuction, serialization and testing. 453 // Accessors for factory constuction, serialization and testing.
473 //---------------------------------------------------------------------------- 454 //----------------------------------------------------------------------------
474 virtual ClassType histogram_type() const;
475 Sample declared_min() const { return declared_min_; } 455 Sample declared_min() const { return declared_min_; }
476 Sample declared_max() const { return declared_max_; } 456 Sample declared_max() const { return declared_max_; }
477 virtual Sample ranges(size_t i) const; 457 virtual Sample ranges(size_t i) const;
478 virtual size_t bucket_count() const; 458 virtual size_t bucket_count() const;
479 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } 459 const BucketRanges* bucket_ranges() const { return bucket_ranges_; }
480 460
481 // This function validates histogram construction arguments. It returns false 461 // This function validates histogram construction arguments. It returns false
482 // if some of the arguments are totally bad. 462 // if some of the arguments are totally bad.
483 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently 463 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently
484 // converts it to good input: 1. 464 // converts it to good input: 1.
485 // TODO(kaiwang): Be more restrict and return false for any bad input, and 465 // TODO(kaiwang): Be more restrict and return false for any bad input, and
486 // make this a readonly validating function. 466 // make this a readonly validating function.
487 static bool InspectConstructionArguments(const std::string& name, 467 static bool InspectConstructionArguments(const std::string& name,
488 Sample* minimum, 468 Sample* minimum,
489 Sample* maximum, 469 Sample* maximum,
490 size_t* bucket_count); 470 size_t* bucket_count);
491 471
492 // HistogramBase implementation: 472 // HistogramBase implementation:
473 virtual HistogramType GetHistogramType() const OVERRIDE;
493 virtual bool HasConstructionArguments(Sample minimum, 474 virtual bool HasConstructionArguments(Sample minimum,
494 Sample maximum, 475 Sample maximum,
495 size_t bucket_count) const OVERRIDE; 476 size_t bucket_count) const OVERRIDE;
496 virtual void Add(Sample value) OVERRIDE; 477 virtual void Add(Sample value) OVERRIDE;
497 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; 478 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE;
498 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; 479 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE;
499 virtual void WriteAscii(std::string* output) const OVERRIDE; 480 virtual void WriteAscii(std::string* output) const OVERRIDE;
500 481
501 protected: 482 protected:
502 // |bucket_count| and |ranges| should contain the underflow and overflow 483 // |bucket_count| and |ranges| should contain the underflow and overflow
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 Sample minimum, 585 Sample minimum,
605 Sample maximum, 586 Sample maximum,
606 size_t bucket_count, 587 size_t bucket_count,
607 int32 flags); 588 int32 flags);
608 static Histogram* FactoryTimeGet(const std::string& name, 589 static Histogram* FactoryTimeGet(const std::string& name,
609 TimeDelta minimum, 590 TimeDelta minimum,
610 TimeDelta maximum, 591 TimeDelta maximum,
611 size_t bucket_count, 592 size_t bucket_count,
612 int32 flags); 593 int32 flags);
613 594
595 // Create a LinearHistogram and store a list of number/text values for use in
596 // writing the histogram graph.
597 // |descriptions| can be NULL, which means no special descriptions to set. If
598 // it's not NULL, the last element in the array must has a NULL in its
599 // "description" field.
600 static Histogram* FactoryGetWithRangeDescription(
601 const std::string& name,
602 Sample minimum,
603 Sample maximum,
604 size_t bucket_count,
605 int32 flags,
606 const DescriptionPair descriptions[]);
607
614 static void InitializeBucketRanges(Sample minimum, 608 static void InitializeBucketRanges(Sample minimum,
615 Sample maximum, 609 Sample maximum,
616 size_t bucket_count, 610 size_t bucket_count,
617 BucketRanges* ranges); 611 BucketRanges* ranges);
618 612
619 // Overridden from Histogram: 613 // Overridden from Histogram:
620 virtual ClassType histogram_type() const OVERRIDE; 614 virtual HistogramType GetHistogramType() const OVERRIDE;
621
622 // Store a list of number/text values for use in rendering the histogram.
623 // The last element in the array has a null in its "description" slot.
624 virtual void SetRangeDescriptions(
625 const DescriptionPair descriptions[]) OVERRIDE;
626 615
627 protected: 616 protected:
628 LinearHistogram(const std::string& name, 617 LinearHistogram(const std::string& name,
629 Sample minimum, 618 Sample minimum,
630 Sample maximum, 619 Sample maximum,
631 size_t bucket_count, 620 size_t bucket_count,
632 const BucketRanges* ranges); 621 const BucketRanges* ranges);
633 622
634 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; 623 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE;
635 624
(...skipping 15 matching lines...) Expand all
651 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); 640 DISALLOW_COPY_AND_ASSIGN(LinearHistogram);
652 }; 641 };
653 642
654 //------------------------------------------------------------------------------ 643 //------------------------------------------------------------------------------
655 644
656 // BooleanHistogram is a histogram for booleans. 645 // BooleanHistogram is a histogram for booleans.
657 class BASE_EXPORT BooleanHistogram : public LinearHistogram { 646 class BASE_EXPORT BooleanHistogram : public LinearHistogram {
658 public: 647 public:
659 static Histogram* FactoryGet(const std::string& name, int32 flags); 648 static Histogram* FactoryGet(const std::string& name, int32 flags);
660 649
661 virtual ClassType histogram_type() const OVERRIDE; 650 virtual HistogramType GetHistogramType() const OVERRIDE;
662 651
663 virtual void AddBoolean(bool value) OVERRIDE; 652 virtual void AddBoolean(bool value) OVERRIDE;
664 653
665 private: 654 private:
666 BooleanHistogram(const std::string& name, const BucketRanges* ranges); 655 BooleanHistogram(const std::string& name, const BucketRanges* ranges);
667 656
668 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); 657 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram);
669 }; 658 };
670 659
671 //------------------------------------------------------------------------------ 660 //------------------------------------------------------------------------------
672 661
673 // CustomHistogram is a histogram for a set of custom integers. 662 // CustomHistogram is a histogram for a set of custom integers.
674 class BASE_EXPORT CustomHistogram : public Histogram { 663 class BASE_EXPORT CustomHistogram : public Histogram {
675 public: 664 public:
676 // |custom_ranges| contains a vector of limits on ranges. Each limit should be 665 // |custom_ranges| contains a vector of limits on ranges. Each limit should be
677 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward 666 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward
678 // compatibility). The limits can be unordered or contain duplication, but 667 // compatibility). The limits can be unordered or contain duplication, but
679 // client should not depend on this. 668 // client should not depend on this.
680 static Histogram* FactoryGet(const std::string& name, 669 static Histogram* FactoryGet(const std::string& name,
681 const std::vector<Sample>& custom_ranges, 670 const std::vector<Sample>& custom_ranges,
682 int32 flags); 671 int32 flags);
683 672
684 // Overridden from Histogram: 673 // Overridden from Histogram:
685 virtual ClassType histogram_type() const OVERRIDE; 674 virtual HistogramType GetHistogramType() const OVERRIDE;
686 675
687 // Helper method for transforming an array of valid enumeration values 676 // Helper method for transforming an array of valid enumeration values
688 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. 677 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION.
689 // This function ensures that a guard bucket exists right after any 678 // This function ensures that a guard bucket exists right after any
690 // valid sample value (unless the next higher sample is also a valid value), 679 // valid sample value (unless the next higher sample is also a valid value),
691 // so that invalid samples never fall into the same bucket as valid samples. 680 // so that invalid samples never fall into the same bucket as valid samples.
692 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. 681 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges.
693 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, 682 static std::vector<Sample> ArrayToCustomRanges(const Sample* values,
694 size_t num_values); 683 size_t num_values);
695 684
(...skipping 13 matching lines...) Expand all
709 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); 698 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges);
710 static BucketRanges* CreateBucketRangesFromCustomRanges( 699 static BucketRanges* CreateBucketRangesFromCustomRanges(
711 const std::vector<Sample>& custom_ranges); 700 const std::vector<Sample>& custom_ranges);
712 701
713 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); 702 DISALLOW_COPY_AND_ASSIGN(CustomHistogram);
714 }; 703 };
715 704
716 } // namespace base 705 } // namespace base
717 706
718 #endif // BASE_METRICS_HISTOGRAM_H_ 707 #endif // BASE_METRICS_HISTOGRAM_H_
OLDNEW
« no previous file with comments | « base/message_loop.cc ('k') | base/metrics/histogram.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698