| 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 // See header file for details and examples. | 8 // See header file for details and examples. |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 size_t bucket_count, | 90 size_t bucket_count, |
| 91 int32 flags) { | 91 int32 flags) { |
| 92 bool valid_arguments = | 92 bool valid_arguments = |
| 93 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); | 93 InspectConstructionArguments(name, &minimum, &maximum, &bucket_count); |
| 94 DCHECK(valid_arguments); | 94 DCHECK(valid_arguments); |
| 95 | 95 |
| 96 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); | 96 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
| 97 if (!histogram) { | 97 if (!histogram) { |
| 98 // To avoid racy destruction at shutdown, the following will be leaked. | 98 // To avoid racy destruction at shutdown, the following will be leaked. |
| 99 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 99 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
| 100 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); | 100 InitializeBucketRanges(minimum, maximum, ranges); |
| 101 const BucketRanges* registered_ranges = | 101 const BucketRanges* registered_ranges = |
| 102 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 102 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
| 103 | 103 |
| 104 Histogram* tentative_histogram = | 104 Histogram* tentative_histogram = |
| 105 new Histogram(name, minimum, maximum, bucket_count, registered_ranges); | 105 new Histogram(name, minimum, maximum, registered_ranges); |
| 106 | 106 |
| 107 tentative_histogram->SetFlags(flags); | 107 tentative_histogram->SetFlags(flags); |
| 108 histogram = | 108 histogram = |
| 109 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 109 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
| 110 } | 110 } |
| 111 | 111 |
| 112 DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); | 112 DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); |
| 113 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 113 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
| 114 return histogram; | 114 return histogram; |
| 115 } | 115 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 136 // consecutive buckets that is sooo small, that the integer bounds are the same | 136 // consecutive buckets that is sooo small, that the integer bounds are the same |
| 137 // (effectively making one bucket get no values). We need to avoid: | 137 // (effectively making one bucket get no values). We need to avoid: |
| 138 // ranges(i) == ranges(i + 1) | 138 // ranges(i) == ranges(i + 1) |
| 139 // To avoid that, we just do a fine-grained bucket width as far as we need to | 139 // To avoid that, we just do a fine-grained bucket width as far as we need to |
| 140 // until we get a ratio that moves us along at least 2 units at a time. From | 140 // until we get a ratio that moves us along at least 2 units at a time. From |
| 141 // that bucket onward we do use the exponential growth of buckets. | 141 // that bucket onward we do use the exponential growth of buckets. |
| 142 // | 142 // |
| 143 // static | 143 // static |
| 144 void Histogram::InitializeBucketRanges(Sample minimum, | 144 void Histogram::InitializeBucketRanges(Sample minimum, |
| 145 Sample maximum, | 145 Sample maximum, |
| 146 size_t bucket_count, | |
| 147 BucketRanges* ranges) { | 146 BucketRanges* ranges) { |
| 148 DCHECK_EQ(ranges->size(), bucket_count + 1); | |
| 149 double log_max = log(static_cast<double>(maximum)); | 147 double log_max = log(static_cast<double>(maximum)); |
| 150 double log_ratio; | 148 double log_ratio; |
| 151 double log_next; | 149 double log_next; |
| 152 size_t bucket_index = 1; | 150 size_t bucket_index = 1; |
| 153 Sample current = minimum; | 151 Sample current = minimum; |
| 154 ranges->set_range(bucket_index, current); | 152 ranges->set_range(bucket_index, current); |
| 153 size_t bucket_count = ranges->bucket_count(); |
| 155 while (bucket_count > ++bucket_index) { | 154 while (bucket_count > ++bucket_index) { |
| 156 double log_current; | 155 double log_current; |
| 157 log_current = log(static_cast<double>(current)); | 156 log_current = log(static_cast<double>(current)); |
| 158 // Calculate the count'th root of the range. | 157 // Calculate the count'th root of the range. |
| 159 log_ratio = (log_max - log_current) / (bucket_count - bucket_index); | 158 log_ratio = (log_max - log_current) / (bucket_count - bucket_index); |
| 160 // See where the next bucket would start. | 159 // See where the next bucket would start. |
| 161 log_next = log_current + log_ratio; | 160 log_next = log_current + log_ratio; |
| 162 Sample next; | 161 Sample next; |
| 163 next = static_cast<int>(floor(exp(log_next) + 0.5)); | 162 next = static_cast<int>(floor(exp(log_next) + 0.5)); |
| 164 if (next > current) | 163 if (next > current) |
| 165 current = next; | 164 current = next; |
| 166 else | 165 else |
| 167 ++current; // Just do a narrow bucket, and keep trying. | 166 ++current; // Just do a narrow bucket, and keep trying. |
| 168 ranges->set_range(bucket_index, current); | 167 ranges->set_range(bucket_index, current); |
| 169 } | 168 } |
| 170 ranges->set_range(ranges->size() - 1, HistogramBase::kSampleType_MAX); | 169 ranges->set_range(ranges->bucket_count(), HistogramBase::kSampleType_MAX); |
| 171 ranges->ResetChecksum(); | 170 ranges->ResetChecksum(); |
| 172 } | 171 } |
| 173 | 172 |
| 174 // static | 173 // static |
| 175 const int Histogram::kCommonRaceBasedCountMismatch = 5; | 174 const int Histogram::kCommonRaceBasedCountMismatch = 5; |
| 176 | 175 |
| 177 int Histogram::FindCorruption(const HistogramSamples& samples) const { | 176 int Histogram::FindCorruption(const HistogramSamples& samples) const { |
| 178 int inconsistencies = NO_INCONSISTENCIES; | 177 int inconsistencies = NO_INCONSISTENCIES; |
| 179 Sample previous_range = -1; // Bottom range is always 0. | 178 Sample previous_range = -1; // Bottom range is always 0. |
| 180 for (size_t index = 0; index < bucket_count(); ++index) { | 179 for (size_t index = 0; index < bucket_count(); ++index) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 204 } | 203 } |
| 205 } | 204 } |
| 206 return inconsistencies; | 205 return inconsistencies; |
| 207 } | 206 } |
| 208 | 207 |
| 209 Sample Histogram::ranges(size_t i) const { | 208 Sample Histogram::ranges(size_t i) const { |
| 210 return bucket_ranges_->range(i); | 209 return bucket_ranges_->range(i); |
| 211 } | 210 } |
| 212 | 211 |
| 213 size_t Histogram::bucket_count() const { | 212 size_t Histogram::bucket_count() const { |
| 214 return bucket_count_; | 213 return bucket_ranges_->bucket_count(); |
| 215 } | 214 } |
| 216 | 215 |
| 217 // static | 216 // static |
| 218 bool Histogram::InspectConstructionArguments(const string& name, | 217 bool Histogram::InspectConstructionArguments(const string& name, |
| 219 Sample* minimum, | 218 Sample* minimum, |
| 220 Sample* maximum, | 219 Sample* maximum, |
| 221 size_t* bucket_count) { | 220 size_t* bucket_count) { |
| 222 // Defensive code for backward compatibility. | 221 // Defensive code for backward compatibility. |
| 223 if (*minimum < 1) { | 222 if (*minimum < 1) { |
| 224 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum; | 223 DVLOG(1) << "Histogram: " << name << " has bad minimum: " << *minimum; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 240 return false; | 239 return false; |
| 241 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) | 240 if (*bucket_count > static_cast<size_t>(*maximum - *minimum + 2)) |
| 242 return false; | 241 return false; |
| 243 return true; | 242 return true; |
| 244 } | 243 } |
| 245 | 244 |
| 246 HistogramType Histogram::GetHistogramType() const { | 245 HistogramType Histogram::GetHistogramType() const { |
| 247 return HISTOGRAM; | 246 return HISTOGRAM; |
| 248 } | 247 } |
| 249 | 248 |
| 250 bool Histogram::HasConstructionArguments(Sample minimum, | 249 bool Histogram::HasConstructionArguments(Sample expected_minimum, |
| 251 Sample maximum, | 250 Sample expected_maximum, |
| 252 size_t bucket_count) const { | 251 size_t expected_bucket_count) const { |
| 253 return ((minimum == declared_min_) && (maximum == declared_max_) && | 252 return ((expected_minimum == declared_min_) && |
| 254 (bucket_count == bucket_count_)); | 253 (expected_maximum == declared_max_) && |
| 254 (expected_bucket_count == bucket_count())); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void Histogram::Add(int value) { | 257 void Histogram::Add(int value) { |
| 258 DCHECK_EQ(0, ranges(0)); | 258 DCHECK_EQ(0, ranges(0)); |
| 259 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count_)); | 259 DCHECK_EQ(kSampleType_MAX, ranges(bucket_count())); |
| 260 | 260 |
| 261 if (value > kSampleType_MAX - 1) | 261 if (value > kSampleType_MAX - 1) |
| 262 value = kSampleType_MAX - 1; | 262 value = kSampleType_MAX - 1; |
| 263 if (value < 0) | 263 if (value < 0) |
| 264 value = 0; | 264 value = 0; |
| 265 samples_->Accumulate(value, 1); | 265 samples_->Accumulate(value, 1); |
| 266 } | 266 } |
| 267 | 267 |
| 268 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { | 268 scoped_ptr<HistogramSamples> Histogram::SnapshotSamples() const { |
| 269 return SnapshotSampleVector().PassAs<HistogramSamples>(); | 269 return SnapshotSampleVector().PassAs<HistogramSamples>(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 295 pickle->WriteInt(flags()) && | 295 pickle->WriteInt(flags()) && |
| 296 pickle->WriteInt(declared_min()) && | 296 pickle->WriteInt(declared_min()) && |
| 297 pickle->WriteInt(declared_max()) && | 297 pickle->WriteInt(declared_max()) && |
| 298 pickle->WriteUInt64(bucket_count()) && | 298 pickle->WriteUInt64(bucket_count()) && |
| 299 pickle->WriteUInt32(bucket_ranges()->checksum()); | 299 pickle->WriteUInt32(bucket_ranges()->checksum()); |
| 300 } | 300 } |
| 301 | 301 |
| 302 Histogram::Histogram(const string& name, | 302 Histogram::Histogram(const string& name, |
| 303 Sample minimum, | 303 Sample minimum, |
| 304 Sample maximum, | 304 Sample maximum, |
| 305 size_t bucket_count, | |
| 306 const BucketRanges* ranges) | 305 const BucketRanges* ranges) |
| 307 : HistogramBase(name), | 306 : HistogramBase(name), |
| 308 bucket_ranges_(ranges), | 307 bucket_ranges_(ranges), |
| 309 declared_min_(minimum), | 308 declared_min_(minimum), |
| 310 declared_max_(maximum), | 309 declared_max_(maximum) { |
| 311 bucket_count_(bucket_count) { | |
| 312 if (ranges) | 310 if (ranges) |
| 313 samples_.reset(new SampleVector(ranges)); | 311 samples_.reset(new SampleVector(ranges)); |
| 314 } | 312 } |
| 315 | 313 |
| 316 Histogram::~Histogram() { | 314 Histogram::~Histogram() { |
| 317 } | 315 } |
| 318 | 316 |
| 319 bool Histogram::PrintEmptyBucket(size_t index) const { | 317 bool Histogram::PrintEmptyBucket(size_t index) const { |
| 320 return true; | 318 return true; |
| 321 } | 319 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 int32 flags, | 539 int32 flags, |
| 542 const DescriptionPair descriptions[]) { | 540 const DescriptionPair descriptions[]) { |
| 543 bool valid_arguments = Histogram::InspectConstructionArguments( | 541 bool valid_arguments = Histogram::InspectConstructionArguments( |
| 544 name, &minimum, &maximum, &bucket_count); | 542 name, &minimum, &maximum, &bucket_count); |
| 545 DCHECK(valid_arguments); | 543 DCHECK(valid_arguments); |
| 546 | 544 |
| 547 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); | 545 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
| 548 if (!histogram) { | 546 if (!histogram) { |
| 549 // To avoid racy destruction at shutdown, the following will be leaked. | 547 // To avoid racy destruction at shutdown, the following will be leaked. |
| 550 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 548 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
| 551 InitializeBucketRanges(minimum, maximum, bucket_count, ranges); | 549 InitializeBucketRanges(minimum, maximum, ranges); |
| 552 const BucketRanges* registered_ranges = | 550 const BucketRanges* registered_ranges = |
| 553 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 551 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
| 554 | 552 |
| 555 LinearHistogram* tentative_histogram = | 553 LinearHistogram* tentative_histogram = |
| 556 new LinearHistogram(name, minimum, maximum, bucket_count, | 554 new LinearHistogram(name, minimum, maximum, registered_ranges); |
| 557 registered_ranges); | |
| 558 | 555 |
| 559 // Set range descriptions. | 556 // Set range descriptions. |
| 560 if (descriptions) { | 557 if (descriptions) { |
| 561 for (int i = 0; descriptions[i].description; ++i) { | 558 for (int i = 0; descriptions[i].description; ++i) { |
| 562 tentative_histogram->bucket_description_[descriptions[i].sample] = | 559 tentative_histogram->bucket_description_[descriptions[i].sample] = |
| 563 descriptions[i].description; | 560 descriptions[i].description; |
| 564 } | 561 } |
| 565 } | 562 } |
| 566 | 563 |
| 567 tentative_histogram->SetFlags(flags); | 564 tentative_histogram->SetFlags(flags); |
| 568 histogram = | 565 histogram = |
| 569 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 566 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
| 570 } | 567 } |
| 571 | 568 |
| 572 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); | 569 DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); |
| 573 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); | 570 CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
| 574 return histogram; | 571 return histogram; |
| 575 } | 572 } |
| 576 | 573 |
| 577 HistogramType LinearHistogram::GetHistogramType() const { | 574 HistogramType LinearHistogram::GetHistogramType() const { |
| 578 return LINEAR_HISTOGRAM; | 575 return LINEAR_HISTOGRAM; |
| 579 } | 576 } |
| 580 | 577 |
| 581 LinearHistogram::LinearHistogram(const string& name, | 578 LinearHistogram::LinearHistogram(const string& name, |
| 582 Sample minimum, | 579 Sample minimum, |
| 583 Sample maximum, | 580 Sample maximum, |
| 584 size_t bucket_count, | |
| 585 const BucketRanges* ranges) | 581 const BucketRanges* ranges) |
| 586 : Histogram(name, minimum, maximum, bucket_count, ranges) { | 582 : Histogram(name, minimum, maximum, ranges) { |
| 587 } | 583 } |
| 588 | 584 |
| 589 double LinearHistogram::GetBucketSize(Count current, size_t i) const { | 585 double LinearHistogram::GetBucketSize(Count current, size_t i) const { |
| 590 DCHECK_GT(ranges(i + 1), ranges(i)); | 586 DCHECK_GT(ranges(i + 1), ranges(i)); |
| 591 // Adjacent buckets with different widths would have "surprisingly" many (few) | 587 // Adjacent buckets with different widths would have "surprisingly" many (few) |
| 592 // samples in a histogram if we didn't normalize this way. | 588 // samples in a histogram if we didn't normalize this way. |
| 593 double denominator = ranges(i + 1) - ranges(i); | 589 double denominator = ranges(i + 1) - ranges(i); |
| 594 return current/denominator; | 590 return current/denominator; |
| 595 } | 591 } |
| 596 | 592 |
| 597 const string LinearHistogram::GetAsciiBucketRange(size_t i) const { | 593 const string LinearHistogram::GetAsciiBucketRange(size_t i) const { |
| 598 int range = ranges(i); | 594 int range = ranges(i); |
| 599 BucketDescriptionMap::const_iterator it = bucket_description_.find(range); | 595 BucketDescriptionMap::const_iterator it = bucket_description_.find(range); |
| 600 if (it == bucket_description_.end()) | 596 if (it == bucket_description_.end()) |
| 601 return Histogram::GetAsciiBucketRange(i); | 597 return Histogram::GetAsciiBucketRange(i); |
| 602 return it->second; | 598 return it->second; |
| 603 } | 599 } |
| 604 | 600 |
| 605 bool LinearHistogram::PrintEmptyBucket(size_t index) const { | 601 bool LinearHistogram::PrintEmptyBucket(size_t index) const { |
| 606 return bucket_description_.find(ranges(index)) == bucket_description_.end(); | 602 return bucket_description_.find(ranges(index)) == bucket_description_.end(); |
| 607 } | 603 } |
| 608 | 604 |
| 609 // static | 605 // static |
| 610 void LinearHistogram::InitializeBucketRanges(Sample minimum, | 606 void LinearHistogram::InitializeBucketRanges(Sample minimum, |
| 611 Sample maximum, | 607 Sample maximum, |
| 612 size_t bucket_count, | |
| 613 BucketRanges* ranges) { | 608 BucketRanges* ranges) { |
| 614 DCHECK_EQ(ranges->size(), bucket_count + 1); | |
| 615 double min = minimum; | 609 double min = minimum; |
| 616 double max = maximum; | 610 double max = maximum; |
| 617 size_t i; | 611 size_t bucket_count = ranges->bucket_count(); |
| 618 for (i = 1; i < bucket_count; ++i) { | 612 for (size_t i = 1; i < bucket_count; ++i) { |
| 619 double linear_range = | 613 double linear_range = |
| 620 (min * (bucket_count -1 - i) + max * (i - 1)) / (bucket_count - 2); | 614 (min * (bucket_count - 1 - i) + max * (i - 1)) / (bucket_count - 2); |
| 621 ranges->set_range(i, static_cast<Sample>(linear_range + 0.5)); | 615 ranges->set_range(i, static_cast<Sample>(linear_range + 0.5)); |
| 622 } | 616 } |
| 623 ranges->set_range(ranges->size() - 1, HistogramBase::kSampleType_MAX); | 617 ranges->set_range(ranges->bucket_count(), HistogramBase::kSampleType_MAX); |
| 624 ranges->ResetChecksum(); | 618 ranges->ResetChecksum(); |
| 625 } | 619 } |
| 626 | 620 |
| 627 // static | 621 // static |
| 628 HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) { | 622 HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) { |
| 629 string histogram_name; | 623 string histogram_name; |
| 630 int flags; | 624 int flags; |
| 631 int declared_min; | 625 int declared_min; |
| 632 int declared_max; | 626 int declared_max; |
| 633 uint64 bucket_count; | 627 uint64 bucket_count; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 649 | 643 |
| 650 //------------------------------------------------------------------------------ | 644 //------------------------------------------------------------------------------ |
| 651 // This section provides implementation for BooleanHistogram. | 645 // This section provides implementation for BooleanHistogram. |
| 652 //------------------------------------------------------------------------------ | 646 //------------------------------------------------------------------------------ |
| 653 | 647 |
| 654 HistogramBase* BooleanHistogram::FactoryGet(const string& name, int32 flags) { | 648 HistogramBase* BooleanHistogram::FactoryGet(const string& name, int32 flags) { |
| 655 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); | 649 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
| 656 if (!histogram) { | 650 if (!histogram) { |
| 657 // To avoid racy destruction at shutdown, the following will be leaked. | 651 // To avoid racy destruction at shutdown, the following will be leaked. |
| 658 BucketRanges* ranges = new BucketRanges(4); | 652 BucketRanges* ranges = new BucketRanges(4); |
| 659 LinearHistogram::InitializeBucketRanges(1, 2, 3, ranges); | 653 LinearHistogram::InitializeBucketRanges(1, 2, ranges); |
| 660 const BucketRanges* registered_ranges = | 654 const BucketRanges* registered_ranges = |
| 661 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 655 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
| 662 | 656 |
| 663 BooleanHistogram* tentative_histogram = | 657 BooleanHistogram* tentative_histogram = |
| 664 new BooleanHistogram(name, registered_ranges); | 658 new BooleanHistogram(name, registered_ranges); |
| 665 | 659 |
| 666 tentative_histogram->SetFlags(flags); | 660 tentative_histogram->SetFlags(flags); |
| 667 histogram = | 661 histogram = |
| 668 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); | 662 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
| 669 } | 663 } |
| 670 | 664 |
| 671 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->GetHistogramType()); | 665 DCHECK_EQ(BOOLEAN_HISTOGRAM, histogram->GetHistogramType()); |
| 672 return histogram; | 666 return histogram; |
| 673 } | 667 } |
| 674 | 668 |
| 675 HistogramType BooleanHistogram::GetHistogramType() const { | 669 HistogramType BooleanHistogram::GetHistogramType() const { |
| 676 return BOOLEAN_HISTOGRAM; | 670 return BOOLEAN_HISTOGRAM; |
| 677 } | 671 } |
| 678 | 672 |
| 679 BooleanHistogram::BooleanHistogram(const string& name, | 673 BooleanHistogram::BooleanHistogram(const string& name, |
| 680 const BucketRanges* ranges) | 674 const BucketRanges* ranges) |
| 681 : LinearHistogram(name, 1, 2, 3, ranges) {} | 675 : LinearHistogram(name, 1, 2, ranges) {} |
| 682 | 676 |
| 683 HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { | 677 HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { |
| 684 string histogram_name; | 678 string histogram_name; |
| 685 int flags; | 679 int flags; |
| 686 int declared_min; | 680 int declared_min; |
| 687 int declared_max; | 681 int declared_max; |
| 688 uint64 bucket_count; | 682 uint64 bucket_count; |
| 689 uint32 range_checksum; | 683 uint32 range_checksum; |
| 690 | 684 |
| 691 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min, | 685 if (!ReadHistogramArguments(iter, &histogram_name, &flags, &declared_min, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 // values, FactoryGet will take care of removing them. | 741 // values, FactoryGet will take care of removing them. |
| 748 all_values.push_back(value + 1); | 742 all_values.push_back(value + 1); |
| 749 } | 743 } |
| 750 return all_values; | 744 return all_values; |
| 751 } | 745 } |
| 752 | 746 |
| 753 CustomHistogram::CustomHistogram(const string& name, | 747 CustomHistogram::CustomHistogram(const string& name, |
| 754 const BucketRanges* ranges) | 748 const BucketRanges* ranges) |
| 755 : Histogram(name, | 749 : Histogram(name, |
| 756 ranges->range(1), | 750 ranges->range(1), |
| 757 ranges->range(ranges->size() - 2), | 751 ranges->range(ranges->bucket_count() - 1), |
| 758 ranges->size() - 1, | |
| 759 ranges) {} | 752 ranges) {} |
| 760 | 753 |
| 761 bool CustomHistogram::SerializeInfoImpl(Pickle* pickle) const { | 754 bool CustomHistogram::SerializeInfoImpl(Pickle* pickle) const { |
| 762 if (!Histogram::SerializeInfoImpl(pickle)) | 755 if (!Histogram::SerializeInfoImpl(pickle)) |
| 763 return false; | 756 return false; |
| 764 | 757 |
| 765 // Serialize ranges. First and last ranges are alwasy 0 and INT_MAX, so don't | 758 // Serialize ranges. First and last ranges are alwasy 0 and INT_MAX, so don't |
| 766 // write them. | 759 // write them. |
| 767 for (size_t i = 1; i < bucket_ranges()->size() - 1; ++i) { | 760 for (size_t i = 1; i < bucket_ranges()->bucket_count(); ++i) { |
| 768 if (!pickle->WriteInt(bucket_ranges()->range(i))) | 761 if (!pickle->WriteInt(bucket_ranges()->range(i))) |
| 769 return false; | 762 return false; |
| 770 } | 763 } |
| 771 return true; | 764 return true; |
| 772 } | 765 } |
| 773 | 766 |
| 774 double CustomHistogram::GetBucketSize(Count current, size_t i) const { | 767 double CustomHistogram::GetBucketSize(Count current, size_t i) const { |
| 775 return 1; | 768 return 1; |
| 776 } | 769 } |
| 777 | 770 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 825 |
| 833 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); | 826 BucketRanges* bucket_ranges = new BucketRanges(ranges.size()); |
| 834 for (size_t i = 0; i < ranges.size(); i++) { | 827 for (size_t i = 0; i < ranges.size(); i++) { |
| 835 bucket_ranges->set_range(i, ranges[i]); | 828 bucket_ranges->set_range(i, ranges[i]); |
| 836 } | 829 } |
| 837 bucket_ranges->ResetChecksum(); | 830 bucket_ranges->ResetChecksum(); |
| 838 return bucket_ranges; | 831 return bucket_ranges; |
| 839 } | 832 } |
| 840 | 833 |
| 841 } // namespace base | 834 } // namespace base |
| OLD | NEW |