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 <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 void ExpectBucketCount(const std::string& name, | 40 void ExpectBucketCount(const std::string& name, |
| 41 base::HistogramBase::Sample sample, | 41 base::HistogramBase::Sample sample, |
| 42 base::HistogramBase::Count expected_count) const; | 42 base::HistogramBase::Count expected_count) const; |
| 43 | 43 |
| 44 // We don't know the values of the samples, but we know how many there are. | 44 // We don't know the values of the samples, but we know how many there are. |
| 45 // This measures the diff from the snapshot taken when this object was | 45 // This measures the diff from the snapshot taken when this object was |
| 46 // constructed. | 46 // constructed. |
| 47 void ExpectTotalCount(const std::string& name, | 47 void ExpectTotalCount(const std::string& name, |
| 48 base::HistogramBase::Count count) const; | 48 base::HistogramBase::Count count) const; |
| 49 | 49 |
| 50 // Finds histograms whose names start with |query|, and return a text | |
|
Ilya Sherman
2015/06/23 00:57:40
nit: "return" -> "returns"
| |
| 51 // representation of any new samples added since the creation of this object. | |
| 52 // Histograms that are unchanged are omitted from the result. The return value | |
| 53 // consists of lines of the form: | |
| 54 // | |
| 55 // - "My.Statistic.Name[2]=5" (for linear, boolean, and enum histograms) | |
| 56 // - "My.Statistic.Name=5" (for other kinds of histograms) | |
| 57 // | |
| 58 // In the above example, 2 is the bucket min and 5 is the count. For nonlinear | |
| 59 // histograms, only the total across all buckets is shown, under the | |
| 60 // assumption that the inputs to nonlinear histograms -- sizes and times, | |
| 61 // commonly -- may be hard for a test to predict. | |
| 62 // | |
| 63 // This is useful for cases where the code under test is choosing among a | |
| 64 // family of related histograms and incrementing one of them. Typically you | |
| 65 // should pass the result of this function directly to EXPECT_EQ, which does a | |
| 66 // good job of formatting human-readable diffs of multi-line strings. | |
|
Ilya Sherman
2015/06/23 00:57:40
nit: You should probably mention somewhere that th
| |
| 67 std::string GetTotalCountsForQuery(const std::string& query) const; | |
| 68 | |
| 50 // Access a modified HistogramSamples containing only what has been logged | 69 // Access a modified HistogramSamples containing only what has been logged |
| 51 // to the histogram since the creation of this object. | 70 // to the histogram since the creation of this object. |
| 52 scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( | 71 scoped_ptr<HistogramSamples> GetHistogramSamplesSinceCreation( |
| 53 const std::string& histogram_name); | 72 const std::string& histogram_name); |
| 54 | 73 |
| 55 private: | 74 private: |
| 56 // Verifies and asserts that value in the |sample| bucket matches the | 75 // Verifies and asserts that value in the |sample| bucket matches the |
| 57 // |expected_count|. The bucket's current value is determined from |samples| | 76 // |expected_count|. The bucket's current value is determined from |samples| |
| 58 // and is modified based on the snapshot stored for histogram |name|. | 77 // and is modified based on the snapshot stored for histogram |name|. |
| 59 void CheckBucketCount(const std::string& name, | 78 void CheckBucketCount(const std::string& name, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 72 // lifecycle. This instance takes ownership of the samples, which are deleted | 91 // lifecycle. This instance takes ownership of the samples, which are deleted |
| 73 // when the instance is destroyed. | 92 // when the instance is destroyed. |
| 74 std::map<std::string, HistogramSamples*> histograms_snapshot_; | 93 std::map<std::string, HistogramSamples*> histograms_snapshot_; |
| 75 | 94 |
| 76 DISALLOW_COPY_AND_ASSIGN(HistogramTester); | 95 DISALLOW_COPY_AND_ASSIGN(HistogramTester); |
| 77 }; | 96 }; |
| 78 | 97 |
| 79 } // namespace base | 98 } // namespace base |
| 80 | 99 |
| 81 #endif // BASE_TEST_HISTOGRAM_TESTER_H_ | 100 #endif // BASE_TEST_HISTOGRAM_TESTER_H_ |
| OLD | NEW |