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 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 HistogramType GetHistogramType() const override; |
386 virtual bool HasConstructionArguments( | 386 bool HasConstructionArguments(Sample expected_minimum, |
387 Sample expected_minimum, | 387 Sample expected_maximum, |
388 Sample expected_maximum, | 388 size_t expected_bucket_count) const override; |
389 size_t expected_bucket_count) const OVERRIDE; | 389 void Add(Sample value) override; |
390 virtual void Add(Sample value) OVERRIDE; | 390 scoped_ptr<HistogramSamples> SnapshotSamples() const override; |
391 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; | 391 void AddSamples(const HistogramSamples& samples) override; |
392 virtual void AddSamples(const HistogramSamples& samples) OVERRIDE; | 392 bool AddSamplesFromPickle(PickleIterator* iter) override; |
393 virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE; | 393 void WriteHTMLGraph(std::string* output) const override; |
394 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; | 394 void WriteAscii(std::string* output) const override; |
395 virtual void WriteAscii(std::string* output) const OVERRIDE; | |
396 | 395 |
397 protected: | 396 protected: |
398 // |ranges| should contain the underflow and overflow buckets. See top | 397 // |ranges| should contain the underflow and overflow buckets. See top |
399 // comments for example. | 398 // comments for example. |
400 Histogram(const std::string& name, | 399 Histogram(const std::string& name, |
401 Sample minimum, | 400 Sample minimum, |
402 Sample maximum, | 401 Sample maximum, |
403 const BucketRanges* ranges); | 402 const BucketRanges* ranges); |
404 | 403 |
405 virtual ~Histogram(); | 404 virtual ~Histogram(); |
406 | 405 |
407 // HistogramBase implementation: | 406 // HistogramBase implementation: |
408 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; | 407 bool SerializeInfoImpl(Pickle* pickle) const override; |
409 | 408 |
410 // Method to override to skip the display of the i'th bucket if it's empty. | 409 // Method to override to skip the display of the i'th bucket if it's empty. |
411 virtual bool PrintEmptyBucket(size_t index) const; | 410 virtual bool PrintEmptyBucket(size_t index) const; |
412 | 411 |
413 // Get normalized size, relative to the ranges(i). | 412 // Get normalized size, relative to the ranges(i). |
414 virtual double GetBucketSize(Count current, size_t i) const; | 413 virtual double GetBucketSize(Count current, size_t i) const; |
415 | 414 |
416 // Return a string description of what goes in a given bucket. | 415 // 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 | 416 // Most commonly this is the numeric value, but in derived classes it may |
418 // be a name (or string description) given to the bucket. | 417 // 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, | 450 Count sample_count, |
452 std::string* output) const; | 451 std::string* output) const; |
453 | 452 |
454 // Write information about previous, current, and next buckets. | 453 // Write information about previous, current, and next buckets. |
455 // Information such as cumulative percentage, etc. | 454 // Information such as cumulative percentage, etc. |
456 void WriteAsciiBucketContext(const int64 past, const Count current, | 455 void WriteAsciiBucketContext(const int64 past, const Count current, |
457 const int64 remaining, const size_t i, | 456 const int64 remaining, const size_t i, |
458 std::string* output) const; | 457 std::string* output) const; |
459 | 458 |
460 // WriteJSON calls these. | 459 // WriteJSON calls these. |
461 virtual void GetParameters(DictionaryValue* params) const OVERRIDE; | 460 void GetParameters(DictionaryValue* params) const override; |
462 | 461 |
463 virtual void GetCountAndBucketData(Count* count, | 462 void GetCountAndBucketData(Count* count, |
464 int64* sum, | 463 int64* sum, |
465 ListValue* buckets) const OVERRIDE; | 464 ListValue* buckets) const override; |
466 | 465 |
467 // Does not own this object. Should get from StatisticsRecorder. | 466 // Does not own this object. Should get from StatisticsRecorder. |
468 const BucketRanges* bucket_ranges_; | 467 const BucketRanges* bucket_ranges_; |
469 | 468 |
470 Sample declared_min_; // Less than this goes into the first bucket. | 469 Sample declared_min_; // Less than this goes into the first bucket. |
471 Sample declared_max_; // Over this goes into the last bucket. | 470 Sample declared_max_; // Over this goes into the last bucket. |
472 | 471 |
473 // Finally, provide the state that changes with the addition of each new | 472 // Finally, provide the state that changes with the addition of each new |
474 // sample. | 473 // sample. |
475 scoped_ptr<SampleVector> samples_; | 474 scoped_ptr<SampleVector> samples_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 Sample maximum, | 513 Sample maximum, |
515 size_t bucket_count, | 514 size_t bucket_count, |
516 int32 flags, | 515 int32 flags, |
517 const DescriptionPair descriptions[]); | 516 const DescriptionPair descriptions[]); |
518 | 517 |
519 static void InitializeBucketRanges(Sample minimum, | 518 static void InitializeBucketRanges(Sample minimum, |
520 Sample maximum, | 519 Sample maximum, |
521 BucketRanges* ranges); | 520 BucketRanges* ranges); |
522 | 521 |
523 // Overridden from Histogram: | 522 // Overridden from Histogram: |
524 virtual HistogramType GetHistogramType() const OVERRIDE; | 523 HistogramType GetHistogramType() const override; |
525 | 524 |
526 protected: | 525 protected: |
527 LinearHistogram(const std::string& name, | 526 LinearHistogram(const std::string& name, |
528 Sample minimum, | 527 Sample minimum, |
529 Sample maximum, | 528 Sample maximum, |
530 const BucketRanges* ranges); | 529 const BucketRanges* ranges); |
531 | 530 |
532 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; | 531 double GetBucketSize(Count current, size_t i) const override; |
533 | 532 |
534 // If we have a description for a bucket, then return that. Otherwise | 533 // If we have a description for a bucket, then return that. Otherwise |
535 // let parent class provide a (numeric) description. | 534 // let parent class provide a (numeric) description. |
536 virtual const std::string GetAsciiBucketRange(size_t i) const OVERRIDE; | 535 const std::string GetAsciiBucketRange(size_t i) const override; |
537 | 536 |
538 // Skip printing of name for numeric range if we have a name (and if this is | 537 // Skip printing of name for numeric range if we have a name (and if this is |
539 // an empty bucket). | 538 // an empty bucket). |
540 virtual bool PrintEmptyBucket(size_t index) const OVERRIDE; | 539 bool PrintEmptyBucket(size_t index) const override; |
541 | 540 |
542 private: | 541 private: |
543 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 542 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
544 PickleIterator* iter); | 543 PickleIterator* iter); |
545 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); | 544 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); |
546 | 545 |
547 // For some ranges, we store a printable description of a bucket range. | 546 // For some ranges, we store a printable description of a bucket range. |
548 // If there is no description, then GetAsciiBucketRange() uses parent class | 547 // If there is no description, then GetAsciiBucketRange() uses parent class |
549 // to provide a description. | 548 // to provide a description. |
550 typedef std::map<Sample, std::string> BucketDescriptionMap; | 549 typedef std::map<Sample, std::string> BucketDescriptionMap; |
551 BucketDescriptionMap bucket_description_; | 550 BucketDescriptionMap bucket_description_; |
552 | 551 |
553 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); | 552 DISALLOW_COPY_AND_ASSIGN(LinearHistogram); |
554 }; | 553 }; |
555 | 554 |
556 //------------------------------------------------------------------------------ | 555 //------------------------------------------------------------------------------ |
557 | 556 |
558 // BooleanHistogram is a histogram for booleans. | 557 // BooleanHistogram is a histogram for booleans. |
559 class BASE_EXPORT BooleanHistogram : public LinearHistogram { | 558 class BASE_EXPORT BooleanHistogram : public LinearHistogram { |
560 public: | 559 public: |
561 static HistogramBase* FactoryGet(const std::string& name, int32 flags); | 560 static HistogramBase* FactoryGet(const std::string& name, int32 flags); |
562 | 561 |
563 virtual HistogramType GetHistogramType() const OVERRIDE; | 562 HistogramType GetHistogramType() const override; |
564 | 563 |
565 private: | 564 private: |
566 BooleanHistogram(const std::string& name, const BucketRanges* ranges); | 565 BooleanHistogram(const std::string& name, const BucketRanges* ranges); |
567 | 566 |
568 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 567 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
569 PickleIterator* iter); | 568 PickleIterator* iter); |
570 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); | 569 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); |
571 | 570 |
572 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 571 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
573 }; | 572 }; |
574 | 573 |
575 //------------------------------------------------------------------------------ | 574 //------------------------------------------------------------------------------ |
576 | 575 |
577 // CustomHistogram is a histogram for a set of custom integers. | 576 // CustomHistogram is a histogram for a set of custom integers. |
578 class BASE_EXPORT CustomHistogram : public Histogram { | 577 class BASE_EXPORT CustomHistogram : public Histogram { |
579 public: | 578 public: |
580 // |custom_ranges| contains a vector of limits on ranges. Each limit should be | 579 // |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 | 580 // > 0 and < kSampleType_MAX. (Currently 0 is still accepted for backward |
582 // compatibility). The limits can be unordered or contain duplication, but | 581 // compatibility). The limits can be unordered or contain duplication, but |
583 // client should not depend on this. | 582 // client should not depend on this. |
584 static HistogramBase* FactoryGet(const std::string& name, | 583 static HistogramBase* FactoryGet(const std::string& name, |
585 const std::vector<Sample>& custom_ranges, | 584 const std::vector<Sample>& custom_ranges, |
586 int32 flags); | 585 int32 flags); |
587 | 586 |
588 // Overridden from Histogram: | 587 // Overridden from Histogram: |
589 virtual HistogramType GetHistogramType() const OVERRIDE; | 588 HistogramType GetHistogramType() const override; |
590 | 589 |
591 // Helper method for transforming an array of valid enumeration values | 590 // Helper method for transforming an array of valid enumeration values |
592 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. | 591 // to the std::vector<int> expected by UMA_HISTOGRAM_CUSTOM_ENUMERATION. |
593 // This function ensures that a guard bucket exists right after any | 592 // 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), | 593 // 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. | 594 // so that invalid samples never fall into the same bucket as valid samples. |
596 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. | 595 // TODO(kaiwang): Change name to ArrayToCustomEnumRanges. |
597 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, | 596 static std::vector<Sample> ArrayToCustomRanges(const Sample* values, |
598 size_t num_values); | 597 size_t num_values); |
599 protected: | 598 protected: |
600 CustomHistogram(const std::string& name, | 599 CustomHistogram(const std::string& name, |
601 const BucketRanges* ranges); | 600 const BucketRanges* ranges); |
602 | 601 |
603 // HistogramBase implementation: | 602 // HistogramBase implementation: |
604 virtual bool SerializeInfoImpl(Pickle* pickle) const OVERRIDE; | 603 bool SerializeInfoImpl(Pickle* pickle) const override; |
605 | 604 |
606 virtual double GetBucketSize(Count current, size_t i) const OVERRIDE; | 605 double GetBucketSize(Count current, size_t i) const override; |
607 | 606 |
608 private: | 607 private: |
609 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( | 608 friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo( |
610 PickleIterator* iter); | 609 PickleIterator* iter); |
611 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); | 610 static HistogramBase* DeserializeInfoImpl(PickleIterator* iter); |
612 | 611 |
613 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 612 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
614 static BucketRanges* CreateBucketRangesFromCustomRanges( | 613 static BucketRanges* CreateBucketRangesFromCustomRanges( |
615 const std::vector<Sample>& custom_ranges); | 614 const std::vector<Sample>& custom_ranges); |
616 | 615 |
617 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 616 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
618 }; | 617 }; |
619 | 618 |
620 } // namespace base | 619 } // namespace base |
621 | 620 |
622 #endif // BASE_METRICS_HISTOGRAM_H_ | 621 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |