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

Unified Diff: base/metrics/histogram_base_unittest.cc

Issue 1726873002: Report histogram creation results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some 'git cl format' changes 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_base_unittest.cc
diff --git a/base/metrics/histogram_base_unittest.cc b/base/metrics/histogram_base_unittest.cc
index 2d6b6df0288850cab31362762957070201ca72e3..1e3e4a7bb917875aa439d22ef4d0d480fe468fec 100644
--- a/base/metrics/histogram_base_unittest.cc
+++ b/base/metrics/histogram_base_unittest.cc
@@ -18,19 +18,26 @@ class HistogramBaseTest : public testing::Test {
HistogramBaseTest() {
// Each test will have a clean state (no Histogram / BucketRanges
// registered).
- statistics_recorder_ = NULL;
ResetStatisticsRecorder();
}
- ~HistogramBaseTest() override { delete statistics_recorder_; }
+ ~HistogramBaseTest() override {
+ HistogramBase::report_histogram_ = nullptr;
+ delete statistics_recorder_;
+ }
void ResetStatisticsRecorder() {
delete statistics_recorder_;
statistics_recorder_ = new StatisticsRecorder();
Alexei Svitkine (slow) 2016/03/01 16:41:34 Nit: While you're changing this, can you make this
bcwhite 2016/03/02 19:14:19 StatisticsRecorder is explicit about what classes
Alexei Svitkine (slow) 2016/03/03 17:56:23 I think making the dtor public should be fine, sin
bcwhite 2016/03/07 13:39:25 Done.
}
+ HistogramBase* GetCreationReportHistogram(StringPiece name) {
+ HistogramBase::EnableCreationReportHistogram(name);
+ return HistogramBase::report_histogram_;
+ }
+
private:
- StatisticsRecorder* statistics_recorder_;
+ StatisticsRecorder* statistics_recorder_ = nullptr;
};
Alexei Svitkine (slow) 2016/03/01 16:41:34 Nit: Add DISALLOW_COPY_AND_ASSIGN().
bcwhite 2016/03/02 19:14:19 Done.
TEST_F(HistogramBaseTest, DeserializeHistogram) {
@@ -152,4 +159,61 @@ TEST_F(HistogramBaseTest, DeserializeSparseHistogram) {
EXPECT_EQ(0, deserialized->flags());
}
+TEST_F(HistogramBaseTest, CreationReportHistogram) {
+ // Enabled creation report. Itself is not included in the report.
+ HistogramBase* report = GetCreationReportHistogram("CreationReportTest");
+ ASSERT_TRUE(report);
+
+ std::vector<HistogramBase::Sample> ranges;
+ ranges.push_back(1);
+ ranges.push_back(2);
+ ranges.push_back(4);
+ ranges.push_back(8);
+ ranges.push_back(10);
+
+ // Create all histogram types and verify counts.
+ Histogram::FactoryGet("CRH-Histogram", 1, 10, 5, 0);
+ LinearHistogram::FactoryGet("CRH-Linear", 1, 10, 5, 0);
+ BooleanHistogram::FactoryGet("CRH-Boolean", 0);
+ CustomHistogram::FactoryGet("CRH-Custom", ranges, 0);
+ SparseHistogram::FactoryGet("CRH-Sparse", 0);
+
+ scoped_ptr<HistogramSamples> samples = report->SnapshotSamples();
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_CREATED));
+ EXPECT_EQ(5, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_CREATED));
+ EXPECT_EQ(0, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP));
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_TYPE_GENERAL));
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_TYPE_LINEAR));
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_TYPE_BOOLEAN));
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_TYPE_CUSTOM));
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_TYPE_SPARSE));
+
+ // Create all flag types and verify counts.
+ Histogram::FactoryGet("CRH-Histogram-UMA-Targeted", 1, 10, 5,
+ HistogramBase::kUmaTargetedHistogramFlag);
+ Histogram::FactoryGet("CRH-Histogram-UMA-Stability", 1, 10, 5,
+ HistogramBase::kUmaStabilityHistogramFlag);
+ SparseHistogram::FactoryGet("CRH-Sparse-UMA-Targeted",
+ HistogramBase::kUmaTargetedHistogramFlag);
+ SparseHistogram::FactoryGet("CRH-Sparse-UMA-Stability",
+ HistogramBase::kUmaStabilityHistogramFlag);
+ samples = report->SnapshotSamples();
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_CREATED));
+ EXPECT_EQ(9, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_CREATED));
+ EXPECT_EQ(0, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP));
+ EXPECT_EQ(2, samples->GetCount(HISTOGRAM_REPORT_FLAG_UMA_TARGETED));
+ EXPECT_EQ(2, samples->GetCount(HISTOGRAM_REPORT_FLAG_UMA_STABILITY));
+
+ // Do lookup of existing histograms and verify counts.
+ Histogram::FactoryGet("CRH-Histogram", 1, 10, 5, 0);
+ LinearHistogram::FactoryGet("CRH-Linear", 1, 10, 5, 0);
+ BooleanHistogram::FactoryGet("CRH-Boolean", 0);
+ CustomHistogram::FactoryGet("CRH-Custom", ranges, 0);
+ SparseHistogram::FactoryGet("CRH-Sparse", 0);
+ samples = report->SnapshotSamples();
+ EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_CREATED));
+ EXPECT_EQ(9, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_CREATED));
+ EXPECT_EQ(5, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP));
+}
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698