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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // ClearCallback clears any callback set on the histogram referred to by | 88 // ClearCallback clears any callback set on the histogram referred to by |
89 // |histogram_name|. This method is thread safe. | 89 // |histogram_name|. This method is thread safe. |
90 static void ClearCallback(const std::string& histogram_name); | 90 static void ClearCallback(const std::string& histogram_name); |
91 | 91 |
92 // FindCallback retrieves the callback for the histogram referred to by | 92 // FindCallback retrieves the callback for the histogram referred to by |
93 // |histogram_name|, or a null callback if no callback exists for this | 93 // |histogram_name|, or a null callback if no callback exists for this |
94 // histogram. This method is thread safe. | 94 // histogram. This method is thread safe. |
95 static OnSampleCallback FindCallback(const std::string& histogram_name); | 95 static OnSampleCallback FindCallback(const std::string& histogram_name); |
96 | 96 |
97 private: | 97 private: |
98 // HistogramNameRef holds a weak const ref to the name field of the associated | 98 // We keep all registered histograms in a map, indexed by the hash of the |
99 // Histogram object, allowing re-use of the underlying string storage for the | 99 // name of the histogram. |
100 // map keys. The wrapper is required as using "const std::string&" as the key | 100 typedef std::map<uint64_t, HistogramBase*> HistogramMap; |
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 | 101 |
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 |
(...skipping 21 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 |