OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // default underflow bucket. | 312 // default underflow bucket. |
313 static scoped_refptr<Histogram> FactoryGet(const std::string& name, | 313 static scoped_refptr<Histogram> FactoryGet(const std::string& name, |
314 Sample minimum, Sample maximum, size_t bucket_count, Flags flags); | 314 Sample minimum, Sample maximum, size_t bucket_count, Flags flags); |
315 static scoped_refptr<Histogram> FactoryTimeGet(const std::string& name, | 315 static scoped_refptr<Histogram> FactoryTimeGet(const std::string& name, |
316 base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count, | 316 base::TimeDelta minimum, base::TimeDelta maximum, size_t bucket_count, |
317 Flags flags); | 317 Flags flags); |
318 | 318 |
319 void Add(int value); | 319 void Add(int value); |
320 | 320 |
321 // This method is an interface, used only by BooleanHistogram. | 321 // This method is an interface, used only by BooleanHistogram. |
322 virtual void AddBoolean(bool value) { DCHECK(false); } | 322 virtual void AddBoolean(bool value); |
323 | 323 |
324 // Accept a TimeDelta to increment. | 324 // Accept a TimeDelta to increment. |
325 void AddTime(base::TimeDelta time) { | 325 void AddTime(base::TimeDelta time) { |
326 Add(static_cast<int>(time.InMilliseconds())); | 326 Add(static_cast<int>(time.InMilliseconds())); |
327 } | 327 } |
328 | 328 |
329 void AddSampleSet(const SampleSet& sample); | 329 void AddSampleSet(const SampleSet& sample); |
330 | 330 |
331 // This method is an interface, used only by LinearHistogram. | 331 // This method is an interface, used only by LinearHistogram. |
332 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]) | 332 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); |
333 { DCHECK(false); } | |
334 | 333 |
335 // The following methods provide graphical histogram displays. | 334 // The following methods provide graphical histogram displays. |
336 void WriteHTMLGraph(std::string* output) const; | 335 void WriteHTMLGraph(std::string* output) const; |
337 void WriteAscii(bool graph_it, const std::string& newline, | 336 void WriteAscii(bool graph_it, const std::string& newline, |
338 std::string* output) const; | 337 std::string* output) const; |
339 | 338 |
340 // Support generic flagging of Histograms. | 339 // Support generic flagging of Histograms. |
341 // 0x1 Currently used to mark this histogram to be recorded by UMA.. | 340 // 0x1 Currently used to mark this histogram to be recorded by UMA.. |
342 // 0x8000 means print ranges in hex. | 341 // 0x8000 means print ranges in hex. |
343 void SetFlags(Flags flags) { flags_ = static_cast<Flags> (flags_ | flags); } | 342 void SetFlags(Flags flags) { flags_ = static_cast<Flags> (flags_ | flags); } |
(...skipping 22 matching lines...) Expand all Loading... |
366 const std::string& histogram_name() const { return histogram_name_; } | 365 const std::string& histogram_name() const { return histogram_name_; } |
367 Sample declared_min() const { return declared_min_; } | 366 Sample declared_min() const { return declared_min_; } |
368 Sample declared_max() const { return declared_max_; } | 367 Sample declared_max() const { return declared_max_; } |
369 virtual Sample ranges(size_t i) const { return ranges_[i];} | 368 virtual Sample ranges(size_t i) const { return ranges_[i];} |
370 virtual size_t bucket_count() const { return bucket_count_; } | 369 virtual size_t bucket_count() const { return bucket_count_; } |
371 // Snapshot the current complete set of sample data. | 370 // Snapshot the current complete set of sample data. |
372 // Override with atomic/locked snapshot if needed. | 371 // Override with atomic/locked snapshot if needed. |
373 virtual void SnapshotSample(SampleSet* sample) const; | 372 virtual void SnapshotSample(SampleSet* sample) const; |
374 | 373 |
375 virtual bool HasConstructorArguments(Sample minimum, Sample maximum, | 374 virtual bool HasConstructorArguments(Sample minimum, Sample maximum, |
376 size_t bucket_count) { | 375 size_t bucket_count); |
377 return ((minimum == declared_min_) && (maximum == declared_max_) && | |
378 (bucket_count == bucket_count_)); | |
379 } | |
380 | 376 |
381 virtual bool HasConstructorTimeDeltaArguments(base::TimeDelta minimum, | 377 virtual bool HasConstructorTimeDeltaArguments(base::TimeDelta minimum, |
382 base::TimeDelta maximum, size_t bucket_count) { | 378 base::TimeDelta maximum, |
383 return ((minimum.InMilliseconds() == declared_min_) && | 379 size_t bucket_count); |
384 (maximum.InMilliseconds() == declared_max_) && | |
385 (bucket_count == bucket_count_)); | |
386 } | |
387 | 380 |
388 protected: | 381 protected: |
389 friend class base::RefCountedThreadSafe<Histogram>; | 382 friend class base::RefCountedThreadSafe<Histogram>; |
390 Histogram(const std::string& name, Sample minimum, | 383 Histogram(const std::string& name, Sample minimum, |
391 Sample maximum, size_t bucket_count); | 384 Sample maximum, size_t bucket_count); |
392 Histogram(const std::string& name, base::TimeDelta minimum, | 385 Histogram(const std::string& name, base::TimeDelta minimum, |
393 base::TimeDelta maximum, size_t bucket_count); | 386 base::TimeDelta maximum, size_t bucket_count); |
394 | 387 |
395 virtual ~Histogram(); | 388 virtual ~Histogram(); |
396 | 389 |
397 // Method to override to skip the display of the i'th bucket if it's empty. | 390 // Method to override to skip the display of the i'th bucket if it's empty. |
398 virtual bool PrintEmptyBucket(size_t index) const { return true; } | 391 virtual bool PrintEmptyBucket(size_t index) const; |
399 | 392 |
400 //---------------------------------------------------------------------------- | 393 //---------------------------------------------------------------------------- |
401 // Methods to override to create histogram with different bucket widths. | 394 // Methods to override to create histogram with different bucket widths. |
402 //---------------------------------------------------------------------------- | 395 //---------------------------------------------------------------------------- |
403 // Initialize ranges_ mapping. | 396 // Initialize ranges_ mapping. |
404 virtual void InitializeBucketRange(); | 397 virtual void InitializeBucketRange(); |
405 // Find bucket to increment for sample value. | 398 // Find bucket to increment for sample value. |
406 virtual size_t BucketIndex(Sample value) const; | 399 virtual size_t BucketIndex(Sample value) const; |
407 // Get normalized size, relative to the ranges_[i]. | 400 // Get normalized size, relative to the ranges_[i]. |
408 virtual double GetBucketSize(Count current, size_t i) const; | 401 virtual double GetBucketSize(Count current, size_t i) const; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 474 |
482 DISALLOW_COPY_AND_ASSIGN(Histogram); | 475 DISALLOW_COPY_AND_ASSIGN(Histogram); |
483 }; | 476 }; |
484 | 477 |
485 //------------------------------------------------------------------------------ | 478 //------------------------------------------------------------------------------ |
486 | 479 |
487 // LinearHistogram is a more traditional histogram, with evenly spaced | 480 // LinearHistogram is a more traditional histogram, with evenly spaced |
488 // buckets. | 481 // buckets. |
489 class LinearHistogram : public Histogram { | 482 class LinearHistogram : public Histogram { |
490 public: | 483 public: |
491 virtual ClassType histogram_type() const { return LINEAR_HISTOGRAM; } | 484 virtual ClassType histogram_type() const; |
492 | 485 |
493 // Store a list of number/text values for use in rendering the histogram. | 486 // Store a list of number/text values for use in rendering the histogram. |
494 // The last element in the array has a null in its "description" slot. | 487 // The last element in the array has a null in its "description" slot. |
495 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); | 488 virtual void SetRangeDescriptions(const DescriptionPair descriptions[]); |
496 | 489 |
497 /* minimum should start from 1. 0 is as minimum is invalid. 0 is an implicit | 490 /* minimum should start from 1. 0 is as minimum is invalid. 0 is an implicit |
498 default underflow bucket. */ | 491 default underflow bucket. */ |
499 static scoped_refptr<Histogram> FactoryGet(const std::string& name, | 492 static scoped_refptr<Histogram> FactoryGet(const std::string& name, |
500 Sample minimum, Sample maximum, size_t bucket_count, Flags flags); | 493 Sample minimum, Sample maximum, size_t bucket_count, Flags flags); |
501 static scoped_refptr<Histogram> FactoryTimeGet(const std::string& name, | 494 static scoped_refptr<Histogram> FactoryTimeGet(const std::string& name, |
(...skipping 30 matching lines...) Expand all Loading... |
532 }; | 525 }; |
533 | 526 |
534 //------------------------------------------------------------------------------ | 527 //------------------------------------------------------------------------------ |
535 | 528 |
536 // BooleanHistogram is a histogram for booleans. | 529 // BooleanHistogram is a histogram for booleans. |
537 class BooleanHistogram : public LinearHistogram { | 530 class BooleanHistogram : public LinearHistogram { |
538 public: | 531 public: |
539 static scoped_refptr<Histogram> FactoryGet(const std::string& name, | 532 static scoped_refptr<Histogram> FactoryGet(const std::string& name, |
540 Flags flags); | 533 Flags flags); |
541 | 534 |
542 virtual ClassType histogram_type() const { return BOOLEAN_HISTOGRAM; } | 535 virtual ClassType histogram_type() const; |
543 | 536 |
544 virtual void AddBoolean(bool value) { Add(value ? 1 : 0); } | 537 virtual void AddBoolean(bool value); |
545 | 538 |
546 private: | 539 private: |
547 explicit BooleanHistogram(const std::string& name) | 540 explicit BooleanHistogram(const std::string& name); |
548 : LinearHistogram(name, 1, 2, 3) { | |
549 } | |
550 | 541 |
551 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); | 542 DISALLOW_COPY_AND_ASSIGN(BooleanHistogram); |
552 }; | 543 }; |
553 | 544 |
554 //------------------------------------------------------------------------------ | 545 //------------------------------------------------------------------------------ |
555 | 546 |
556 // CustomHistogram is a histogram for a set of custom integers. | 547 // CustomHistogram is a histogram for a set of custom integers. |
557 class CustomHistogram : public Histogram { | 548 class CustomHistogram : public Histogram { |
558 public: | 549 public: |
559 virtual ClassType histogram_type() const { return CUSTOM_HISTOGRAM; } | 550 virtual ClassType histogram_type() const; |
560 | 551 |
561 static scoped_refptr<Histogram> FactoryGet(const std::string& name, | 552 static scoped_refptr<Histogram> FactoryGet(const std::string& name, |
562 const std::vector<int>& custom_ranges, Flags flags); | 553 const std::vector<int>& custom_ranges, Flags flags); |
563 | 554 |
564 protected: | 555 protected: |
565 CustomHistogram(const std::string& name, | 556 CustomHistogram(const std::string& name, |
566 const std::vector<int>& custom_ranges); | 557 const std::vector<int>& custom_ranges); |
567 | 558 |
568 // Initialize ranges_ mapping. | 559 // Initialize ranges_ mapping. |
569 virtual void InitializeBucketRange(); | 560 virtual void InitializeBucketRange(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // lock protects access to the above map. | 621 // lock protects access to the above map. |
631 static Lock* lock_; | 622 static Lock* lock_; |
632 | 623 |
633 // Dump all known histograms to log. | 624 // Dump all known histograms to log. |
634 static bool dump_on_exit_; | 625 static bool dump_on_exit_; |
635 | 626 |
636 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 627 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
637 }; | 628 }; |
638 | 629 |
639 #endif // BASE_HISTOGRAM_H_ | 630 #endif // BASE_HISTOGRAM_H_ |
OLD | NEW |