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

Unified Diff: base/metrics/sparse_histogram_unittest.cc

Issue 2867303004: [histogram] Make histograms more resistant to overflows. (Closed)
Patch Set: addressed comments from bcwhite@ 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/sparse_histogram.cc ('K') | « base/metrics/sparse_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/sparse_histogram_unittest.cc
diff --git a/base/metrics/sparse_histogram_unittest.cc b/base/metrics/sparse_histogram_unittest.cc
index 40e6fbf644bdf4ac8024259534fed9b01126c70d..a6fb3efea730797c050bce0a1864f8b138ff4f2d 100644
--- a/base/metrics/sparse_histogram_unittest.cc
+++ b/base/metrics/sparse_histogram_unittest.cc
@@ -149,6 +149,25 @@ TEST_P(SparseHistogramTest, AddCount_LargeValuesDontOverflow) {
EXPECT_EQ(55250000000LL, snapshot2->sum());
}
+// Make sure that counts returned by Histogram::SnapshotDelta do not overflow
+// even when a total count (returned by Histogram::SnapshotSample) does.
+TEST_P(SparseHistogramTest, AddCount_LargeCountsDontOverflow) {
+ std::unique_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse"));
+ std::unique_ptr<HistogramSamples> snapshot(histogram->SnapshotSamples());
+ EXPECT_EQ(0, snapshot->TotalCount());
+ EXPECT_EQ(0, snapshot->sum());
+
+ const int count = (1 << 30) - 1;
+
+ // Repeat N times to make sure that there is no internal value overflow.
+ for (int i = 0; i < 10; ++i) {
+ histogram->AddCount(42, count);
+ std::unique_ptr<HistogramSamples> samples = histogram->SnapshotDelta();
+ EXPECT_EQ(count, samples->TotalCount());
+ EXPECT_EQ(count, samples->GetCount(42));
+ }
+}
+
TEST_P(SparseHistogramTest, MacroBasicTest) {
UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 100);
UMA_HISTOGRAM_SPARSE_SLOWLY("Sparse", 200);
« base/metrics/sparse_histogram.cc ('K') | « base/metrics/sparse_histogram.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698