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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 409 |
410 // Time call for use with DHISTOGRAM*. | 410 // Time call for use with DHISTOGRAM*. |
411 // Returns TimeTicks::Now() in debug and TimeTicks() in release build. | 411 // Returns TimeTicks::Now() in debug and TimeTicks() in release build. |
412 static TimeTicks DebugNow(); | 412 static TimeTicks DebugNow(); |
413 | 413 |
414 static void InitializeBucketRanges(Sample minimum, | 414 static void InitializeBucketRanges(Sample minimum, |
415 Sample maximum, | 415 Sample maximum, |
416 size_t bucket_count, | 416 size_t bucket_count, |
417 BucketRanges* ranges); | 417 BucketRanges* ranges); |
418 | 418 |
419 virtual void Add(Sample value) OVERRIDE; | |
420 | |
421 // This method is an interface, used only by BooleanHistogram. | 419 // This method is an interface, used only by BooleanHistogram. |
422 virtual void AddBoolean(bool value); | 420 virtual void AddBoolean(bool value); |
423 | 421 |
424 // Accept a TimeDelta to increment. | 422 // Accept a TimeDelta to increment. |
425 void AddTime(TimeDelta time) { | 423 void AddTime(TimeDelta time) { |
426 Add(static_cast<int>(time.InMilliseconds())); | 424 Add(static_cast<int>(time.InMilliseconds())); |
427 } | 425 } |
428 | 426 |
429 void AddSamples(const HistogramSamples& samples); | 427 void AddSamples(const HistogramSamples& samples); |
430 bool AddSamplesFromPickle(PickleIterator* iter); | 428 bool AddSamplesFromPickle(PickleIterator* iter); |
431 | 429 |
432 // This method is an interface, used only by LinearHistogram. | 430 // This method is an interface, used only by LinearHistogram. |
433 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); | 431 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); |
434 | 432 |
435 // The following methods provide graphical histogram displays. | |
436 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; | |
437 virtual void WriteAscii(std::string* output) const OVERRIDE; | |
438 | |
439 // Convenience methods for serializing/deserializing the histograms. | 433 // Convenience methods for serializing/deserializing the histograms. |
440 // Histograms from Renderer process are serialized and sent to the browser. | 434 // Histograms from Renderer process are serialized and sent to the browser. |
441 // Browser process reconstructs the histogram from the pickled version | 435 // Browser process reconstructs the histogram from the pickled version |
442 // accumulates the browser-side shadow copy of histograms (that mirror | 436 // accumulates the browser-side shadow copy of histograms (that mirror |
443 // histograms created in the renderer). | 437 // histograms created in the renderer). |
444 | 438 |
445 // Serialize the given snapshot of a Histogram into a String. Uses | 439 // Serialize the given snapshot of a Histogram into a String. Uses |
446 // Pickle class to flatten the object. | 440 // Pickle class to flatten the object. |
447 static std::string SerializeHistogramInfo(const Histogram& histogram, | 441 static std::string SerializeHistogramInfo(const Histogram& histogram, |
448 const HistogramSamples& snapshot); | 442 const HistogramSamples& snapshot); |
(...skipping 22 matching lines...) Expand all Loading... |
471 //---------------------------------------------------------------------------- | 465 //---------------------------------------------------------------------------- |
472 // Accessors for factory constuction, serialization and testing. | 466 // Accessors for factory constuction, serialization and testing. |
473 //---------------------------------------------------------------------------- | 467 //---------------------------------------------------------------------------- |
474 virtual ClassType histogram_type() const; | 468 virtual ClassType histogram_type() const; |
475 Sample declared_min() const { return declared_min_; } | 469 Sample declared_min() const { return declared_min_; } |
476 Sample declared_max() const { return declared_max_; } | 470 Sample declared_max() const { return declared_max_; } |
477 virtual Sample ranges(size_t i) const; | 471 virtual Sample ranges(size_t i) const; |
478 virtual size_t bucket_count() const; | 472 virtual size_t bucket_count() const; |
479 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } | 473 const BucketRanges* bucket_ranges() const { return bucket_ranges_; } |
480 | 474 |
481 // Snapshot the current complete set of sample data. | 475 // This function validates histogram construction arguments. It returns false |
482 // Override with atomic/locked snapshot if needed. | 476 // if some of the arguments are totally bad. |
483 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; | 477 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently |
| 478 // converts it to good input: 1. |
| 479 // TODO(kaiwang): Be more restrict and return false for any bad input, and |
| 480 // make this a readonly validating function. |
| 481 static bool InspectConstructionArguments(const std::string& name, |
| 482 Sample* minimum, |
| 483 Sample* maximum, |
| 484 size_t* bucket_count); |
484 | 485 |
| 486 // HistogramBase implementation: |
485 virtual bool HasConstructionArguments(Sample minimum, | 487 virtual bool HasConstructionArguments(Sample minimum, |
486 Sample maximum, | 488 Sample maximum, |
487 size_t bucket_count); | 489 size_t bucket_count) const OVERRIDE; |
| 490 virtual void Add(Sample value) OVERRIDE; |
| 491 virtual scoped_ptr<HistogramSamples> SnapshotSamples() const OVERRIDE; |
| 492 virtual void WriteHTMLGraph(std::string* output) const OVERRIDE; |
| 493 virtual void WriteAscii(std::string* output) const OVERRIDE; |
| 494 |
488 protected: | 495 protected: |
489 // |bucket_count| and |ranges| should contain the underflow and overflow | 496 // |bucket_count| and |ranges| should contain the underflow and overflow |
490 // buckets. See top comments for example. | 497 // buckets. See top comments for example. |
491 Histogram(const std::string& name, | 498 Histogram(const std::string& name, |
492 Sample minimum, | 499 Sample minimum, |
493 Sample maximum, | 500 Sample maximum, |
494 size_t bucket_count, | 501 size_t bucket_count, |
495 const BucketRanges* ranges); | 502 const BucketRanges* ranges); |
496 | 503 |
497 virtual ~Histogram(); | 504 virtual ~Histogram(); |
498 | 505 |
499 // This function validates histogram construction arguments. It returns false | |
500 // if some of the arguments are totally bad. | |
501 // Note. Currently it allow some bad input, e.g. 0 as minimum, but silently | |
502 // converts it to good input: 1. | |
503 // TODO(kaiwang): Be more restrict and return false for any bad input, and | |
504 // make this a readonly validating function. | |
505 static bool InspectConstructionArguments(const std::string& name, | |
506 Sample* minimum, | |
507 Sample* maximum, | |
508 size_t* bucket_count); | |
509 | |
510 // Serialize the histogram's ranges to |*pickle|, returning true on success. | 506 // Serialize the histogram's ranges to |*pickle|, returning true on success. |
511 // Most subclasses can leave this no-op implementation, but some will want to | 507 // Most subclasses can leave this no-op implementation, but some will want to |
512 // override it, especially if the ranges cannot be re-derived from other | 508 // override it, especially if the ranges cannot be re-derived from other |
513 // serialized parameters. | 509 // serialized parameters. |
514 virtual bool SerializeRanges(Pickle* pickle) const; | 510 virtual bool SerializeRanges(Pickle* pickle) const; |
515 | 511 |
516 // Method to override to skip the display of the i'th bucket if it's empty. | 512 // Method to override to skip the display of the i'th bucket if it's empty. |
517 virtual bool PrintEmptyBucket(size_t index) const; | 513 virtual bool PrintEmptyBucket(size_t index) const; |
518 | 514 |
519 // Get normalized size, relative to the ranges(i). | 515 // Get normalized size, relative to the ranges(i). |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); | 702 static bool ValidateCustomRanges(const std::vector<Sample>& custom_ranges); |
707 static BucketRanges* CreateBucketRangesFromCustomRanges( | 703 static BucketRanges* CreateBucketRangesFromCustomRanges( |
708 const std::vector<Sample>& custom_ranges); | 704 const std::vector<Sample>& custom_ranges); |
709 | 705 |
710 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); | 706 DISALLOW_COPY_AND_ASSIGN(CustomHistogram); |
711 }; | 707 }; |
712 | 708 |
713 } // namespace base | 709 } // namespace base |
714 | 710 |
715 #endif // BASE_METRICS_HISTOGRAM_H_ | 711 #endif // BASE_METRICS_HISTOGRAM_H_ |
OLD | NEW |