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

Side by Side Diff: base/test/histogram_tester.h

Issue 2796283005: Adding UseCounter specific for extensions (Closed)
Patch Set: Fix compile err Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/test/histogram_tester.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // If you build the expected list programmatically, you can use ContainerEq: 71 // If you build the expected list programmatically, you can use ContainerEq:
72 // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"), 72 // EXPECT_THAT(histogram_tester.GetAllSamples("HistogramName"),
73 // ContainerEq(expected_buckets)); 73 // ContainerEq(expected_buckets));
74 // 74 //
75 // or EXPECT_EQ if you prefer not to depend on gMock, at the expense of a 75 // or EXPECT_EQ if you prefer not to depend on gMock, at the expense of a
76 // slightly less helpful failure message: 76 // slightly less helpful failure message:
77 // EXPECT_EQ(expected_buckets, 77 // EXPECT_EQ(expected_buckets,
78 // histogram_tester.GetAllSamples("HistogramName")); 78 // histogram_tester.GetAllSamples("HistogramName"));
79 std::vector<Bucket> GetAllSamples(const std::string& name) const; 79 std::vector<Bucket> GetAllSamples(const std::string& name) const;
80 80
81 // Returns the value of the |sample| bucket for ths histogram |name|.
82 HistogramBase::Count GetBucketCount(const std::string& name,
83 HistogramBase::Sample sample) const;
84
81 // Finds histograms whose names start with |prefix|, and returns them along 85 // Finds histograms whose names start with |prefix|, and returns them along
82 // with the counts of any samples added since the creation of this object. 86 // with the counts of any samples added since the creation of this object.
83 // Histograms that are unchanged are omitted from the result. The return value 87 // Histograms that are unchanged are omitted from the result. The return value
84 // is a map whose keys are the histogram name, and whose values are the sample 88 // is a map whose keys are the histogram name, and whose values are the sample
85 // count. 89 // count.
86 // 90 //
87 // This is useful for cases where the code under test is choosing among a 91 // This is useful for cases where the code under test is choosing among a
88 // family of related histograms and incrementing one of them. Typically you 92 // family of related histograms and incrementing one of them. Typically you
89 // should pass the result of this function directly to EXPECT_THAT. 93 // should pass the result of this function directly to EXPECT_THAT.
90 // 94 //
(...skipping 21 matching lines...) Expand all
112 Histogram::Count expected_count, 116 Histogram::Count expected_count,
113 const HistogramSamples& samples) const; 117 const HistogramSamples& samples) const;
114 118
115 // Verifies that the total number of values recorded for the histogram |name| 119 // Verifies that the total number of values recorded for the histogram |name|
116 // is |expected_count|. This is checked against |samples| minus the snapshot 120 // is |expected_count|. This is checked against |samples| minus the snapshot
117 // that was taken for |name|. 121 // that was taken for |name|.
118 void CheckTotalCount(const std::string& name, 122 void CheckTotalCount(const std::string& name,
119 Histogram::Count expected_count, 123 Histogram::Count expected_count,
120 const HistogramSamples& samples) const; 124 const HistogramSamples& samples) const;
121 125
126 // Sets the value for |count| to be the value in the |sample| bucket. The
127 // bucket's current value is determined from |samples| and is modified based
128 // on the snapshot stored for histogram |name|.
129 void GetBucketCountForSamples(const std::string& name,
130 HistogramBase::Sample sample,
131 const HistogramSamples& samples,
132 HistogramBase::Count* count) const;
133
122 // Used to determine the histogram changes made during this instance's 134 // Used to determine the histogram changes made during this instance's
123 // lifecycle. 135 // lifecycle.
124 std::map<std::string, std::unique_ptr<HistogramSamples>> histograms_snapshot_; 136 std::map<std::string, std::unique_ptr<HistogramSamples>> histograms_snapshot_;
125 137
126 DISALLOW_COPY_AND_ASSIGN(HistogramTester); 138 DISALLOW_COPY_AND_ASSIGN(HistogramTester);
127 }; 139 };
128 140
129 struct Bucket { 141 struct Bucket {
130 Bucket(HistogramBase::Sample min, HistogramBase::Count count) 142 Bucket(HistogramBase::Sample min, HistogramBase::Count count)
131 : min(min), count(count) {} 143 : min(min), count(count) {}
132 144
133 bool operator==(const Bucket& other) const; 145 bool operator==(const Bucket& other) const;
134 146
135 HistogramBase::Sample min; 147 HistogramBase::Sample min;
136 HistogramBase::Count count; 148 HistogramBase::Count count;
137 }; 149 };
138 150
139 void PrintTo(const Bucket& value, std::ostream* os); 151 void PrintTo(const Bucket& value, std::ostream* os);
140 152
141 } // namespace base 153 } // namespace base
142 154
143 #endif // BASE_TEST_HISTOGRAM_TESTER_H_ 155 #endif // BASE_TEST_HISTOGRAM_TESTER_H_
OLDNEW
« 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