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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 base::TimeDelta maximum, | 389 base::TimeDelta maximum, |
390 size_t bucket_count, | 390 size_t bucket_count, |
391 int32 flags); | 391 int32 flags); |
392 | 392 |
393 // Time call for use with DHISTOGRAM*. | 393 // Time call for use with DHISTOGRAM*. |
394 // Returns TimeTicks::Now() in debug and TimeTicks() in release build. | 394 // Returns TimeTicks::Now() in debug and TimeTicks() in release build. |
395 static TimeTicks DebugNow(); | 395 static TimeTicks DebugNow(); |
396 | 396 |
397 static void InitializeBucketRanges(Sample minimum, | 397 static void InitializeBucketRanges(Sample minimum, |
398 Sample maximum, | 398 Sample maximum, |
399 size_t bucket_count, | |
400 BucketRanges* ranges); | 399 BucketRanges* ranges); |
401 | 400 |
402 // This constant if for FindCorruption. Since snapshots of histograms are | 401 // This constant if for FindCorruption. Since snapshots of histograms are |
403 // taken asynchronously relative to sampling, and our counting code currently | 402 // taken asynchronously relative to sampling, and our counting code currently |
404 // does not prevent race conditions, it is pretty likely that we'll catch a | 403 // does not prevent race conditions, it is pretty likely that we'll catch a |
405 // redundant count that doesn't match the sample count. We allow for a | 404 // redundant count that doesn't match the sample count. We allow for a |
406 // certain amount of slop before flagging this as an inconsistency. Even with | 405 // certain amount of slop before flagging this as an inconsistency. Even with |
407 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), | 406 // an inconsistency, we'll snapshot it again (for UMA in about a half hour), |
408 // so we'll eventually get the data, if it was not the result of a corruption. | 407 // so we'll eventually get the data, if it was not the result of a corruption. |
409 static const int kCommonRaceBasedCountMismatch; | 408 static const int kCommonRaceBasedCountMismatch; |
410 | 409 |
411 // Check to see if bucket ranges, counts and tallies in the snapshot are | 410 // Check to see if bucket ranges, counts and tallies in the snapshot are |
412 // consistent with the bucket ranges and checksums in our histogram. This can | 411 // consistent with the bucket ranges and checksums in our histogram. This can |
413 // produce a false-alarm if a race occurred in the reading of the data during | 412 // produce a false-alarm if a race occurred in the reading of the data during |
414 // a SnapShot process, but should otherwise be false at all times (unless we | 413 // a SnapShot process, but should otherwise be false at all times (unless we |
415 // have memory over-writes, or DRAM failures). | 414 // have memory over-writes, or DRAM failures). |
416 virtual int FindCorruption(const HistogramSamples& samples) const OVERRIDE; | 415 virtual int FindCorruption(const HistogramSamples& samples) const OVERRIDE; |
417 | 416 |
418 //---------------------------------------------------------------------------- | 417 //---------------------------------------------------------------------------- |
419 // Accessors for factory constuction, serialization and testing. | 418 // Accessors for factory constuction, serialization and testing. |
420 //---------------------------------------------------------------------------- | 419 //---------------------------------------------------------------------------- |
421 Sample declared_min() const { return declared_min_; } | 420 Sample declared_min() const { return declared_min_; } |
422 Sample declared_max() const { return declared_max_; } | 421 Sample declared_max() const { return declared_max_; } |
423 virtual Sample ranges(size_t i) const; | 422 virtual Sample ranges(size_t i) const; |
424 virtual size_t bucket_count() const; | 423 virtual size_t BucketCount() const; |
425 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } | 424 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } |
426 | 425 |
427 // This function validates histogram construction arguments. It returns false | 426 // This function validates histogram construction arguments. It returns false |
428 // if some of the arguments are totally bad. | 427 // if some of the arguments are totally bad. |
429 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently | 428 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently |
430 // converts it to good input: 1. | 429 // converts it to good input: 1. |
431 // TODO(kaiwang): Be more restrict and return false for any bad input, and | 430 // TODO(kaiwang): Be more restrict and return false for any bad input, and |
432 // make this a readonly validating function. | 431 // make this a readonly validating function. |
433 static bool InspectConstructionArguments(const std::string& name, | 432 static bool InspectConstructionArguments(const std::string& name, |
434 Sample* minimum, | 433 Sample* minimum, |
435 Sample* maximum, | 434 Sample* maximum, |
436 size_t* bucket_count); | 435 size_t* bucket_count); |
437 | 436 |
438 // HistogramBase implementation: | 437 // HistogramBase implementation: |
439 virtual HistogramType GetHistogramType() const OVERRIDE; | 438 virtual HistogramType GetHistogramType() const OVERRIDE; |
440 virtual bool HasConstructionArguments(Sample minimum, | 439 virtual bool HasConstructionArguments(Sample minimum, |
441 Sample maximum, | 440 Sample maximum, |
442 size_t bucket_count) const OVERRIDE; | 441 size_t bucket_count) const OVERRIDE; |
443 virtual void Add(Sample value) OVERRIDE; | 442 virtual void Add(Sample value) OVERRIDE; |
444 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; | 443 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; |
445 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE; | 444 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE; |
446 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE; | 445 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE; |
447 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; | 446 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; |
448 virtual void WriteAscii(std::string* output) const OVERRIDE; | 447 virtual void WriteAscii(std::string* output) const OVERRIDE; |
449 | 448 |
450 protected: | 449 protected: |
451 // |bucket_count| and |ranges| should contain the underflow and overflow | 450 // |ranges| should contain the underflow and overflow buckets. See top |
452 // buckets. See top comments for example. | 451 // comments for example. |
453 Histogram(const std::string& name, | 452 Histogram(const std::string& name, |
454 Sample minimum, | 453 Sample minimum, |
455 Sample maximum, | 454 Sample maximum, |
456 size_t bucket_count, | |
457 const BucketRanges* ranges); | 455 const BucketRanges* ranges); |
458 | 456 |
459 virtual ~Histogram(); | 457 virtual ~Histogram(); |
460 | 458 |
461 // HistogramBase implementation: | 459 // HistogramBase implementation: |
462 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; | 460 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; |
463 | 461 |
464 // Method to override to skip the display of the i'th bucket if it's empty. | 462 // Method to override to skip the display of the i'th bucket if it's empty. |
465 virtual bool PrintEmptyBucket(size_t index) const; | 463 virtual bool PrintEmptyBucket(size_t index) const; |
466 | 464 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // WriteJSON calls these. | 512 // WriteJSON calls these. |
515 virtual void GetParameters(DictionaryValue* params) const OVERRIDE; | 513 virtual void GetParameters(DictionaryValue* params) const OVERRIDE; |
516 | 514 |
517 virtual void GetCountAndBucketData(Count* count, | 515 virtual void GetCountAndBucketData(Count* count, |
518 int64* sum, | 516 int64* sum, |
519 ListValue* buckets) const OVERRIDE; | 517 ListValue* buckets) const OVERRIDE; |
520 | 518 |
521 // Does not own this object. Should get from StatisticsRecorder. | 519 // Does not own this object. Should get from StatisticsRecorder. |
522 const BucketRanges* bucket_ranges_; | 520 const BucketRanges* bucket_ranges_; |
523 | 521 |
524 Sample declared_min_; // Less than this goes into counts_[0] | 522 Sample declared_min_; // Less than this goes into the first bucket. |
525 Sample declared_max_; // Over this goes into counts_[bucket_count_ - 1]. | 523 Sample declared_max_; // Over this goes into the last bucket. |
526 size_t bucket_count_; // Dimension of counts_[]. | |
527 | 524 |
528 // Finally, provide the state that changes with the addition of each new | 525 // Finally, provide the state that changes with the addition of each new |
529 // sample. | 526 // sample. |
530 scoped_ptr<SampleVector> samples_; | 527 scoped_ptr<SampleVector> samples_; |
531 | 528 |
532 DISALLOW_COPY_AND_ASSIGN(Histogram); | 529 DISALLOW_COPY_AND_ASSIGN(Histogram); |
533 }; | 530 }; |
534 | 531 |
535 //------------------------------------------------------------------------------ | 532 //------------------------------------------------------------------------------ |
536 | 533 |
(...skipping 29 matching lines...) Expand all Loading... |
566 static HistogramBase* FactoryGetWithRangeDescription( | 563 static HistogramBase* FactoryGetWithRangeDescription( |
567 const std::string& name, | 564 const std::string& name, |
568 Sample minimum, | 565 Sample minimum, |
569 Sample maximum, | 566 Sample maximum, |
570 size_t bucket_count, | 567 size_t bucket_count, |
571 int32 flags, | 568 int32 flags, |
572 const DescriptionPair descriptions[]); | 569 const DescriptionPair descriptions[]); |
573 | 570 |
574 static void InitializeBucketRanges(Sample minimum, | 571 static void InitializeBucketRanges(Sample minimum, |
575 Sample maximum, | 572 Sample maximum, |
576 size_t bucket_count, | |
577 BucketRanges* ranges); | 573 BucketRanges* ranges); |
578 | 574 |
579 // Overridden from Histogram: | 575 // Overridden from Histogram: |
580 virtual HistogramType GetHistogramType() const OVERRIDE; | 576 virtual HistogramType GetHistogramType() const OVERRIDE; |
581 | 577 |
582 protected: | 578 protected: |
583 LinearHistogram(const std::string& name, | 579 LinearHistogram(const std::string& name, |
584 Sample minimum, | 580 Sample minimum, |
585 Sample maximum, | 581 Sample maximum, |
586 size_t bucket_count, | |
587 const BucketRanges* ranges); | 582 const BucketRanges* ranges); |
588 | 583 |
589 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; | 584 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; |
590 | 585 |
591 // If we have a description for a bucket, then return that. Otherwise | 586 // If we have a description for a bucket, then return that. Otherwise |
592 // let parent class provide a (numeric) description. | 587 // let parent class provide a (numeric) description. |
593 virtual const std::string GetAsciiBucketRange(size_t i) const OVERRIDE; | 588 virtual const std::string GetAsciiBucketRange(size_t i) const OVERRIDE; |
594 | 589 |
595 // Skip printing of name for numeric range if we have a name (and if this is | 590 // Skip printing of name for numeric range if we have a name (and if this is |
596 // an empty bucket). | 591 // an empty bucket). |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 665 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
671 static BucketRanges* CreateBucketRangesFromCustomRanges( | 666 static BucketRanges* CreateBucketRangesFromCustomRanges( |
672 const std::vector<Sample>& custom_ranges); | 667 const std::vector<Sample>& custom_ranges); |
673 | 668 |
674 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 669 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
675 }; | 670 }; |
676 | 671 |
677 } // namespace base | 672 } // namespace base |
678 | 673 |
679 #endif // BASE_METRICS_HISTOGRAM_H_ | 674 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |