| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // Clean out what this object created and then restore what existed before. | 86 // Clean out what this object created and then restore what existed before. |
| 87 Reset(); | 87 Reset(); |
| 88 base::AutoLock auto_lock(*lock_); | 88 base::AutoLock auto_lock(*lock_); |
| 89 histograms_ = existing_histograms_.release(); | 89 histograms_ = existing_histograms_.release(); |
| 90 callbacks_ = existing_callbacks_.release(); | 90 callbacks_ = existing_callbacks_.release(); |
| 91 ranges_ = existing_ranges_.release(); | 91 ranges_ = existing_ranges_.release(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // static | 94 // static |
| 95 void StatisticsRecorder::Initialize() { | 95 void StatisticsRecorder::Initialize() { |
| 96 // Tests sometimes create local StatisticsRecorders in order to provide a |
| 97 // contained environment of histograms that can be later discarded. If a |
| 98 // true global instance gets created in this environment then it will |
| 99 // eventually get disconnected when the local instance destructs and |
| 100 // restores the previous state, resulting in no StatisticsRecorder at all. |
| 101 // The global lazy instance, however, will remain valid thus ensuring that |
| 102 // another never gets installed via this method. If a |histograms_| map |
| 103 // exists then assume the StatisticsRecorder is already "initialized". |
| 104 if (histograms_) |
| 105 return; |
| 106 |
| 96 // Ensure that an instance of the StatisticsRecorder object is created. | 107 // Ensure that an instance of the StatisticsRecorder object is created. |
| 97 g_statistics_recorder_.Get(); | 108 g_statistics_recorder_.Get(); |
| 98 } | 109 } |
| 99 | 110 |
| 100 // static | 111 // static |
| 101 bool StatisticsRecorder::IsActive() { | 112 bool StatisticsRecorder::IsActive() { |
| 102 if (lock_ == NULL) | 113 if (lock_ == NULL) |
| 103 return false; | 114 return false; |
| 104 base::AutoLock auto_lock(*lock_); | 115 base::AutoLock auto_lock(*lock_); |
| 105 return NULL != histograms_; | 116 return NULL != histograms_; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 // static | 545 // static |
| 535 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 546 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
| 536 // static | 547 // static |
| 537 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 548 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
| 538 // static | 549 // static |
| 539 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 550 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
| 540 // static | 551 // static |
| 541 base::Lock* StatisticsRecorder::lock_ = NULL; | 552 base::Lock* StatisticsRecorder::lock_ = NULL; |
| 542 | 553 |
| 543 } // namespace base | 554 } // namespace base |
| OLD | NEW |