Index: base/test/histogram_tester.h |
diff --git a/base/test/histogram_tester.h b/base/test/histogram_tester.h |
index 7ac7ca67e7efac0db0f4d8fe1921b719c77aedef..294704a20e8a8e0ae78f53ae2789388908c4fde5 100644 |
--- a/base/test/histogram_tester.h |
+++ b/base/test/histogram_tester.h |
@@ -67,12 +67,33 @@ 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; |
twifkak
2015/07/23 21:21:54
Oops, good catch.
ncarter (slow)
2015/07/23 21:50:43
Acknowledged.
|
+ |
+ // 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-matchers.h" |
twifkak
2015/07/23 21:21:54
The documentation at https://wiki.corp.google.com/
ncarter (slow)
2015/07/23 21:50:43
Done.
|
+ // ... |
+ // 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)); |
+ using CountsMap = std::map<std::string, base::HistogramBase::Count>; |
twifkak
2015/07/23 21:21:54
Using decls aren't explicitly called out in the st
ncarter (slow)
2015/07/23 21:50:43
Yeah, I'm torn about this generally. I'm usually a
|
+ 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 |