Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Unified Diff: base/metrics/histogram.cc

Issue 17451016: [UMA] Remove redundant bucket_count variable from base::Histogram. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram.cc
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index a3dd63a49c1f7cfbf2e8d77767215f0a9b609721..882269b058a6eb54443cbfbd43917ad1515d19d1 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -97,12 +97,12 @@ HistogramBase* Histogram::FactoryGet(const string& name,
if (!histogram) {
// To avoid racy destruction at shutdown, the following will be leaked.
BucketRanges* ranges = new BucketRanges(bucket_count + 1);
- InitializeBucketRanges(minimum, maximum, bucket_count, ranges);
+ InitializeBucketRanges(minimum, maximum, ranges);
const BucketRanges* registered_ranges =
StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
Histogram* tentative_histogram =
- new Histogram(name, minimum, maximum, bucket_count, registered_ranges);
+ new Histogram(name, minimum, maximum, registered_ranges);
tentative_histogram->SetFlags(flags);
histogram =
@@ -143,15 +143,14 @@ TimeTicks Histogram::DebugNow() {
// static
void Histogram::InitializeBucketRanges(Sample minimum,
Sample maximum,
- size_t bucket_count,
BucketRanges* ranges) {
- DCHECK_EQ(ranges->size(), bucket_count + 1);
double log_max = log(static_cast<double>(maximum));
double log_ratio;
double log_next;
size_t bucket_index = 1;
Sample current = minimum;
ranges->set_range(bucket_index, current);
+ size_t bucket_count = ranges->BucketCount();
while (bucket_count > ++bucket_index) {
double log_current;
log_current = log(static_cast<double>(current));
@@ -167,7 +166,7 @@ void Histogram::InitializeBucketRanges(Sample minimum,
++current; // Just do a narrow bucket, and keep trying.
ranges->set_range(bucket_index, current);
}
- ranges->set_range(ranges->size() - 1, HistogramBase::kSampleType_MAX);
+ ranges->set_range(ranges->BucketCount(), HistogramBase::kSampleType_MAX);
ranges->ResetChecksum();
}
@@ -177,7 +176,7 @@ const int Histogram::kCommonRaceBasedCountMismatch = 5;
int Histogram::FindCorruption(const HistogramSamples& samples) const {
int inconsistencies = NO_INCONSISTENCIES;
Sample previous_range = -1; // Bottom range is always 0.
- for (size_t index = 0; index < bucket_count(); ++index) {
+ for (size_t index = 0; index < BucketCount(); ++index) {
int new_range = ranges(index);
if (previous_range >= new_range)
inconsistencies |= BUCKET_ORDER_ERROR;
@@ -210,8 +209,8 @@ Sample Histogram::ranges(size_t i) const {
return bucket_ranges_->range(i);
}
-size_t Histogram::bucket_count() const {
- return bucket_count_;
+size_t Histogram::BucketCount() const {
+ return bucket_ranges_->BucketCount();
}
// static
@@ -251,12 +250,12 @@ bool Histogram::HasConstructionArguments(Sample minimum,
Sample maximum,
size_t bucket_count) const {
return ((minimum == declared_min_) && (maximum == declared_max_) &&
- (bucket_count == bucket_count_));
+ (bucket_count == BucketCount()));
}
void Histogram::Add(int value) {
DCHECK_EQ(0, ranges(0));
- DCHECK_EQ(kSampleType_MAX, ranges(bucket_count_));
+ DCHECK_EQ(kSampleType_MAX, ranges(BucketCount()));
if (value > kSampleType_MAX - 1)
value = kSampleType_MAX - 1;
@@ -295,20 +294,18 @@ bool Histogram::SerializeInfoImpl(Pickle* pickle) const {
pickle->WriteInt(flags()) &&
pickle->WriteInt(declared_min()) &&
pickle->WriteInt(declared_max()) &&
- pickle->WriteUInt64(bucket_count()) &&
+ pickle->WriteUInt64(BucketCount()) &&
pickle->WriteUInt32(bucket_ranges()->checksum());
}
Histogram::Histogram(const string& name,
Sample minimum,
Sample maximum,
- size_t bucket_count,
const BucketRanges* ranges)
: HistogramBase(name),
bucket_ranges_(ranges),
declared_min_(minimum),
- declared_max_(maximum),
- bucket_count_(bucket_count) {
+ declared_max_(maximum) {
if (ranges)
samples_.reset(new SampleVector(ranges));
}
@@ -390,7 +387,7 @@ void Histogram::WriteAsciiImpl(bool graph_it,
// Calculate space needed to print bucket range numbers. Leave room to print
// nearly the largest bucket range without sliding over the histogram.
- size_t largest_non_empty_bucket = bucket_count() - 1;
+ size_t largest_non_empty_bucket = BucketCount() - 1;
while (0 == snapshot->GetCountAtIndex(largest_non_empty_bucket)) {
if (0 == largest_non_empty_bucket)
break; // All buckets are empty.
@@ -399,7 +396,7 @@ void Histogram::WriteAsciiImpl(bool graph_it,
// Calculate largest print width needed for any of our bucket range displays.
size_t print_width = 1;
- for (size_t i = 0; i < bucket_count(); ++i) {
+ for (size_t i = 0; i < BucketCount(); ++i) {
if (snapshot->GetCountAtIndex(i)) {
size_t width = GetAsciiBucketRange(i).size() + 1;
if (width > print_width)
@@ -410,7 +407,7 @@ void Histogram::WriteAsciiImpl(bool graph_it,
int64 remaining = sample_count;
int64 past = 0;
// Output the actual histogram graph.
- for (size_t i = 0; i < bucket_count(); ++i) {
+ for (size_t i = 0; i < BucketCount(); ++i) {
Count current = snapshot->GetCountAtIndex(i);
if (!current && !PrintEmptyBucket(i))
continue;
@@ -419,9 +416,9 @@ void Histogram::WriteAsciiImpl(bool graph_it,
output->append(range);
for (size_t j = 0; range.size() + j < print_width + 1; ++j)
output->push_back(' ');
- if (0 == current && i < bucket_count() - 1 &&
+ if (0 == current && i < BucketCount() - 1 &&
0 == snapshot->GetCountAtIndex(i + 1)) {
- while (i < bucket_count() - 1 &&
+ while (i < BucketCount() - 1 &&
0 == snapshot->GetCountAtIndex(i + 1)) {
++i;
}
@@ -441,7 +438,7 @@ void Histogram::WriteAsciiImpl(bool graph_it,
double Histogram::GetPeakBucketSize(const SampleVector& samples) const {
double max = 0;
- for (size_t i = 0; i < bucket_count() ; ++i) {
+ for (size_t i = 0; i < BucketCount() ; ++i) {
double current_size = GetBucketSize(samples.GetCountAtIndex(i), i);
if (current_size > max)
max = current_size;
@@ -484,7 +481,7 @@ void Histogram::GetParameters(DictionaryValue* params) const {
params->SetString("type", HistogramTypeToString(GetHistogramType()));
params->SetInteger("min", declared_min());
params->SetInteger("max", declared_max());
- params->SetInteger("bucket_count", static_cast<int>(bucket_count()));
+ params->SetInteger("bucket_count", static_cast<int>(BucketCount()));
}
void Histogram::GetCountAndBucketData(Count* count,
@@ -494,12 +491,12 @@ void Histogram::GetCountAndBucketData(Count* count,
*count = snapshot->TotalCount();
*sum = snapshot->sum();
size_t index = 0;
- for (size_t i = 0; i < bucket_count(); ++i) {
+ for (size_t i = 0; i < BucketCount(); ++i) {
Sample count = snapshot->GetCountAtIndex(i);
if (count > 0) {
scoped_ptr<DictionaryValue> bucket_value(new DictionaryValue());
bucket_value->SetInteger("low", ranges(i));
- if (i != bucket_count() - 1)
+ if (i != BucketCount() - 1)
bucket_value->SetInteger("high", ranges(i + 1));
bucket_value->SetInteger("count", count);
buckets->Set(index, bucket_value.release());
@@ -548,13 +545,12 @@ HistogramBase* LinearHistogram::FactoryGetWithRangeDescription(
if (!histogram) {
// To avoid racy destruction at shutdown, the following will be leaked.
BucketRanges* ranges = new BucketRanges(bucket_count + 1);
- InitializeBucketRanges(minimum, maximum, bucket_count, ranges);
+ InitializeBucketRanges(minimum, maximum, ranges);
const BucketRanges* registered_ranges =
StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
LinearHistogram* tentative_histogram =
- new LinearHistogram(name, minimum, maximum, bucket_count,
- registered_ranges);
+ new LinearHistogram(name, minimum, maximum, registered_ranges);
// Set range descriptions.
if (descriptions) {
@@ -581,9 +577,8 @@ HistogramType LinearHistogram::GetHistogramType() const {
LinearHistogram::LinearHistogram(const string& name,
Sample minimum,
Sample maximum,
- size_t bucket_count,
const BucketRanges* ranges)
- : Histogram(name, minimum, maximum, bucket_count, ranges) {
+ : Histogram(name, minimum, maximum, ranges) {
}
double LinearHistogram::GetBucketSize(Count current, size_t i) const {
@@ -609,18 +604,16 @@ bool LinearHistogram::PrintEmptyBucket(size_t index) const {
// static
void LinearHistogram::InitializeBucketRanges(Sample minimum,
Sample maximum,
- size_t bucket_count,
BucketRanges* ranges) {
- DCHECK_EQ(ranges->size(), bucket_count + 1);
double min = minimum;
double max = maximum;
- size_t i;
- for (i = 1; i < bucket_count; ++i) {
+ size_t bucket_count = ranges->BucketCount();
+ for (size_t i = 1; i < bucket_count; ++i) {
double linear_range =
- (min * (bucket_count -1 - i) + max * (i - 1)) / (bucket_count - 2);
+ (min * (bucket_count - 1 - i) + max * (i - 1)) / (bucket_count - 2);
ranges->set_range(i, static_cast<Sample>(linear_range + 0.5));
}
- ranges->set_range(ranges->size() - 1, HistogramBase::kSampleType_MAX);
+ ranges->set_range(ranges->BucketCount(), HistogramBase::kSampleType_MAX);
ranges->ResetChecksum();
}
@@ -656,7 +649,7 @@ HistogramBase* BooleanHistogram::FactoryGet(const string& name, int32 flags) {
if (!histogram) {
// To avoid racy destruction at shutdown, the following will be leaked.
BucketRanges* ranges = new BucketRanges(4);
- LinearHistogram::InitializeBucketRanges(1, 2, 3, ranges);
+ LinearHistogram::InitializeBucketRanges(1, 2, ranges);
const BucketRanges* registered_ranges =
StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
@@ -678,7 +671,7 @@ HistogramType BooleanHistogram::GetHistogramType() const {
BooleanHistogram::BooleanHistogram(const string& name,
const BucketRanges* ranges)
- : LinearHistogram(name, 1, 2, 3, ranges) {}
+ : LinearHistogram(name, 1, 2, ranges) {}
HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) {
string histogram_name;
@@ -754,8 +747,7 @@ CustomHistogram::CustomHistogram(const string& name,
const BucketRanges* ranges)
: Histogram(name,
ranges->range(1),
- ranges->range(ranges->size() - 2),
- ranges->size() - 1,
+ ranges->range(ranges->BucketCount() - 1),
ranges) {}
bool CustomHistogram::SerializeInfoImpl(Pickle* pickle) const {
@@ -764,7 +756,7 @@ bool CustomHistogram::SerializeInfoImpl(Pickle* pickle) const {
// Serialize ranges. First and last ranges are alwasy 0 and INT_MAX, so don't
// write them.
- for (size_t i = 1; i < bucket_ranges()->size() - 1; ++i) {
+ for (size_t i = 1; i < bucket_ranges()->BucketCount(); ++i) {
if (!pickle->WriteInt(bucket_ranges()->range(i)))
return false;
}

Powered by Google App Engine
This is Rietveld 408576698