Chromium Code Reviews| 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 MetricsDisplay { | |
|
Ilya Sherman
2016/04/13 00:29:32
Optional nit: Perhaps MetricsDisplayer?
bcwhite
2016/04/13 11:58:18
Done.
| |
| 39 public: | |
| 40 // Writes a title string (without formatting) to |output|. | |
| 41 virtual void WriteTitleString(std::string* output) = 0; | |
| 42 | |
| 43 // Writes graphs for all known histograms to |output|, optionally with | |
| 44 // |html| formatting. If |query| is non-empty, only histograms with | |
| 45 // that substring will be included. | |
| 46 virtual void WriteGraphs(const std::string& query, | |
| 47 bool html, | |
|
Ilya Sherman
2016/04/13 00:29:32
nit: Could you use an enum rather than a bool here
bcwhite
2016/04/13 11:58:18
Done.
| |
| 48 std::string* output) = 0; | |
| 49 }; | |
| 50 | |
| 36 // A class used as a key for the histogram map below. It always references | 51 // 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. | 52 // a string owned outside of this class, likely in the value of the map. |
| 38 class StringKey : public StringPiece { | 53 class StringKey : public StringPiece { |
| 39 public: | 54 public: |
| 40 // Constructs the StringKey using various sources. The source must live | 55 // Constructs the StringKey using various sources. The source must live |
| 41 // at least as long as the created object. | 56 // at least as long as the created object. |
| 42 StringKey(const std::string& str) : StringPiece(str) {} | 57 StringKey(const std::string& str) : StringPiece(str) {} |
| 43 StringKey(StringPiece str) : StringPiece(str) {} | 58 StringKey(StringPiece str) : StringPiece(str) {} |
| 44 | 59 |
| 45 // Though StringPiece is better passed by value than by reference, in | 60 // 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); | 173 static void ClearCallback(const std::string& histogram_name); |
| 159 | 174 |
| 160 // FindCallback retrieves the callback for the histogram referred to by | 175 // FindCallback retrieves the callback for the histogram referred to by |
| 161 // |histogram_name|, or a null callback if no callback exists for this | 176 // |histogram_name|, or a null callback if no callback exists for this |
| 162 // histogram. This method is thread safe. | 177 // histogram. This method is thread safe. |
| 163 static OnSampleCallback FindCallback(const std::string& histogram_name); | 178 static OnSampleCallback FindCallback(const std::string& histogram_name); |
| 164 | 179 |
| 165 // Returns the number of known histograms. | 180 // Returns the number of known histograms. |
| 166 static size_t GetHistogramCount(); | 181 static size_t GetHistogramCount(); |
| 167 | 182 |
| 183 // Adds an object that can display metrics. | |
| 184 static void RegisterMetricsDisplay(MetricsDisplay* display); | |
| 185 | |
| 186 // Removes an object that can display metrics. | |
| 187 static void DeregisterMetricsDisplay(MetricsDisplay* display); | |
| 188 | |
| 168 // Removes a histogram from the internal set of known ones. This can be | 189 // Removes a histogram from the internal set of known ones. This can be |
| 169 // necessary during testing persistent histograms where the underlying | 190 // necessary during testing persistent histograms where the underlying |
| 170 // memory is being released. | 191 // memory is being released. |
| 171 static void ForgetHistogramForTesting(base::StringPiece name); | 192 static void ForgetHistogramForTesting(base::StringPiece name); |
| 172 | 193 |
| 173 // Reset any global instance of the statistics-recorder that was created | 194 // Reset any global instance of the statistics-recorder that was created |
| 174 // by a call to Initialize(). | 195 // by a call to Initialize(). |
| 175 static void UninitializeForTesting(); | 196 static void UninitializeForTesting(); |
| 176 | 197 |
| 177 private: | 198 private: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 237 |
| 217 // Lock protects access to above maps. | 238 // Lock protects access to above maps. |
| 218 static base::Lock* lock_; | 239 static base::Lock* lock_; |
| 219 | 240 |
| 220 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 241 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 221 }; | 242 }; |
| 222 | 243 |
| 223 } // namespace base | 244 } // namespace base |
| 224 | 245 |
| 225 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 246 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
| OLD | NEW |