Index: base/test/histogram_tester.h |
diff --git a/base/test/histogram_tester.h b/base/test/histogram_tester.h |
index 7ac7ca67e7efac0db0f4d8fe1921b719c77aedef..cfab3c60f24e267c9b6e0a08dcde3421764201f8 100644 |
--- a/base/test/histogram_tester.h |
+++ b/base/test/histogram_tester.h |
@@ -26,6 +26,8 @@ class HistogramSamples; |
// getting logged as intended. |
class HistogramTester { |
public: |
+ using CountsMap = std::map<std::string, base::HistogramBase::Count>; |
+ |
// The constructor will call StatisticsRecorder::Initialize() for you. Also, |
// this takes a snapshot of all current histograms counts. |
HistogramTester(); |
@@ -67,12 +69,32 @@ class HistogramTester { |
// slightly less helpful failure message: |
// EXPECT_EQ(expected_buckets, |
// histogram_tester.GetAllSamples("HistogramName")); |
- std::vector<Bucket> GetAllSamples(const std::string& name); |
+ std::vector<Bucket> GetAllSamples(const std::string& name) const; |
+ |
+ // Finds histograms whose names start with |query|, and returns them along |
+ // with the counts of any samples added since the creation of this object. |
+ // Histograms that are unchanged are omitted from the result. The return value |
+ // is a map whose keys are the histogram name, and whose values are the sample |
+ // count. |
+ // |
+ // This is useful for cases where the code under test is choosing among a |
+ // family of related histograms and incrementing one of them. Typically you |
+ // should pass the result of this function directly to EXPECT_THAT. |
+ // |
+ // Example usage, using gmock (which produces better failure messages): |
+ // #include "testing/gmock/include/gmock/gmock.h" |
+ // ... |
+ // base::HistogramTester::CountsMap expected_counts; |
+ // expected_counts["MyMetric.A"] = 1; |
+ // expected_counts["MyMetric.B"] = 1; |
+ // EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("MyMetric."), |
+ // testing::ContainerEq(expected_counts)); |
+ CountsMap GetTotalCountsForPrefix(const std::string& query) const; |
// Access a modified HistogramSamples containing only what has been logged |
// to the histogram since the creation of this object. |
scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( |
- const std::string& histogram_name); |
+ const std::string& histogram_name) const; |
private: |
// Verifies and asserts that value in the |sample| bucket matches the |