Chromium Code Reviews| Index: base/test/histogram_tester.h |
| diff --git a/base/test/histogram_tester.h b/base/test/histogram_tester.h |
| index 96317f98d2d33283ed09a8d3e69487312af1dd38..1b773f4aa2593f176008857b07effc53620247b6 100644 |
| --- a/base/test/histogram_tester.h |
| +++ b/base/test/histogram_tester.h |
| @@ -6,7 +6,10 @@ |
| #define BASE_TEST_HISTOGRAM_TESTER_H_ |
| #include <map> |
| +#include <ostream> |
| #include <string> |
| +#include <utility> |
| +#include <vector> |
| #include "base/basictypes.h" |
| #include "base/memory/scoped_ptr.h" |
| @@ -15,6 +18,7 @@ |
| namespace base { |
| +class Bucket; |
| class HistogramSamples; |
| // HistogramTester provides a simple interface for examining histograms, UMA |
| @@ -47,6 +51,24 @@ class HistogramTester { |
| void ExpectTotalCount(const std::string& name, |
| base::HistogramBase::Count count) const; |
| + // Returns a list of all of the buckets recorded since creation of this |
| + // object, as pair<Sample, Count>, where the Sample is the min boundary of the |
|
Ilya Sherman
2015/06/27 07:25:19
nit: Please update "pair<Sample, Count>"
twifkak
2015/06/29 21:52:29
Done.
|
| + // bucket and the Count is the count recorded since creation. |
| + // |
| + // Example usage, using gMock: |
| + // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), |
| + // ElementsAre(Bucket(1, 5), Bucket(2, 10), Bucket(3, 5))); |
| + // |
| + // If you build the expected list programmatically, you can use ContainerEq: |
| + // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), |
| + // ContainerEq(expected_buckets)); |
| + // |
| + // or EXPECT_EQ if you prefer not to depend on gMock, at the expense of a |
| + // slightly less helpful failure message: |
| + // EXPECT_EQ(expected_buckets, |
| + // histogram_tester.GetAllSamples("HistogramName")); |
| + std::vector<Bucket> GetAllSamples(const std::string& name); |
| + |
| // Access a modified HistogramSamples containing only what has been logged |
| // to the histogram since the creation of this object. |
| scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( |
| @@ -76,6 +98,22 @@ class HistogramTester { |
| DISALLOW_COPY_AND_ASSIGN(HistogramTester); |
| }; |
| +class Bucket { |
| + public: |
| + Bucket(base::HistogramBase::Sample min, base::HistogramBase::Count count) |
| + : min_(min), count_(count) {} |
| + |
| + bool operator==(const Bucket& other) const; |
| + |
| + private: |
| + friend void PrintTo(const Bucket& value, std::ostream* os); |
| + |
| + base::HistogramBase::Sample min_; |
| + base::HistogramBase::Count count_; |
|
Ilya Sherman
2015/06/27 07:25:19
Optional nit: It's probably fine to make this a st
Ilya Sherman
2015/06/27 07:25:19
nit: Can these be const?
twifkak
2015/06/29 21:52:29
Done.
twifkak
2015/06/29 21:52:29
Done.
|
| +}; |
| + |
| +void PrintTo(const Bucket& value, std::ostream* os); |
| + |
| } // namespace base |
| #endif // BASE_TEST_HISTOGRAM_TESTER_H_ |