Commit c25b8d44 authored by Joshua Berenhaus's avatar Joshua Berenhaus Committed by Commit Bot

Fixing expiration of ScaledLinearHistogram to no longer segfault

Bug: 1088051
Change-Id: Ib400d10aa0c7e92d1bd0fa8a7071ed89a7306a3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2293262
Commit-Queue: Joshua Berenhaus <joshber@microsoft.com>
Auto-Submit: Joshua Berenhaus <joshber@microsoft.com>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787784}
parent f4ea1654
......@@ -1084,12 +1084,19 @@ ScaledLinearHistogram::ScaledLinearHistogram(const std::string& name,
CHECK_EQ(static_cast<Sample>(bucket_count), maximum - minimum + 2)
<< " ScaledLinearHistogram requires buckets of size 1";
// Normally, |histogram_| should have type LINEAR_HISTOGRAM or be
// inherited from it. However, if it's expired, it will be DUMMY_HISTOGRAM.
if (histogram_->GetHistogramType() == DUMMY_HISTOGRAM)
return;
remainders_.resize(histogram_->bucket_count(), 0);
}
ScaledLinearHistogram::~ScaledLinearHistogram() = default;
void ScaledLinearHistogram::AddScaledCount(Sample value, int count) {
if (histogram_->GetHistogramType() == DUMMY_HISTOGRAM)
return;
if (count == 0)
return;
if (count < 0) {
......
......@@ -872,6 +872,13 @@ TEST_P(HistogramTest, ExpiredHistogramTest) {
samples = linear_expired->SnapshotDelta();
EXPECT_EQ(0, samples->TotalCount());
ScaledLinearHistogram scaled_linear_expired(kExpiredHistogramName, 1, 5, 6,
100, HistogramBase::kNoFlags);
scaled_linear_expired.AddScaledCount(0, 1);
scaled_linear_expired.AddScaledCount(1, 49);
samples = scaled_linear_expired.histogram()->SnapshotDelta();
EXPECT_EQ(0, samples->TotalCount());
std::vector<int> custom_ranges;
custom_ranges.push_back(1);
custom_ranges.push_back(5);
......
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