| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef BASE_TEST_HISTOGRAM_TESTER_H_ | 5 #ifndef BASE_TEST_HISTOGRAM_TESTER_H_ | 
| 6 #define BASE_TEST_HISTOGRAM_TESTER_H_ | 6 #define BASE_TEST_HISTOGRAM_TESTER_H_ | 
| 7 | 7 | 
| 8 #include <map> | 8 #include <map> | 
|  | 9 #include <memory> | 
| 9 #include <ostream> | 10 #include <ostream> | 
| 10 #include <string> | 11 #include <string> | 
| 11 #include <utility> | 12 #include <utility> | 
| 12 #include <vector> | 13 #include <vector> | 
| 13 | 14 | 
| 14 #include "base/macros.h" | 15 #include "base/macros.h" | 
| 15 #include "base/memory/scoped_ptr.h" |  | 
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" | 
| 17 #include "base/metrics/histogram_base.h" | 17 #include "base/metrics/histogram_base.h" | 
| 18 | 18 | 
| 19 namespace base { | 19 namespace base { | 
| 20 | 20 | 
| 21 struct Bucket; | 21 struct Bucket; | 
| 22 class HistogramSamples; | 22 class HistogramSamples; | 
| 23 | 23 | 
| 24 // HistogramTester provides a simple interface for examining histograms, UMA | 24 // HistogramTester provides a simple interface for examining histograms, UMA | 
| 25 // or otherwise. Tests can use this interface to verify that histogram data is | 25 // or otherwise. Tests can use this interface to verify that histogram data is | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 86   // ... | 86   // ... | 
| 87   //   base::HistogramTester::CountsMap expected_counts; | 87   //   base::HistogramTester::CountsMap expected_counts; | 
| 88   //   expected_counts["MyMetric.A"] = 1; | 88   //   expected_counts["MyMetric.A"] = 1; | 
| 89   //   expected_counts["MyMetric.B"] = 1; | 89   //   expected_counts["MyMetric.B"] = 1; | 
| 90   //   EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("MyMetric."), | 90   //   EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix("MyMetric."), | 
| 91   //               testing::ContainerEq(expected_counts)); | 91   //               testing::ContainerEq(expected_counts)); | 
| 92   CountsMap GetTotalCountsForPrefix(const std::string& query) const; | 92   CountsMap GetTotalCountsForPrefix(const std::string& query) const; | 
| 93 | 93 | 
| 94   // Access a modified HistogramSamples containing only what has been logged | 94   // Access a modified HistogramSamples containing only what has been logged | 
| 95   // to the histogram since the creation of this object. | 95   // to the histogram since the creation of this object. | 
| 96   scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( | 96   std::unique_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( | 
| 97       const std::string& histogram_name) const; | 97       const std::string& histogram_name) const; | 
| 98 | 98 | 
| 99  private: | 99  private: | 
| 100   // Verifies and asserts that value in the |sample| bucket matches the | 100   // Verifies and asserts that value in the |sample| bucket matches the | 
| 101   // |expected_count|. The bucket's current value is determined from |samples| | 101   // |expected_count|. The bucket's current value is determined from |samples| | 
| 102   // and is modified based on the snapshot stored for histogram |name|. | 102   // and is modified based on the snapshot stored for histogram |name|. | 
| 103   void CheckBucketCount(const std::string& name, | 103   void CheckBucketCount(const std::string& name, | 
| 104                         base::HistogramBase::Sample sample, | 104                         base::HistogramBase::Sample sample, | 
| 105                         base::Histogram::Count expected_count, | 105                         base::Histogram::Count expected_count, | 
| 106                         const base::HistogramSamples& samples) const; | 106                         const base::HistogramSamples& samples) const; | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 128 | 128 | 
| 129   base::HistogramBase::Sample min; | 129   base::HistogramBase::Sample min; | 
| 130   base::HistogramBase::Count count; | 130   base::HistogramBase::Count count; | 
| 131 }; | 131 }; | 
| 132 | 132 | 
| 133 void PrintTo(const Bucket& value, std::ostream* os); | 133 void PrintTo(const Bucket& value, std::ostream* os); | 
| 134 | 134 | 
| 135 }  // namespace base | 135 }  // namespace base | 
| 136 | 136 | 
| 137 #endif  // BASE_TEST_HISTOGRAM_TESTER_H_ | 137 #endif  // BASE_TEST_HISTOGRAM_TESTER_H_ | 
| OLD | NEW | 
|---|