Commit 564cedfc authored by Brian White's avatar Brian White Committed by Commit Bot

Handle linear histograms with a single #0 value.

Some enumerations have only a single entry of 0 (which is technically
an "underflow").  Support this by changing the maximum from 1 to 2.

Bug: 904964
Change-Id: If81522c55da292948f6a04cc51077111200537f1
Reviewed-on: https://chromium-review.googlesource.com/c/1336208Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Commit-Queue: Brian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608493}
parent 52c43975
......@@ -1026,6 +1026,18 @@ HistogramBase* LinearHistogram::FactoryGetWithRangeDescription(
uint32_t bucket_count,
int32_t flags,
const DescriptionPair descriptions[]) {
// Originally, histograms were required to have at least one sample value
// plus underflow and overflow buckets. For single-entry enumerations,
// that one value is usually zero (which IS the underflow bucket)
// resulting in a |maximum| value of 1 (the exclusive upper-bound) and only
// the two outlier buckets. Handle this by making max==2 and buckets==3.
// This usually won't have any cost since the single-value-optimization
// will be used until the count exceeds 16 bits.
if (maximum == 1 && bucket_count == 2) {
maximum = 2;
bucket_count = 3;
}
bool valid_arguments = Histogram::InspectConstructionArguments(
name, &minimum, &maximum, &bucket_count);
DCHECK(valid_arguments);
......
......@@ -295,6 +295,25 @@ TEST_P(HistogramTest, LinearRangesTest) {
EXPECT_TRUE(ranges2.Equals(histogram2->bucket_ranges()));
}
TEST_P(HistogramTest, SingleValueEnumerationHistogram) {
// Make sure its possible to construct a linear histogram with only the two
// required outlier buckets (underflow and overflow).
HistogramBase* histogram = LinearHistogram::FactoryGet(
"SingleValueEnum", 1, 1, 2, HistogramBase::kNoFlags);
EXPECT_TRUE(histogram);
// Make sure the macros work properly. This can only be run when
// there is no persistent allocator which can be discarded and leave
// dangling pointers.
if (!use_persistent_histogram_allocator_) {
enum EnumWithMax {
kSomething = 0,
kMaxValue = kSomething,
};
UMA_HISTOGRAM_ENUMERATION("h1", kSomething);
}
}
TEST_P(HistogramTest, ArrayToCustomEnumRangesTest) {
const HistogramBase::Sample ranges[3] = {5, 10, 20};
std::vector<HistogramBase::Sample> ranges_vec =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment