Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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. The last element in the array has a NULL in | |
| 597 // its "description" field. | |
|
Ilya Sherman
2012/10/31 00:35:19
nit: You should document that |descriptions| can b
kaiwang
2012/10/31 01:12:56
Done.
| |
| 598 static Histogram* FactoryGetWithRangeDescription( | |
| 599 const std::string& name, | |
| 600 Sample minimum, | |
| 601 Sample maximum, | |
| 602 size_t bucket_count, | |
| 603 int32 flags, | |
| 604 const DescriptionPair descriptions[]); | |
| 605 | |
| 614 static void InitializeBucketRanges(Sample minimum, | 606 static void InitializeBucketRanges(Sample minimum, |
| 615 Sample maximum, | 607 Sample maximum, |
| 616 size_t bucket_count, | 608 size_t bucket_count, |
| 617 BucketRanges* ranges); | 609 BucketRanges* ranges); |
| 618 | 610 |
| 619 // Overridden from Histogram: | 611 // Overridden from Histogram: |
| 620 virtual ClassType histogram_type() const OVERRIDE; | 612 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 | 613 |
| 627 protected: | 614 protected: |
| 628 LinearHistogram(const std::string& name, | 615 LinearHistogram(const std::string& name, |
| 629 Sample minimum, | 616 Sample minimum, |
| 630 Sample maximum, | 617 Sample maximum, |
| 631 size_t bucket_count, | 618 size_t bucket_count, |
| 632 const BucketRanges* ranges); | 619 const BucketRanges* ranges); |
| 633 | 620 |
| 634 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; | 621 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; |
| 635 | 622 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 651 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); | 638 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); |
| 652 }; | 639 }; |
| 653 | 640 |
| 654 //------------------------------------------------------------------------------ | 641 //------------------------------------------------------------------------------ |
| 655 | 642 |
| 656 // BooleanHistogram is a histogram for booleans. | 643 // BooleanHistogram is a histogram for booleans. |
| 657 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 644 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
| 658 public: | 645 public: |
| 659 static Histogram* FactoryGet(const std::string& name, int32 flags); | 646 static Histogram* FactoryGet(const std::string& name, int32 flags); |
| 660 | 647 |
| 661 virtual ClassType histogram_type() const OVERRIDE; | 648 virtual HistogramType GetHistogramType() const OVERRIDE; |
| 662 | 649 |
| 663 virtual void AddBoolean(bool value) OVERRIDE; | 650 virtual void AddBoolean(bool value) OVERRIDE; |
| 664 | 651 |
| 665 private: | 652 private: |
| 666 BooleanHistogram(const std::string& name, const BucketRanges* ranges); | 653 BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
| 667 | 654 |
| 668 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 655 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
| 669 }; | 656 }; |
| 670 | 657 |
| 671 //------------------------------------------------------------------------------ | 658 //------------------------------------------------------------------------------ |
| 672 | 659 |
| 673 // CustomHistogram is a histogram for a set of custom integers. | 660 // CustomHistogram is a histogram for a set of custom integers. |
| 674 class BASE_EXPORT CustomHistogram : public Histogram { | 661 class BASE_EXPORT CustomHistogram : public Histogram { |
| 675 public: | 662 public: |
| 676 // |custom_ranges| contains a vector of limits on ranges. Each limit should be | 663 // |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 | 664 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward |
| 678 // compatibility). The limits can be unordered or contain duplication, but | 665 // compatibility). The limits can be unordered or contain duplication, but |
| 679 // client should not depend on this. | 666 // client should not depend on this. |
| 680 static Histogram* FactoryGet(const std::string& name, | 667 static Histogram* FactoryGet(const std::string& name, |
| 681 const std::vector<Sample>& custom_ranges, | 668 const std::vector<Sample>& custom_ranges, |
| 682 int32 flags); | 669 int32 flags); |
| 683 | 670 |
| 684 // Overridden from Histogram: | 671 // Overridden from Histogram: |
| 685 virtual ClassType histogram_type() const OVERRIDE; | 672 virtual HistogramType GetHistogramType() const OVERRIDE; |
| 686 | 673 |
| 687 // Helper method for transforming an array of valid enumeration values | 674 // Helper method for transforming an array of valid enumeration values |
| 688 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. | 675 // to the std::vector<int> expected by HISTOGRAM_CUSTOM_ENUMERATION. |
| 689 // This function ensures that a guard bucket exists right after any | 676 // 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), | 677 // 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. | 678 // so that invalid samples never fall into the same bucket as valid samples. |
| 692 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. | 679 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. |
| 693 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 680 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
| 694 size_t num_values); | 681 size_t num_values); |
| 695 | 682 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 709 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 696 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
| 710 static BucketRanges* CreateBucketRangesFromCustomRanges( | 697 static BucketRanges* CreateBucketRangesFromCustomRanges( |
| 711 const std::vector<Sample>& custom_ranges); | 698 const std::vector<Sample>& custom_ranges); |
| 712 | 699 |
| 713 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 700 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| 714 }; | 701 }; |
| 715 | 702 |
| 716 } // namespace base | 703 } // namespace base |
| 717 | 704 |
| 718 #endif // BASE_METRICS_HISTOGRAM_H_ | 705 #endif // BASE_METRICS_HISTOGRAM_H_ |
| OLD | NEW |