| Index: base/histogram.cc
|
| ===================================================================
|
| --- base/histogram.cc (revision 45775)
|
| +++ base/histogram.cc (working copy)
|
| @@ -180,7 +180,7 @@
|
| bool Histogram::ValidateBucketRanges() const {
|
| // Standard assertions that all bucket ranges should satisfy.
|
| DCHECK(ranges_.size() == bucket_count_ + 1);
|
| - DCHECK_EQ(0, ranges_[0]);
|
| + DCHECK_EQ(ranges_[0], 0);
|
| DCHECK(declared_min() == ranges_[1]);
|
| DCHECK(declared_max() == ranges_[bucket_count_ - 1]);
|
| DCHECK(kSampleType_MAX == ranges_[bucket_count_]);
|
| @@ -194,10 +194,10 @@
|
| if (declared_max_ >= kSampleType_MAX)
|
| declared_max_ = kSampleType_MAX - 1;
|
| DCHECK(declared_min_ <= declared_max_);
|
| - DCHECK_LT(1u, bucket_count_);
|
| + DCHECK_GT(bucket_count_, 1u);
|
| size_t maximal_bucket_count = declared_max_ - declared_min_ + 2;
|
| DCHECK(bucket_count_ <= maximal_bucket_count);
|
| - DCHECK_EQ(0, ranges_[0]);
|
| + DCHECK_EQ(ranges_[0], 0);
|
| ranges_[bucket_count_] = kSampleType_MAX;
|
| InitializeBucketRange();
|
| DCHECK(ValidateBucketRanges());
|
| @@ -325,7 +325,7 @@
|
| histogram_name().c_str(),
|
| sample_count);
|
| if (0 == sample_count) {
|
| - DCHECK_EQ(0, snapshot.sum());
|
| + DCHECK_EQ(snapshot.sum(), 0);
|
| } else {
|
| double average = static_cast<float>(snapshot.sum()) / sample_count;
|
| double variance = static_cast<float>(snapshot.square_sum())/sample_count
|
| @@ -646,7 +646,7 @@
|
|
|
|
|
| void LinearHistogram::InitializeBucketRange() {
|
| - DCHECK_LT(0, declared_min()); // 0 is the underflow bucket here.
|
| + DCHECK_GT(declared_min(), 0); // 0 is the underflow bucket here.
|
| double min = declared_min();
|
| double max = declared_max();
|
| size_t i;
|
| @@ -691,6 +691,70 @@
|
|
|
|
|
| //------------------------------------------------------------------------------
|
| +// CustomHistogram:
|
| +//------------------------------------------------------------------------------
|
| +
|
| +scoped_refptr<Histogram> CustomHistogram::FactoryGet(
|
| + const std::string& name, const std::vector<int>& custom_ranges,
|
| + Flags flags) {
|
| + scoped_refptr<Histogram> histogram(NULL);
|
| +
|
| + // Remove the duplicates in the custom ranges array.
|
| + std::vector<int> ranges = custom_ranges;
|
| + ranges.push_back(0); // Ensure we have a zero value.
|
| + std::sort(ranges.begin(), ranges.end());
|
| + ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end());
|
| + if (ranges.size() <= 1) {
|
| + DCHECK(false);
|
| + // Note that we pushed a 0 in above, so for defensive code....
|
| + ranges.push_back(1); // Put in some data so we can index to [1].
|
| + }
|
| +
|
| + DCHECK_LT(ranges.back(), kSampleType_MAX);
|
| +
|
| + if (StatisticsRecorder::FindHistogram(name, &histogram)) {
|
| + DCHECK(histogram.get());
|
| + DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM);
|
| + } else {
|
| + histogram = new CustomHistogram(name, ranges);
|
| + scoped_refptr<Histogram> registered_histogram(NULL);
|
| + StatisticsRecorder::FindHistogram(name, ®istered_histogram);
|
| + if (registered_histogram.get() &&
|
| + registered_histogram.get() != histogram.get())
|
| + histogram = registered_histogram;
|
| + }
|
| +
|
| + DCHECK_EQ(histogram->histogram_type(), CUSTOM_HISTOGRAM);
|
| + DCHECK(histogram->HasConstructorArguments(ranges[1], ranges.back(),
|
| + ranges.size()));
|
| + histogram->SetFlags(flags);
|
| + return histogram;
|
| +}
|
| +
|
| +CustomHistogram::CustomHistogram(const std::string& name,
|
| + const std::vector<int>& custom_ranges)
|
| + : Histogram(name, custom_ranges[1], custom_ranges.back(),
|
| + custom_ranges.size()) {
|
| + DCHECK_GT(custom_ranges.size(), 1u);
|
| + DCHECK_EQ(custom_ranges[0], 0);
|
| + ranges_vector_ = &custom_ranges;
|
| + InitializeBucketRange();
|
| + ranges_vector_ = NULL;
|
| + DCHECK(ValidateBucketRanges());
|
| +}
|
| +
|
| +void CustomHistogram::InitializeBucketRange() {
|
| + DCHECK(ranges_vector_->size() <= bucket_count());
|
| + for (size_t index = 0; index < ranges_vector_->size(); ++index) {
|
| + SetBucketRange(index, (*ranges_vector_)[index]);
|
| + }
|
| +}
|
| +
|
| +double CustomHistogram::GetBucketSize(Count current, size_t i) const {
|
| + return 1;
|
| +}
|
| +
|
| +//------------------------------------------------------------------------------
|
| // The next section handles global (central) support for all histograms, as well
|
| // as startup/teardown of this service.
|
| //------------------------------------------------------------------------------
|
|
|