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 #include "base/metrics/statistics_recorder.h" | 5 #include "base/metrics/statistics_recorder.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/debug/leak_annotations.h" | 8 #include "base/debug/leak_annotations.h" |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 HistogramBase* histogram_to_delete = NULL; | 52 HistogramBase* histogram_to_delete = NULL; |
53 HistogramBase* histogram_to_return = NULL; | 53 HistogramBase* histogram_to_return = NULL; |
54 { | 54 { |
55 base::AutoLock auto_lock(*lock_); | 55 base::AutoLock auto_lock(*lock_); |
56 if (histograms_ == NULL) { | 56 if (histograms_ == NULL) { |
57 histogram_to_return = histogram; | 57 histogram_to_return = histogram; |
58 } else { | 58 } else { |
59 const std::string& name = histogram->histogram_name(); | 59 const std::string& name = histogram->histogram_name(); |
60 HistogramMap::iterator it = histograms_->find(name); | 60 HistogramMap::iterator it = histograms_->find(HistogramNameRef(name)); |
61 if (histograms_->end() == it) { | 61 if (histograms_->end() == it) { |
62 (*histograms_)[name] = histogram; | 62 (*histograms_)[HistogramNameRef(name)] = histogram; |
63 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 | 63 ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322 |
64 histogram_to_return = histogram; | 64 histogram_to_return = histogram; |
65 } else if (histogram == it->second) { | 65 } else if (histogram == it->second) { |
66 // The histogram was registered before. | 66 // The histogram was registered before. |
67 histogram_to_return = histogram; | 67 histogram_to_return = histogram; |
68 } else { | 68 } else { |
69 // We already have one histogram with this name. | 69 // We already have one histogram with this name. |
70 histogram_to_return = it->second; | 70 histogram_to_return = it->second; |
71 histogram_to_delete = histogram; | 71 histogram_to_delete = histogram; |
72 } | 72 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 183 |
184 // static | 184 // static |
185 void StatisticsRecorder::GetHistograms(Histograms* output) { | 185 void StatisticsRecorder::GetHistograms(Histograms* output) { |
186 if (lock_ == NULL) | 186 if (lock_ == NULL) |
187 return; | 187 return; |
188 base::AutoLock auto_lock(*lock_); | 188 base::AutoLock auto_lock(*lock_); |
189 if (histograms_ == NULL) | 189 if (histograms_ == NULL) |
190 return; | 190 return; |
191 | 191 |
192 for (const auto& entry : *histograms_) { | 192 for (const auto& entry : *histograms_) { |
193 DCHECK_EQ(entry.first, entry.second->histogram_name()); | 193 DCHECK_EQ(entry.first.name_, entry.second->histogram_name()); |
194 output->push_back(entry.second); | 194 output->push_back(entry.second); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 // static | 198 // static |
199 void StatisticsRecorder::GetBucketRanges( | 199 void StatisticsRecorder::GetBucketRanges( |
200 std::vector<const BucketRanges*>* output) { | 200 std::vector<const BucketRanges*>* output) { |
201 if (lock_ == NULL) | 201 if (lock_ == NULL) |
202 return; | 202 return; |
203 base::AutoLock auto_lock(*lock_); | 203 base::AutoLock auto_lock(*lock_); |
204 if (ranges_ == NULL) | 204 if (ranges_ == NULL) |
205 return; | 205 return; |
206 | 206 |
207 for (const auto& entry : *ranges_) { | 207 for (const auto& entry : *ranges_) { |
208 for (const auto& range_entry : *entry.second) { | 208 for (const auto& range_entry : *entry.second) { |
209 output->push_back(range_entry); | 209 output->push_back(range_entry); |
210 } | 210 } |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 // static | 214 // static |
215 HistogramBase* StatisticsRecorder::FindHistogram(const std::string& name) { | 215 HistogramBase* StatisticsRecorder::FindHistogram(const std::string& name) { |
216 if (lock_ == NULL) | 216 if (lock_ == NULL) |
217 return NULL; | 217 return NULL; |
218 base::AutoLock auto_lock(*lock_); | 218 base::AutoLock auto_lock(*lock_); |
219 if (histograms_ == NULL) | 219 if (histograms_ == NULL) |
220 return NULL; | 220 return NULL; |
221 | 221 |
222 HistogramMap::iterator it = histograms_->find(name); | 222 HistogramMap::iterator it = histograms_->find(HistogramNameRef(name)); |
223 if (histograms_->end() == it) | 223 if (histograms_->end() == it) |
224 return NULL; | 224 return NULL; |
225 return it->second; | 225 return it->second; |
226 } | 226 } |
227 | 227 |
228 // private static | 228 // private static |
229 void StatisticsRecorder::GetSnapshot(const std::string& query, | 229 void StatisticsRecorder::GetSnapshot(const std::string& query, |
230 Histograms* snapshot) { | 230 Histograms* snapshot) { |
231 if (lock_ == NULL) | 231 if (lock_ == NULL) |
232 return; | 232 return; |
233 base::AutoLock auto_lock(*lock_); | 233 base::AutoLock auto_lock(*lock_); |
234 if (histograms_ == NULL) | 234 if (histograms_ == NULL) |
235 return; | 235 return; |
236 | 236 |
237 for (const auto& entry : *histograms_) { | 237 for (const auto& entry : *histograms_) { |
238 if (entry.first.find(query) != std::string::npos) | 238 if (entry.first.name_.find(query) != std::string::npos) |
239 snapshot->push_back(entry.second); | 239 snapshot->push_back(entry.second); |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 // This singleton instance should be started during the single threaded portion | 243 // This singleton instance should be started during the single threaded portion |
244 // of main(), and hence it is not thread safe. It initializes globals to | 244 // of main(), and hence it is not thread safe. It initializes globals to |
245 // provide support for all future calls. | 245 // provide support for all future calls. |
246 StatisticsRecorder::StatisticsRecorder() { | 246 StatisticsRecorder::StatisticsRecorder() { |
247 DCHECK(!histograms_); | 247 DCHECK(!histograms_); |
248 if (lock_ == NULL) { | 248 if (lock_ == NULL) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 289 |
290 | 290 |
291 // static | 291 // static |
292 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 292 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
293 // static | 293 // static |
294 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 294 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
295 // static | 295 // static |
296 base::Lock* StatisticsRecorder::lock_ = NULL; | 296 base::Lock* StatisticsRecorder::lock_ = NULL; |
297 | 297 |
298 } // namespace base | 298 } // namespace base |
OLD | NEW |