| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // See header file for details and examples. | 8 // See header file for details and examples. |
| 9 | 9 |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 Histogram* render_histogram = | 394 Histogram* render_histogram = |
| 395 StatisticsRecorder::GetHistogram(histogram_name); | 395 StatisticsRecorder::GetHistogram(histogram_name); |
| 396 | 396 |
| 397 if (render_histogram == NULL) { | 397 if (render_histogram == NULL) { |
| 398 if (histogram_type == EXPONENTIAL) { | 398 if (histogram_type == EXPONENTIAL) { |
| 399 render_histogram = new Histogram(histogram_name.c_str(), | 399 render_histogram = new Histogram(histogram_name.c_str(), |
| 400 declared_min, | 400 declared_min, |
| 401 declared_max, | 401 declared_max, |
| 402 bucket_count); | 402 bucket_count); |
| 403 } else if (histogram_type == LINEAR) { | 403 } else if (histogram_type == LINEAR) { |
| 404 render_histogram = reinterpret_cast<Histogram*> | 404 render_histogram = new LinearHistogram(histogram_name.c_str(), |
| 405 (new LinearHistogram(histogram_name.c_str(), | 405 declared_min, |
| 406 declared_min, | 406 declared_max, |
| 407 declared_max, | 407 bucket_count); |
| 408 bucket_count)); | |
| 409 } else { | 408 } else { |
| 410 LOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " << | 409 LOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: " << |
| 411 histogram_type; | 410 histogram_type; |
| 412 return false; | 411 return false; |
| 413 } | 412 } |
| 414 DCHECK(!(flags & kRendererHistogramFlag)); | 413 DCHECK(!(flags & kRendererHistogramFlag)); |
| 415 render_histogram->SetFlags(flags | kRendererHistogramFlag); | 414 render_histogram->SetFlags(flags | kRendererHistogramFlag); |
| 416 } | 415 } |
| 417 | 416 |
| 418 DCHECK(declared_min == render_histogram->declared_min()); | 417 DCHECK(declared_min == render_histogram->declared_min()); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 double min = declared_min(); | 576 double min = declared_min(); |
| 578 double max = declared_max(); | 577 double max = declared_max(); |
| 579 size_t i; | 578 size_t i; |
| 580 for (i = 1; i < bucket_count(); ++i) { | 579 for (i = 1; i < bucket_count(); ++i) { |
| 581 double linear_range = (min * (bucket_count() -1 - i) + max * (i - 1)) / | 580 double linear_range = (min * (bucket_count() -1 - i) + max * (i - 1)) / |
| 582 (bucket_count() - 2); | 581 (bucket_count() - 2); |
| 583 SetBucketRange(i, static_cast<int> (linear_range + 0.5)); | 582 SetBucketRange(i, static_cast<int> (linear_range + 0.5)); |
| 584 } | 583 } |
| 585 } | 584 } |
| 586 | 585 |
| 587 // Find bucket to increment for sample value. | |
| 588 size_t LinearHistogram::BucketIndex(Sample value) const { | |
| 589 if (value < declared_min()) return 0; | |
| 590 if (value >= declared_max()) return bucket_count() - 1; | |
| 591 size_t index; | |
| 592 index = static_cast<size_t>(((value - declared_min()) * (bucket_count() - 2)) | |
| 593 / (declared_max() - declared_min()) + 1); | |
| 594 DCHECK(1 <= index && bucket_count() > index); | |
| 595 return index; | |
| 596 } | |
| 597 | |
| 598 double LinearHistogram::GetBucketSize(Count current, size_t i) const { | 586 double LinearHistogram::GetBucketSize(Count current, size_t i) const { |
| 599 DCHECK(ranges(i + 1) > ranges(i)); | 587 DCHECK(ranges(i + 1) > ranges(i)); |
| 600 // Adjacent buckets with different widths would have "surprisingly" many (few) | 588 // Adjacent buckets with different widths would have "surprisingly" many (few) |
| 601 // samples in a histogram if we didn't normalize this way. | 589 // samples in a histogram if we didn't normalize this way. |
| 602 double denominator = ranges(i + 1) - ranges(i); | 590 double denominator = ranges(i + 1) - ranges(i); |
| 603 return current/denominator; | 591 return current/denominator; |
| 604 } | 592 } |
| 605 | 593 |
| 606 //------------------------------------------------------------------------------ | 594 //------------------------------------------------------------------------------ |
| 607 // This section provides implementation for ThreadSafeHistogram. | 595 // This section provides implementation for ThreadSafeHistogram. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 return NULL != histograms_; | 654 return NULL != histograms_; |
| 667 } | 655 } |
| 668 | 656 |
| 669 // static | 657 // static |
| 670 bool StatisticsRecorder::Register(Histogram* histogram) { | 658 bool StatisticsRecorder::Register(Histogram* histogram) { |
| 671 if (!histograms_) | 659 if (!histograms_) |
| 672 return false; | 660 return false; |
| 673 const std::string name = histogram->histogram_name(); | 661 const std::string name = histogram->histogram_name(); |
| 674 AutoLock auto_lock(*lock_); | 662 AutoLock auto_lock(*lock_); |
| 675 | 663 |
| 676 DCHECK(histograms_->end() == histograms_->find(name)) << name << " is already" | 664 if (histograms_->end() != histograms_->find(name)) { |
| 677 "registered as a histogram. Check for duplicate use of the name, or a " | 665 // Check to be sure it is compatible.... and if not, then do a CHECK() |
| 678 "race where a static initializer could be run by several threads."; | 666 return false; // This name is already registered. |
| 667 } |
| 679 (*histograms_)[name] = histogram; | 668 (*histograms_)[name] = histogram; |
| 680 return true; | 669 return true; |
| 681 } | 670 } |
| 682 | 671 |
| 683 // static | 672 // static |
| 684 void StatisticsRecorder::UnRegister(Histogram* histogram) { | 673 void StatisticsRecorder::UnRegister(Histogram* histogram) { |
| 685 if (!histograms_) | 674 if (!histograms_) |
| 686 return; | 675 return; |
| 687 const std::string name = histogram->histogram_name(); | 676 const std::string name = histogram->histogram_name(); |
| 688 AutoLock auto_lock(*lock_); | 677 AutoLock auto_lock(*lock_); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 snapshot->push_back(it->second); | 764 snapshot->push_back(it->second); |
| 776 } | 765 } |
| 777 } | 766 } |
| 778 | 767 |
| 779 // static | 768 // static |
| 780 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 769 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
| 781 // static | 770 // static |
| 782 Lock* StatisticsRecorder::lock_ = NULL; | 771 Lock* StatisticsRecorder::lock_ = NULL; |
| 783 // static | 772 // static |
| 784 bool StatisticsRecorder::dump_on_exit_ = false; | 773 bool StatisticsRecorder::dump_on_exit_ = false; |
| OLD | NEW |