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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 for (const auto& range_entry : *entry.second) { | 278 for (const auto& range_entry : *entry.second) { |
279 output->push_back(range_entry); | 279 output->push_back(range_entry); |
280 } | 280 } |
281 } | 281 } |
282 } | 282 } |
283 | 283 |
284 // static | 284 // static |
285 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) { | 285 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) { |
286 if (lock_ == NULL) | 286 if (lock_ == NULL) |
287 return NULL; | 287 return NULL; |
288 base::AutoLock auto_lock(*lock_); | |
289 if (histograms_ == NULL) | |
290 return NULL; | |
291 | 288 |
292 // Import histograms from known persistent storage. Histograms could have | 289 // Import histograms from known persistent storage. Histograms could have |
293 // been added by other processes and they must be fetched and recognized | 290 // been added by other processes and they must be fetched and recognized |
294 // locally. If the persistent memory segment is not shared between processes, | 291 // locally. If the persistent memory segment is not shared between processes, |
295 // this call does nothing. | 292 // this call does nothing. |
| 293 // This must be called *before* the lock is acquired below because it will |
| 294 // call back into this object to register histograms. Those called methods |
| 295 // will acquire the lock at that time. |
296 GlobalHistogramAllocator* allocator = GlobalHistogramAllocator::Get(); | 296 GlobalHistogramAllocator* allocator = GlobalHistogramAllocator::Get(); |
297 if (allocator) | 297 if (allocator) |
298 allocator->ImportHistogramsToStatisticsRecorder(); | 298 allocator->ImportHistogramsToStatisticsRecorder(); |
299 | 299 |
| 300 base::AutoLock auto_lock(*lock_); |
| 301 if (histograms_ == NULL) |
| 302 return NULL; |
| 303 |
300 HistogramMap::iterator it = histograms_->find(name); | 304 HistogramMap::iterator it = histograms_->find(name); |
301 if (histograms_->end() == it) | 305 if (histograms_->end() == it) |
302 return NULL; | 306 return NULL; |
303 return it->second; | 307 return it->second; |
304 } | 308 } |
305 | 309 |
306 // static | 310 // static |
307 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin( | 311 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin( |
308 bool include_persistent) { | 312 bool include_persistent) { |
309 return HistogramIterator(histograms_->begin(), include_persistent); | 313 return HistogramIterator(histograms_->begin(), include_persistent); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 // static | 465 // static |
462 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 466 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
463 // static | 467 // static |
464 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 468 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
465 // static | 469 // static |
466 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 470 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
467 // static | 471 // static |
468 base::Lock* StatisticsRecorder::lock_ = NULL; | 472 base::Lock* StatisticsRecorder::lock_ = NULL; |
469 | 473 |
470 } // namespace base | 474 } // namespace base |
OLD | NEW |