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

Unified Diff: base/metrics/histogram_unittest.cc

Issue 2867303004: [histogram] Make histograms more resistant to overflows. (Closed)
Patch Set: addressed comments from isherman@ Created 3 years, 7 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
« base/metrics/histogram.cc ('K') | « base/metrics/histogram_base.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_unittest.cc
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index d89e7e93247d8b60896aa46b6bd4fa3dafe03b39..8d8d6aaac7e84f1926176abbd7ddae9f31978bc2 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -401,6 +401,22 @@ TEST_P(HistogramTest, AddCount_LargeValuesDontOverflow) {
EXPECT_EQ(19400000000LL, samples2->sum());
}
+// Make sure that counts returned by Histogram::SnapshotDelta do not overflow
+// even when a total count (returned by Histogram::SnapshotSample) does.
+TEST_P(HistogramTest, AddCount_LargeCountsDontOverflow) {
+ const size_t kBucketCount = 50;
+ Histogram* histogram = static_cast<Histogram*>(Histogram::FactoryGet(
+ "AddCountHistogram", 10, 50, kBucketCount, HistogramBase::kNoFlags));
bcwhite 2017/05/10 12:40:33 You have 50 buckets for a range of 40.
altimin 2017/05/10 13:08:55 Done.
+
+ // Repeat N times to make sure that there is no internal value overflow.
+ for (int i = 0; i < 10; ++i) {
+ histogram->AddCount(42, 1 << 30);
+ std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta();
+ EXPECT_EQ(1 << 30, samples->TotalCount());
+ EXPECT_EQ(1 << 30, samples->GetCount(42));
+ }
+}
+
// Make sure histogram handles out-of-bounds data gracefully.
TEST_P(HistogramTest, BoundsTest) {
const size_t kBucketCount = 50;
« base/metrics/histogram.cc ('K') | « base/metrics/histogram_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698