| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // certain amount of slop before flagging this as an inconsistency. Even with | 352 // certain amount of slop before flagging this as an inconsistency. Even with |
| 353 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), | 353 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), |
| 354 // so we'll eventually get the data, if it was not the result of a corruption. | 354 // so we'll eventually get the data, if it was not the result of a corruption. |
| 355 static const int kCommonRaceBasedCountMismatch; | 355 static const int kCommonRaceBasedCountMismatch; |
| 356 | 356 |
| 357 // Check to see if bucket ranges, counts and tallies in the snapshot are | 357 // Check to see if bucket ranges, counts and tallies in the snapshot are |
| 358 // consistent with the bucket ranges and checksums in our histogram. This can | 358 // consistent with the bucket ranges and checksums in our histogram. This can |
| 359 // produce a false-alarm if a race occurred in the reading of the data during | 359 // produce a false-alarm if a race occurred in the reading of the data during |
| 360 // a SnapShot process, but should otherwise be false at all times (unless we | 360 // a SnapShot process, but should otherwise be false at all times (unless we |
| 361 // have memory over-writes, or DRAM failures). | 361 // have memory over-writes, or DRAM failures). |
| 362 virtual int FindCorruption(const HistogramSamples& samples) const OVERRIDE; | 362 virtual int FindCorruption(const HistogramSamples& samples) const override; |
| 363 | 363 |
| 364 //---------------------------------------------------------------------------- | 364 //---------------------------------------------------------------------------- |
| 365 // Accessors for factory construction, serialization and testing. | 365 // Accessors for factory construction, serialization and testing. |
| 366 //---------------------------------------------------------------------------- | 366 //---------------------------------------------------------------------------- |
| 367 Sample declared_min() const { return declared_min_; } | 367 Sample declared_min() const { return declared_min_; } |
| 368 Sample declared_max() const { return declared_max_; } | 368 Sample declared_max() const { return declared_max_; } |
| 369 virtual Sample ranges(size_t i) const; | 369 virtual Sample ranges(size_t i) const; |
| 370 virtual size_t bucket_count() const; | 370 virtual size_t bucket_count() const; |
| 371 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } | 371 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } |
| 372 | 372 |
| 373 // This function validates histogram construction arguments. It returns false | 373 // This function validates histogram construction arguments. It returns false |
| 374 // if some of the arguments are totally bad. | 374 // if some of the arguments are totally bad. |
| 375 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently | 375 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently |
| 376 // converts it to good input: 1. | 376 // converts it to good input: 1. |
| 377 // TODO(kaiwang): Be more restrict and return false for any bad input, and | 377 // TODO(kaiwang): Be more restrict and return false for any bad input, and |
| 378 // make this a readonly validating function. | 378 // make this a readonly validating function. |
| 379 static bool InspectConstructionArguments(const std::string& name, | 379 static bool InspectConstructionArguments(const std::string& name, |
| 380 Sample* minimum, | 380 Sample* minimum, |
| 381 Sample* maximum, | 381 Sample* maximum, |
| 382 size_t* bucket_count); | 382 size_t* bucket_count); |
| 383 | 383 |
| 384 // HistogramBase implementation: | 384 // HistogramBase implementation: |
| 385 virtual HistogramType GetHistogramType() const OVERRIDE; | 385 virtual HistogramType GetHistogramType() const override; |
| 386 virtual bool HasConstructionArguments( | 386 virtual bool HasConstructionArguments( |
| 387 Sample expected_minimum, | 387 Sample expected_minimum, |
| 388 Sample expected_maximum, | 388 Sample expected_maximum, |
| 389 size_t expected_bucket_count) const OVERRIDE; | 389 size_t expected_bucket_count) const override; |
| 390 virtual void Add(Sample value) OVERRIDE; | 390 virtual void Add(Sample value) override; |
| 391 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; | 391 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const override; |
| 392 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE; | 392 virtual void AddSamples(const HistogramSamples& samples) override; |
| 393 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE; | 393 virtual bool AddSamplesFromPickle(PickleIterator* iter) override; |
| 394 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; | 394 virtual void WriteHTMLGraph(std::string* output) const override; |
| 395 virtual void WriteAscii(std::string* output) const OVERRIDE; | 395 virtual void WriteAscii(std::string* output) const override; |
| 396 | 396 |
| 397 protected: | 397 protected: |
| 398 // |ranges| should contain the underflow and overflow buckets. See top | 398 // |ranges| should contain the underflow and overflow buckets. See top |
| 399 // comments for example. | 399 // comments for example. |
| 400 Histogram(const std::string& name, | 400 Histogram(const std::string& name, |
| 401 Sample minimum, | 401 Sample minimum, |
| 402 Sample maximum, | 402 Sample maximum, |
| 403 const BucketRanges* ranges); | 403 const BucketRanges* ranges); |
| 404 | 404 |
| 405 virtual ~Histogram(); | 405 virtual ~Histogram(); |
| 406 | 406 |
| 407 // HistogramBase implementation: | 407 // HistogramBase implementation: |
| 408 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; | 408 virtual bool SerializeInfoImpl(Pickle* pickle) const override; |
| 409 | 409 |
| 410 // Method to override to skip the display of the i'th bucket if it's empty. | 410 // Method to override to skip the display of the i'th bucket if it's empty. |
| 411 virtual bool PrintEmptyBucket(size_t index) const; | 411 virtual bool PrintEmptyBucket(size_t index) const; |
| 412 | 412 |
| 413 // Get normalized size, relative to the ranges(i). | 413 // Get normalized size, relative to the ranges(i). |
| 414 virtual double GetBucketSize(Count current, size_t i) const; | 414 virtual double GetBucketSize(Count current, size_t i) const; |
| 415 | 415 |
| 416 // Return a string description of what goes in a given bucket. | 416 // Return a string description of what goes in a given bucket. |
| 417 // Most commonly this is the numeric value, but in derived classes it may | 417 // Most commonly this is the numeric value, but in derived classes it may |
| 418 // be a name (or string description) given to the bucket. | 418 // be a name (or string description) given to the bucket. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 Count sample_count, | 451 Count sample_count, |
| 452 std::string* output) const; | 452 std::string* output) const; |
| 453 | 453 |
| 454 // Write information about previous, current, and next buckets. | 454 // Write information about previous, current, and next buckets. |
| 455 // Information such as cumulative percentage, etc. | 455 // Information such as cumulative percentage, etc. |
| 456 void WriteAsciiBucketContext(const int64 past, const Count current, | 456 void WriteAsciiBucketContext(const int64 past, const Count current, |
| 457 const int64 remaining, const size_t i, | 457 const int64 remaining, const size_t i, |
| 458 std::string* output) const; | 458 std::string* output) const; |
| 459 | 459 |
| 460 // WriteJSON calls these. | 460 // WriteJSON calls these. |
| 461 virtual void GetParameters(DictionaryValue* params) const OVERRIDE; | 461 virtual void GetParameters(DictionaryValue* params) const override; |
| 462 | 462 |
| 463 virtual void GetCountAndBucketData(Count* count, | 463 virtual void GetCountAndBucketData(Count* count, |
| 464 int64* sum, | 464 int64* sum, |
| 465 ListValue* buckets) const OVERRIDE; | 465 ListValue* buckets) const override; |
| 466 | 466 |
| 467 // Does not own this object. Should get from StatisticsRecorder. | 467 // Does not own this object. Should get from StatisticsRecorder. |
| 468 const BucketRanges* bucket_ranges_; | 468 const BucketRanges* bucket_ranges_; |
| 469 | 469 |
| 470 Sample declared_min_; // Less than this goes into the first bucket. | 470 Sample declared_min_; // Less than this goes into the first bucket. |
| 471 Sample declared_max_; // Over this goes into the last bucket. | 471 Sample declared_max_; // Over this goes into the last bucket. |
| 472 | 472 |
| 473 // Finally, provide the state that changes with the addition of each new | 473 // Finally, provide the state that changes with the addition of each new |
| 474 // sample. | 474 // sample. |
| 475 scoped_ptr<SampleVector> samples_; | 475 scoped_ptr<SampleVector> samples_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 Sample maximum, | 514 Sample maximum, |
| 515 size_t bucket_count, | 515 size_t bucket_count, |
| 516 int32 flags, | 516 int32 flags, |
| 517 const DescriptionPair descriptions[]); | 517 const DescriptionPair descriptions[]); |
| 518 | 518 |
| 519 static void InitializeBucketRanges(Sample minimum, | 519 static void InitializeBucketRanges(Sample minimum, |
| 520 Sample maximum, | 520 Sample maximum, |
| 521 BucketRanges* ranges); | 521 BucketRanges* ranges); |
| 522 | 522 |
| 523 // Overridden from Histogram: | 523 // Overridden from Histogram: |
| 524 virtual HistogramType GetHistogramType() const OVERRIDE; | 524 virtual HistogramType GetHistogramType() const override; |
| 525 | 525 |
| 526 protected: | 526 protected: |
| 527 LinearHistogram(const std::string& name, | 527 LinearHistogram(const std::string& name, |
| 528 Sample minimum, | 528 Sample minimum, |
| 529 Sample maximum, | 529 Sample maximum, |
| 530 const BucketRanges* ranges); | 530 const BucketRanges* ranges); |
| 531 | 531 |
| 532 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; | 532 virtual double GetBucketSize(Count current, size_t i) const override; |
| 533 | 533 |
| 534 // If we have a description for a bucket, then return that. Otherwise | 534 // If we have a description for a bucket, then return that. Otherwise |
| 535 // let parent class provide a (numeric) description. | 535 // let parent class provide a (numeric) description. |
| 536 virtual const std::string GetAsciiBucketRange(size_t i) const OVERRIDE; | 536 virtual const std::string GetAsciiBucketRange(size_t i) const override; |
| 537 | 537 |
| 538 // Skip printing of name for numeric range if we have a name (and if this is | 538 // Skip printing of name for numeric range if we have a name (and if this is |
| 539 // an empty bucket). | 539 // an empty bucket). |
| 540 virtual bool PrintEmptyBucket(size_t index) const OVERRIDE; | 540 virtual bool PrintEmptyBucket(size_t index) const override; |
| 541 | 541 |
| 542 private: | 542 private: |
| 543 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 543 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
| 544 PickleIterator* iter); | 544 PickleIterator* iter); |
| 545 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); | 545 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); |
| 546 | 546 |
| 547 // For some ranges, we store a printable description of a bucket range. | 547 // For some ranges, we store a printable description of a bucket range. |
| 548 // If there is no description, then GetAsciiBucketRange() uses parent class | 548 // If there is no description, then GetAsciiBucketRange() uses parent class |
| 549 // to provide a description. | 549 // to provide a description. |
| 550 typedef std::map<Sample, std::string> BucketDescriptionMap; | 550 typedef std::map<Sample, std::string> BucketDescriptionMap; |
| 551 BucketDescriptionMap bucket_description_; | 551 BucketDescriptionMap bucket_description_; |
| 552 | 552 |
| 553 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); | 553 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); |
| 554 }; | 554 }; |
| 555 | 555 |
| 556 //------------------------------------------------------------------------------ | 556 //------------------------------------------------------------------------------ |
| 557 | 557 |
| 558 // BooleanHistogram is a histogram for booleans. | 558 // BooleanHistogram is a histogram for booleans. |
| 559 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 559 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
| 560 public: | 560 public: |
| 561 static HistogramBase* FactoryGet(const std::string& name, int32 flags); | 561 static HistogramBase* FactoryGet(const std::string& name, int32 flags); |
| 562 | 562 |
| 563 virtual HistogramType GetHistogramType() const OVERRIDE; | 563 virtual HistogramType GetHistogramType() const override; |
| 564 | 564 |
| 565 private: | 565 private: |
| 566 BooleanHistogram(const std::string& name, const BucketRanges* ranges); | 566 BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
| 567 | 567 |
| 568 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 568 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
| 569 PickleIterator* iter); | 569 PickleIterator* iter); |
| 570 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); | 570 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); |
| 571 | 571 |
| 572 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 572 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
| 573 }; | 573 }; |
| 574 | 574 |
| 575 //------------------------------------------------------------------------------ | 575 //------------------------------------------------------------------------------ |
| 576 | 576 |
| 577 // CustomHistogram is a histogram for a set of custom integers. | 577 // CustomHistogram is a histogram for a set of custom integers. |
| 578 class BASE_EXPORT CustomHistogram : public Histogram { | 578 class BASE_EXPORT CustomHistogram : public Histogram { |
| 579 public: | 579 public: |
| 580 // |custom_ranges| contains a vector of limits on ranges. Each limit should be | 580 // |custom_ranges| contains a vector of limits on ranges. Each limit should be |
| 581 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward | 581 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward |
| 582 // compatibility). The limits can be unordered or contain duplication, but | 582 // compatibility). The limits can be unordered or contain duplication, but |
| 583 // client should not depend on this. | 583 // client should not depend on this. |
| 584 static HistogramBase* FactoryGet(const std::string& name, | 584 static HistogramBase* FactoryGet(const std::string& name, |
| 585 const std::vector<Sample>& custom_ranges, | 585 const std::vector<Sample>& custom_ranges, |
| 586 int32 flags); | 586 int32 flags); |
| 587 | 587 |
| 588 // Overridden from Histogram: | 588 // Overridden from Histogram: |
| 589 virtual HistogramType GetHistogramType() const OVERRIDE; | 589 virtual HistogramType GetHistogramType() const override; |
| 590 | 590 |
| 591 // Helper method for transforming an array of valid enumeration values | 591 // Helper method for transforming an array of valid enumeration values |
| 592 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. | 592 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. |
| 593 // This function ensures that a guard bucket exists right after any | 593 // This function ensures that a guard bucket exists right after any |
| 594 // valid sample value (unless the next higher sample is also a valid value), | 594 // valid sample value (unless the next higher sample is also a valid value), |
| 595 // so that invalid samples never fall into the same bucket as valid samples. | 595 // so that invalid samples never fall into the same bucket as valid samples. |
| 596 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. | 596 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. |
| 597 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 597 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
| 598 size_t num_values); | 598 size_t num_values); |
| 599 protected: | 599 protected: |
| 600 CustomHistogram(const std::string& name, | 600 CustomHistogram(const std::string& name, |
| 601 const BucketRanges* ranges); | 601 const BucketRanges* ranges); |
| 602 | 602 |
| 603 // HistogramBase implementation: | 603 // HistogramBase implementation: |
| 604 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; | 604 virtual bool SerializeInfoImpl(Pickle* pickle) const override; |
| 605 | 605 |
| 606 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; | 606 virtual double GetBucketSize(Count current, size_t i) const override; |
| 607 | 607 |
| 608 private: | 608 private: |
| 609 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 609 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
| 610 PickleIterator* iter); | 610 PickleIterator* iter); |
| 611 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); | 611 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); |
| 612 | 612 |
| 613 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 613 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
| 614 static BucketRanges* CreateBucketRangesFromCustomRanges( | 614 static BucketRanges* CreateBucketRangesFromCustomRanges( |
| 615 const std::vector<Sample>& custom_ranges); | 615 const std::vector<Sample>& custom_ranges); |
| 616 | 616 |
| 617 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 617 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
| 618 }; | 618 }; |
| 619 | 619 |
| 620 } // namespace base | 620 } // namespace base |
| 621 | 621 |
| 622 #endif // BASE_METRICS_HISTOGRAM_H_ | 622 #endif // BASE_METRICS_HISTOGRAM_H_ |
| OLD | NEW |