OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 #include "base/metrics/histogram_base.h" | 26 #include "base/metrics/histogram_base.h" |
27 #include "base/strings/string_piece.h" | 27 #include "base/strings/string_piece.h" |
28 | 28 |
29 namespace base { | 29 namespace base { |
30 | 30 |
31 class BucketRanges; | 31 class BucketRanges; |
32 class Lock; | 32 class Lock; |
33 | 33 |
34 class BASE_EXPORT StatisticsRecorder { | 34 class BASE_EXPORT StatisticsRecorder { |
35 public: | 35 public: |
| 36 // An interface class for registering objects that can display histograms |
| 37 // on the chrome://histograms page. |
| 38 class MetricsDisplayer { |
| 39 public: |
| 40 enum DisplayType { |
| 41 DISPLAY_TEXT_PLAIN, |
| 42 DISPLAY_TEXT_HTML, |
| 43 }; |
| 44 |
| 45 // Writes a title string (without formatting) to |output|. |
| 46 virtual void WriteTitleString(std::string* output) = 0; |
| 47 |
| 48 // Writes graphs for all known histograms to |output|, optionally with |
| 49 // |html| formatting. If |query| is non-empty, only histograms with |
| 50 // that substring will be included. |
| 51 virtual void WriteGraphs(const std::string& query, |
| 52 DisplayType format, |
| 53 std::string* output) = 0; |
| 54 }; |
| 55 |
36 // A class used as a key for the histogram map below. It always references | 56 // A class used as a key for the histogram map below. It always references |
37 // a string owned outside of this class, likely in the value of the map. | 57 // a string owned outside of this class, likely in the value of the map. |
38 class StringKey : public StringPiece { | 58 class StringKey : public StringPiece { |
39 public: | 59 public: |
40 // Constructs the StringKey using various sources. The source must live | 60 // Constructs the StringKey using various sources. The source must live |
41 // at least as long as the created object. | 61 // at least as long as the created object. |
42 StringKey(const std::string& str) : StringPiece(str) {} | 62 StringKey(const std::string& str) : StringPiece(str) {} |
43 StringKey(StringPiece str) : StringPiece(str) {} | 63 StringKey(StringPiece str) : StringPiece(str) {} |
44 | 64 |
45 // Though StringPiece is better passed by value than by reference, in | 65 // Though StringPiece is better passed by value than by reference, in |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 static void ClearCallback(const std::string& histogram_name); | 178 static void ClearCallback(const std::string& histogram_name); |
159 | 179 |
160 // FindCallback retrieves the callback for the histogram referred to by | 180 // FindCallback retrieves the callback for the histogram referred to by |
161 // |histogram_name|, or a null callback if no callback exists for this | 181 // |histogram_name|, or a null callback if no callback exists for this |
162 // histogram. This method is thread safe. | 182 // histogram. This method is thread safe. |
163 static OnSampleCallback FindCallback(const std::string& histogram_name); | 183 static OnSampleCallback FindCallback(const std::string& histogram_name); |
164 | 184 |
165 // Returns the number of known histograms. | 185 // Returns the number of known histograms. |
166 static size_t GetHistogramCount(); | 186 static size_t GetHistogramCount(); |
167 | 187 |
| 188 // Adds an object that can display metrics. |
| 189 static void RegisterMetricsDisplayer(MetricsDisplayer* display); |
| 190 |
| 191 // Removes an object that can display metrics. |
| 192 static void DeregisterMetricsDisplayer(MetricsDisplayer* display); |
| 193 |
168 // Removes a histogram from the internal set of known ones. This can be | 194 // Removes a histogram from the internal set of known ones. This can be |
169 // necessary during testing persistent histograms where the underlying | 195 // necessary during testing persistent histograms where the underlying |
170 // memory is being released. | 196 // memory is being released. |
171 static void ForgetHistogramForTesting(base::StringPiece name); | 197 static void ForgetHistogramForTesting(base::StringPiece name); |
172 | 198 |
173 // Reset any global instance of the statistics-recorder that was created | 199 // Reset any global instance of the statistics-recorder that was created |
174 // by a call to Initialize(). | 200 // by a call to Initialize(). |
175 static void UninitializeForTesting(); | 201 static void UninitializeForTesting(); |
176 | 202 |
177 private: | 203 private: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 246 |
221 // Lock protects access to above maps. | 247 // Lock protects access to above maps. |
222 static base::Lock* lock_; | 248 static base::Lock* lock_; |
223 | 249 |
224 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 250 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
225 }; | 251 }; |
226 | 252 |
227 } // namespace base | 253 } // namespace base |
228 | 254 |
229 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 255 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
OLD | NEW |