Chromium Code Reviews| Index: base/metrics/histogram_snapshot_manager_unittest.cc |
| diff --git a/base/metrics/histogram_snapshot_manager_unittest.cc b/base/metrics/histogram_snapshot_manager_unittest.cc |
| index 72db7d58674520206bb96c77e0abc7fffc9a9493..bf7b0209515fa941eda6deaccc643ad05e890132 100644 |
| --- a/base/metrics/histogram_snapshot_manager_unittest.cc |
| +++ b/base/metrics/histogram_snapshot_manager_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/macros.h" |
| #include "base/metrics/histogram_delta_serialization.h" |
| #include "base/metrics/histogram_macros.h" |
| +#include "base/metrics/sample_vector.h" |
| #include "base/metrics/statistics_recorder.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -22,6 +23,12 @@ class HistogramFlattenerDeltaRecorder : public HistogramFlattener { |
| void RecordDelta(const HistogramBase& histogram, |
| const HistogramSamples& snapshot) override { |
| recorded_delta_histogram_names_.push_back(histogram.histogram_name()); |
| + ASSERT_EQ(recorded_delta_histogram_sum_.end(), |
| + recorded_delta_histogram_sum_.find( |
| + histogram.histogram_name())); |
| + // Keep pointer to snapshot for testing. This really isn't ideal but the |
| + // snapshot-manager keeps the snapshot alive until it's "forgotten". |
| + recorded_delta_histogram_sum_[histogram.histogram_name()] = snapshot.sum(); |
| } |
| void InconsistencyDetected(HistogramBase::Inconsistency problem) override { |
| @@ -37,12 +44,25 @@ class HistogramFlattenerDeltaRecorder : public HistogramFlattener { |
| ASSERT_TRUE(false); |
| } |
| + void Reset() { |
| + recorded_delta_histogram_names_.clear(); |
| + recorded_delta_histogram_sum_.clear(); |
| + } |
| + |
| std::vector<std::string> GetRecordedDeltaHistogramNames() { |
| return recorded_delta_histogram_names_; |
| } |
| + int64_t GetRecordedDeltaHistogramSum( |
| + const std::string& name) { |
|
Alexei Svitkine (slow)
2016/02/18 15:47:40
Nit: Fits on previous line?
bcwhite
2016/02/18 17:07:04
Done.
|
| + EXPECT_NE(recorded_delta_histogram_sum_.end(), |
| + recorded_delta_histogram_sum_.find(name)); |
| + return recorded_delta_histogram_sum_[name]; |
| + } |
| + |
| private: |
| std::vector<std::string> recorded_delta_histogram_names_; |
| + std::map<std::string, int64_t> recorded_delta_histogram_sum_; |
| DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder); |
| }; |
| @@ -61,7 +81,7 @@ class HistogramSnapshotManagerTest : public testing::Test { |
| TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) { |
| // kNoFlags filter should record all histograms. |
| - UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 4); |
| UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| histogram_snapshot_manager_.PrepareDeltas( |
| @@ -77,7 +97,7 @@ TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) { |
| TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) { |
| // Note that kUmaStabilityHistogramFlag includes kUmaTargetedHistogramFlag. |
| - UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 4); |
| UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| histogram_snapshot_manager_.PrepareDeltas( |
| @@ -93,7 +113,7 @@ TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) { |
| TEST_F(HistogramSnapshotManagerTest, |
| PrepareDeltasUmaStabilityHistogramFlagFilter) { |
| - UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 4); |
| UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| histogram_snapshot_manager_.PrepareDeltas( |
| @@ -106,4 +126,35 @@ TEST_F(HistogramSnapshotManagerTest, |
| EXPECT_EQ("UmaStabilityHistogram", histograms[0]); |
| } |
| +TEST_F(HistogramSnapshotManagerTest, CheckMerge) { |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 4); |
| + UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| + |
| + base::HistogramBase* h1 = base::LinearHistogram::FactoryGet( |
| + "UmaHistogram", 1, 4, 5, 0); |
| + ASSERT_TRUE(h1); |
| + base::HistogramBase* h2 = base::LinearHistogram::FactoryGet( |
| + "UmaStabilityHistogram", 1, 2, 3, 0); |
| + ASSERT_TRUE(h2); |
| + |
| + histogram_snapshot_manager_.StartDeltas(); |
| + histogram_snapshot_manager_.PrepareDelta(h1); |
| + histogram_snapshot_manager_.PrepareDelta(h1); // Delta will be zero. |
| + histogram_snapshot_manager_.PrepareDelta(h2); |
| + h1->Add(2); |
| + h2->Add(1); |
| + histogram_snapshot_manager_.PrepareDelta(h2); |
| + histogram_snapshot_manager_.PrepareDelta(h1); |
| + histogram_snapshot_manager_.FinishDeltas(); |
| + { |
| + const std::vector<std::string>& histograms = |
|
Alexei Svitkine (slow)
2016/02/18 15:47:40
Nit: No &
The object is returned by value.
bcwhite
2016/02/18 17:07:04
Done.
|
| + histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames(); |
| + EXPECT_EQ(2U, histograms.size()); |
| + EXPECT_EQ(3, histogram_flattener_delta_recorder_. |
| + GetRecordedDeltaHistogramSum("UmaHistogram")); |
| + EXPECT_EQ(2, histogram_flattener_delta_recorder_. |
| + GetRecordedDeltaHistogramSum("UmaStabilityHistogram")); |
| + } |
| +} |
| + |
| } // namespace base |