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

Unified Diff: base/metrics/histogram_unittest.cc

Issue 1485763002: Merge multiple histogram snapshots into single one for reporting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: rebased Created 4 years, 10 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
Index: base/metrics/histogram_unittest.cc
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index 09f9106d09758837ce79ac15453bb5c198a3b9d8..81fb38c977ece78b7b0b6f006952665f55b1367f 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -208,6 +208,34 @@ TEST_F(HistogramTest, NameMatchTest) {
EXPECT_EQ(2, samples->GetCount(10));
}
+// Check that delta calculations work correct.
+TEST_F(HistogramTest, DeltaTest) {
+ HistogramBase* histogram =
+ Histogram::FactoryGet("DeltaHistogram", 1, 64, 8,
+ HistogramBase::kNoFlags);
+ histogram->Add(1);
+ histogram->Add(10);
+ histogram->Add(50);
+
+ scoped_ptr<HistogramSamples> samples = histogram->SnapshotDelta();
+ EXPECT_EQ(3, samples->TotalCount());
+ EXPECT_EQ(1, samples->GetCount(1));
+ EXPECT_EQ(1, samples->GetCount(10));
+ EXPECT_EQ(1, samples->GetCount(50));
+
+ samples = histogram->SnapshotDelta();
+ EXPECT_EQ(0, samples->TotalCount());
+
+ histogram->Add(10);
+ histogram->Add(10);
+ samples = histogram->SnapshotDelta();
+ EXPECT_EQ(2, samples->TotalCount());
+ EXPECT_EQ(2, samples->GetCount(10));
+
+ samples = histogram->SnapshotDelta();
+ EXPECT_EQ(0, samples->TotalCount());
+}
+
TEST_F(HistogramTest, ExponentialRangesTest) {
// Check that we got a nice exponential when there was enough room.
BucketRanges ranges(9);

Powered by Google App Engine
This is Rietveld 408576698