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

Unified Diff: base/test/histogram_tester.h

Issue 1190423006: base/test/histogram_tester.h: Add a way to query a whole family of related (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes from twifkak Created 5 years, 5 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
« no previous file with comments | « no previous file | base/test/histogram_tester.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | base/test/histogram_tester.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698