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

Side by Side Diff: base/metrics/statistics_recorder.h

Issue 2036643004: Create ForTesting method rather than declaring a dozen "friend" classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 6 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 | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // StatisticsRecorder holds all Histograms and BucketRanges that are used by 5 // StatisticsRecorder holds all Histograms and BucketRanges that are used by
6 // Histograms in the system. It provides a general place for 6 // Histograms in the system. It provides a general place for
7 // Histograms/BucketRanges to register, and supports a global API for accessing 7 // Histograms/BucketRanges to register, and supports a global API for accessing
8 // (i.e., dumping, or graphing) the data. 8 // (i.e., dumping, or graphing) the data.
9 9
10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_ 10 #ifndef BASE_METRICS_STATISTICS_RECORDER_H_
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 static OnSampleCallback FindCallback(const std::string& histogram_name); 165 static OnSampleCallback FindCallback(const std::string& histogram_name);
166 166
167 // Returns the number of known histograms. 167 // Returns the number of known histograms.
168 static size_t GetHistogramCount(); 168 static size_t GetHistogramCount();
169 169
170 // Removes a histogram from the internal set of known ones. This can be 170 // Removes a histogram from the internal set of known ones. This can be
171 // necessary during testing persistent histograms where the underlying 171 // necessary during testing persistent histograms where the underlying
172 // memory is being released. 172 // memory is being released.
173 static void ForgetHistogramForTesting(base::StringPiece name); 173 static void ForgetHistogramForTesting(base::StringPiece name);
174 174
175 // Reset any global instance of the statistics-recorder that was created 175 // Creates a local StatisticsRecorder object for testing purposes. All new
176 // histograms will be registered in it until it is destructed or pushed
177 // aside for the lifetime of yet another SR object. The destruction of the
178 // returned object will re-activate the previous one. Always release SR
179 // objects in the opposite order to which they're created.
180 static std::unique_ptr<StatisticsRecorder> CreateTemporaryForTesting()
181 WARN_UNUSED_RESULT;
182
183 // Resets any global instance of the statistics-recorder that was created
176 // by a call to Initialize(). 184 // by a call to Initialize().
177 static void UninitializeForTesting(); 185 static void UninitializeForTesting();
178 186
179 private: 187 private:
180 // We keep a map of callbacks to histograms, so that as histograms are 188 // We keep a map of callbacks to histograms, so that as histograms are
181 // created, we can set the callback properly. 189 // created, we can set the callback properly.
182 typedef std::map<std::string, OnSampleCallback> CallbackMap; 190 typedef std::map<std::string, OnSampleCallback> CallbackMap;
183 191
184 // We keep all |bucket_ranges_| in a map, from checksum to a list of 192 // We keep all |bucket_ranges_| in a map, from checksum to a list of
185 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in 193 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in
186 // |bucket_ranges_|. 194 // |bucket_ranges_|.
187 typedef std::map<uint32_t, std::list<const BucketRanges*>*> RangesMap; 195 typedef std::map<uint32_t, std::list<const BucketRanges*>*> RangesMap;
188 196
189 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; 197 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>;
190 friend class ::SubprocessMetricsProviderTest;
191 friend class HistogramBaseTest;
192 friend class HistogramSnapshotManagerTest;
193 friend class HistogramTest;
194 friend class JsonPrefStoreTest;
195 friend class PersistentHistogramAllocatorTest;
196 friend class SharedHistogramTest;
197 friend class SparseHistogramTest;
198 friend class StatisticsRecorderTest;
199 FRIEND_TEST_ALL_PREFIXES(HistogramDeltaSerializationTest,
200 DeserializeHistogramAndAddSamples);
201 198
202 // Imports histograms from global persistent memory. The global lock must 199 // Imports histograms from global persistent memory. The global lock must
203 // not be held during this call. 200 // not be held during this call.
204 static void ImportGlobalPersistentHistograms(); 201 static void ImportGlobalPersistentHistograms();
205 202
206 // The constructor just initializes static members. Usually client code should 203 // The constructor just initializes static members. Usually client code should
207 // use Initialize to do this. But in test code, you can friend this class and 204 // use Initialize to do this. But in test code, you can friend this class and
208 // call the constructor to get a clean StatisticsRecorder. 205 // call the constructor to get a clean StatisticsRecorder.
209 StatisticsRecorder(); 206 StatisticsRecorder();
210 207
(...skipping 13 matching lines...) Expand all
224 221
225 // Lock protects access to above maps. 222 // Lock protects access to above maps.
226 static base::Lock* lock_; 223 static base::Lock* lock_;
227 224
228 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); 225 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder);
229 }; 226 };
230 227
231 } // namespace base 228 } // namespace base
232 229
233 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ 230 #endif // BASE_METRICS_STATISTICS_RECORDER_H_
OLDNEW
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698