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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 if (!include_persistent_ && (iter_->second->flags() & | 60 if (!include_persistent_ && (iter_->second->flags() & |
61 HistogramBase::kIsPersistent)) { | 61 HistogramBase::kIsPersistent)) { |
62 continue; | 62 continue; |
63 } | 63 } |
64 break; | 64 break; |
65 } | 65 } |
66 | 66 |
67 return *this; | 67 return *this; |
68 } | 68 } |
69 | 69 |
70 StatisticsRecorder::~StatisticsRecorder() { | |
71 DCHECK(histograms_ && ranges_ && lock_); | |
Alexei Svitkine (slow)
2016/03/07 21:14:51
Nit: Not sure why I missed that in the previous CL
bcwhite
2016/03/07 22:20:41
Done.
| |
72 | |
73 // Global clean up. | |
74 Reset(); | |
75 } | |
76 | |
70 // static | 77 // static |
71 void StatisticsRecorder::Initialize() { | 78 void StatisticsRecorder::Initialize() { |
72 // Ensure that an instance of the StatisticsRecorder object is created. | 79 // Ensure that an instance of the StatisticsRecorder object is created. |
73 g_statistics_recorder_.Get(); | 80 g_statistics_recorder_.Get(); |
74 } | 81 } |
75 | 82 |
76 // static | 83 // static |
77 bool StatisticsRecorder::IsActive() { | 84 bool StatisticsRecorder::IsActive() { |
78 if (lock_ == NULL) | 85 if (lock_ == NULL) |
79 return false; | 86 return false; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 base::AutoLock auto_lock(*lock_); | 369 base::AutoLock auto_lock(*lock_); |
363 if (histograms_ == NULL) | 370 if (histograms_ == NULL) |
364 return OnSampleCallback(); | 371 return OnSampleCallback(); |
365 | 372 |
366 auto callback_iterator = callbacks_->find(name); | 373 auto callback_iterator = callbacks_->find(name); |
367 return callback_iterator != callbacks_->end() ? callback_iterator->second | 374 return callback_iterator != callbacks_->end() ? callback_iterator->second |
368 : OnSampleCallback(); | 375 : OnSampleCallback(); |
369 } | 376 } |
370 | 377 |
371 // static | 378 // static |
379 size_t StatisticsRecorder::GetHistogramCount() { | |
380 if (!lock_) | |
381 return 0; | |
382 | |
383 base::AutoLock auto_lock(*lock_); | |
384 if (!histograms_) | |
385 return 0; | |
386 return histograms_->size(); | |
387 } | |
388 | |
389 // static | |
372 void StatisticsRecorder::ResetForTesting() { | 390 void StatisticsRecorder::ResetForTesting() { |
373 // Just call the private version that is used also by the destructor. | 391 // Just call the private version that is used also by the destructor. |
374 Reset(); | 392 Reset(); |
375 } | 393 } |
376 | 394 |
377 // static | 395 // static |
378 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { | 396 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { |
379 if (histograms_) | 397 if (histograms_) |
380 histograms_->erase(HashMetricName(name.as_string())); | 398 histograms_->erase(HashMetricName(name.as_string())); |
381 } | 399 } |
(...skipping 14 matching lines...) Expand all Loading... | |
396 } | 414 } |
397 base::AutoLock auto_lock(*lock_); | 415 base::AutoLock auto_lock(*lock_); |
398 histograms_ = new HistogramMap; | 416 histograms_ = new HistogramMap; |
399 callbacks_ = new CallbackMap; | 417 callbacks_ = new CallbackMap; |
400 ranges_ = new RangesMap; | 418 ranges_ = new RangesMap; |
401 | 419 |
402 if (VLOG_IS_ON(1)) | 420 if (VLOG_IS_ON(1)) |
403 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); | 421 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); |
404 } | 422 } |
405 | 423 |
406 StatisticsRecorder::~StatisticsRecorder() { | |
407 DCHECK(histograms_ && ranges_ && lock_); | |
408 | |
409 // Global clean up. | |
410 Reset(); | |
411 } | |
412 | |
413 // static | 424 // static |
414 void StatisticsRecorder::Reset() { | 425 void StatisticsRecorder::Reset() { |
415 // If there's no lock then there is nothing to reset. | 426 // If there's no lock then there is nothing to reset. |
416 if (!lock_) | 427 if (!lock_) |
417 return; | 428 return; |
418 | 429 |
419 scoped_ptr<HistogramMap> histograms_deleter; | 430 scoped_ptr<HistogramMap> histograms_deleter; |
420 scoped_ptr<CallbackMap> callbacks_deleter; | 431 scoped_ptr<CallbackMap> callbacks_deleter; |
421 scoped_ptr<RangesMap> ranges_deleter; | 432 scoped_ptr<RangesMap> ranges_deleter; |
422 // We don't delete lock_ on purpose to avoid having to properly protect | 433 // We don't delete lock_ on purpose to avoid having to properly protect |
(...skipping 21 matching lines...) Expand all Loading... | |
444 // static | 455 // static |
445 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 456 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
446 // static | 457 // static |
447 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 458 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
448 // static | 459 // static |
449 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 460 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
450 // static | 461 // static |
451 base::Lock* StatisticsRecorder::lock_ = NULL; | 462 base::Lock* StatisticsRecorder::lock_ = NULL; |
452 | 463 |
453 } // namespace base | 464 } // namespace base |
OLD | NEW |