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 10 matching lines...) Expand all Loading... | |
| 21 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
| 22 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
| 23 #include "base/metrics/histogram_base.h" | 23 #include "base/metrics/histogram_base.h" |
| 24 | 24 |
| 25 namespace base { | 25 namespace base { |
| 26 | 26 |
| 27 class BucketRanges; | 27 class BucketRanges; |
| 28 class Lock; | 28 class Lock; |
| 29 | 29 |
| 30 class BASE_EXPORT StatisticsRecorder { | 30 class BASE_EXPORT StatisticsRecorder { |
| 31 private: | |
|
Alexei Svitkine (slow)
2015/11/25 18:05:27
Why is there a private section at the top?
bcwhite
2015/11/25 21:54:17
Paste-o. Fixed.
| |
| 32 // We keep all registered histograms in a map, from name to histogram. | |
| 33 typedef std::map<uint64_t, HistogramBase*> HistogramMap; | |
| 34 | |
| 31 public: | 35 public: |
| 32 typedef std::vector<HistogramBase*> Histograms; | 36 typedef std::vector<HistogramBase*> Histograms; |
| 33 | 37 |
| 34 // Initializes the StatisticsRecorder system. Safe to call multiple times. | 38 // Initializes the StatisticsRecorder system. Safe to call multiple times. |
| 35 static void Initialize(); | 39 static void Initialize(); |
| 36 | 40 |
| 37 // Find out if histograms can now be registered into our list. | 41 // Find out if histograms can now be registered into our list. |
| 38 static bool IsActive(); | 42 static bool IsActive(); |
| 39 | 43 |
| 40 // Register, or add a new histogram to the collection of statistics. If an | 44 // Register, or add a new histogram to the collection of statistics. If an |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // ClearCallback clears any callback set on the histogram referred to by | 92 // ClearCallback clears any callback set on the histogram referred to by |
| 89 // |histogram_name|. This method is thread safe. | 93 // |histogram_name|. This method is thread safe. |
| 90 static void ClearCallback(const std::string& histogram_name); | 94 static void ClearCallback(const std::string& histogram_name); |
| 91 | 95 |
| 92 // FindCallback retrieves the callback for the histogram referred to by | 96 // FindCallback retrieves the callback for the histogram referred to by |
| 93 // |histogram_name|, or a null callback if no callback exists for this | 97 // |histogram_name|, or a null callback if no callback exists for this |
| 94 // histogram. This method is thread safe. | 98 // histogram. This method is thread safe. |
| 95 static OnSampleCallback FindCallback(const std::string& histogram_name); | 99 static OnSampleCallback FindCallback(const std::string& histogram_name); |
| 96 | 100 |
| 97 private: | 101 private: |
| 98 // HistogramNameRef holds a weak const ref to the name field of the associated | |
| 99 // Histogram object, allowing re-use of the underlying string storage for the | |
| 100 // map keys. The wrapper is required as using "const std::string&" as the key | |
| 101 // results in compile errors. | |
| 102 struct HistogramNameRef { | |
| 103 explicit HistogramNameRef(const std::string& name) : name_(name) {}; | |
| 104 | |
| 105 // Operator < is necessary to use this type as a std::map key. | |
| 106 bool operator<(const HistogramNameRef& other) const { | |
| 107 return name_ < other.name_; | |
| 108 } | |
| 109 | |
| 110 // Weak, owned by the associated Histogram object. | |
| 111 const std::string& name_; | |
| 112 }; | |
| 113 | |
| 114 // We keep all registered histograms in a map, from name to histogram. | |
| 115 typedef std::map<HistogramNameRef, HistogramBase*> HistogramMap; | |
| 116 | |
| 117 // We keep a map of callbacks to histograms, so that as histograms are | 102 // We keep a map of callbacks to histograms, so that as histograms are |
| 118 // created, we can set the callback properly. | 103 // created, we can set the callback properly. |
| 119 typedef std::map<std::string, OnSampleCallback> CallbackMap; | 104 typedef std::map<std::string, OnSampleCallback> CallbackMap; |
| 120 | 105 |
| 121 // We keep all |bucket_ranges_| in a map, from checksum to a list of | 106 // We keep all |bucket_ranges_| in a map, from checksum to a list of |
| 122 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in | 107 // |bucket_ranges_|. Checksum is calculated from the |ranges_| in |
| 123 // |bucket_ranges_|. | 108 // |bucket_ranges_|. |
| 124 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; | 109 typedef std::map<uint32, std::list<const BucketRanges*>*> RangesMap; |
| 125 | 110 |
| 126 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; | 111 friend struct DefaultLazyInstanceTraits<StatisticsRecorder>; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 147 | 132 |
| 148 // Lock protects access to above maps. | 133 // Lock protects access to above maps. |
| 149 static base::Lock* lock_; | 134 static base::Lock* lock_; |
| 150 | 135 |
| 151 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); | 136 DISALLOW_COPY_AND_ASSIGN(StatisticsRecorder); |
| 152 }; | 137 }; |
| 153 | 138 |
| 154 } // namespace base | 139 } // namespace base |
| 155 | 140 |
| 156 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ | 141 #endif // BASE_METRICS_STATISTICS_RECORDER_H_ |
| OLD | NEW |