Chromium Code Reviews| 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 <memory> |
| 10 #include <ostream> | 10 #include <ostream> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.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 #include "base/time/time.h" | |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 | 21 |
| 21 struct Bucket; | 22 struct Bucket; |
| 22 class HistogramSamples; | 23 class HistogramSamples; |
| 23 | 24 |
| 24 // HistogramTester provides a simple interface for examining histograms, UMA | 25 // HistogramTester provides a simple interface for examining histograms, UMA |
| 25 // or otherwise. Tests can use this interface to verify that histogram data is | 26 // or otherwise. Tests can use this interface to verify that histogram data is |
| 26 // getting logged as intended. | 27 // getting logged as intended. |
| 27 class HistogramTester { | 28 class HistogramTester { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 46 void ExpectBucketCount(const std::string& name, | 47 void ExpectBucketCount(const std::string& name, |
| 47 base::HistogramBase::Sample sample, | 48 base::HistogramBase::Sample sample, |
| 48 base::HistogramBase::Count expected_count) const; | 49 base::HistogramBase::Count expected_count) const; |
| 49 | 50 |
| 50 // We don't know the values of the samples, but we know how many there are. | 51 // We don't know the values of the samples, but we know how many there are. |
| 51 // This measures the diff from the snapshot taken when this object was | 52 // This measures the diff from the snapshot taken when this object was |
| 52 // constructed. | 53 // constructed. |
| 53 void ExpectTotalCount(const std::string& name, | 54 void ExpectTotalCount(const std::string& name, |
| 54 base::HistogramBase::Count count) const; | 55 base::HistogramBase::Count count) const; |
| 55 | 56 |
| 57 // We know exact number of samples for buckets corresponding to a | |
| 58 // time interval. Other intervals may have samples too. | |
| 59 void ExpectTimeBucketCount(const std::string& name, | |
| 60 const base::TimeDelta& sample, | |
|
Alexei Svitkine (slow)
2016/11/12 00:51:14
Nit: I think base::TimeDelta should be passed by v
nikunjb
2016/11/12 01:35:15
Done. Also fixed the TimeDelta used in histogram_f
| |
| 61 base::HistogramBase::Count count) const; | |
| 62 | |
| 56 // Returns a list of all of the buckets recorded since creation of this | 63 // Returns a list of all of the buckets recorded since creation of this |
| 57 // object, as vector<Bucket>, where the Bucket represents the min boundary of | 64 // object, as vector<Bucket>, where the Bucket represents the min boundary of |
| 58 // the bucket and the count of samples recorded to that bucket since creation. | 65 // the bucket and the count of samples recorded to that bucket since creation. |
| 59 // | 66 // |
| 60 // Example usage, using gMock: | 67 // Example usage, using gMock: |
| 61 // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), | 68 // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), |
| 62 // ElementsAre(Bucket(1, 5), Bucket(2, 10), Bucket(3, 5))); | 69 // ElementsAre(Bucket(1, 5), Bucket(2, 10), Bucket(3, 5))); |
| 63 // | 70 // |
| 64 // If you build the expected list programmatically, you can use ContainerEq: | 71 // If you build the expected list programmatically, you can use ContainerEq: |
| 65 // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), | 72 // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 134 |
| 128 base::HistogramBase::Sample min; | 135 base::HistogramBase::Sample min; |
| 129 base::HistogramBase::Count count; | 136 base::HistogramBase::Count count; |
| 130 }; | 137 }; |
| 131 | 138 |
| 132 void PrintTo(const Bucket& value, std::ostream* os); | 139 void PrintTo(const Bucket& value, std::ostream* os); |
| 133 | 140 |
| 134 } // namespace base | 141 } // namespace base |
| 135 | 142 |
| 136 #endif // BASE_TEST_HISTOGRAM_TESTER_H_ | 143 #endif // BASE_TEST_HISTOGRAM_TESTER_H_ |
| OLD | NEW |