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

Unified Diff: base/metrics/histogram_unittest.cc

Issue 2867303004: [histogram] Make histograms more resistant to overflows. (Closed)
Patch Set: 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.cc ('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..4a6137c5bf8c3fad34a5e12034114c71a8e7e4ea 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -401,6 +401,21 @@ TEST_P(HistogramTest, AddCount_LargeValuesDontOverflow) {
EXPECT_EQ(19400000000LL, samples2->sum());
}
+TEST_P(HistogramTest, AddCount_LargeCountsDontOverflow) {
Ilya Sherman 2017/05/09 22:15:32 Please add a comment documenting what this is inte
altimin 2017/05/10 11:50:38 Done.
+ const size_t kBucketCount = 50;
+ Histogram* histogram = static_cast<Histogram*>(
+ Histogram::FactoryGet("AddCountHistogram", 10, 1000000000, kBucketCount,
Ilya Sherman 2017/05/09 22:15:32 nit: Do you need such a large max bucket value? I
altimin 2017/05/10 11:50:38 Done.
+ HistogramBase::kNoFlags));
+
+ // 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.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698