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

Unified Diff: base/metrics/sparse_histogram_unittest.cc

Issue 2867303004: [histogram] Make histograms more resistant to overflows. (Closed)
Patch Set: final final fix 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
« no previous file with comments | « 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..3ad2bc86801c05111c2354224bef2100eabaffc1 100644
--- a/base/metrics/sparse_histogram_unittest.cc
+++ b/base/metrics/sparse_histogram_unittest.cc
@@ -10,6 +10,7 @@
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_samples.h"
+#include "base/metrics/metrics_hashes.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/metrics/persistent_memory_allocator.h"
#include "base/metrics/sample_map.h"
@@ -149,6 +150,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);
@@ -364,4 +384,11 @@ TEST_P(SparseHistogramTest, ExtremeValues) {
}
}
+TEST_P(SparseHistogramTest, HistogramNameHash) {
+ const char kName[] = "TestName";
+ HistogramBase* histogram = SparseHistogram::FactoryGet(
+ kName, HistogramBase::kUmaTargetedHistogramFlag);
+ EXPECT_EQ(histogram->name_hash(), HashMetricName(kName));
+}
+
} // namespace base
« no previous file with comments | « base/metrics/sparse_histogram.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698