Chromium Code Reviews| Index: base/metrics/statistics_recorder.cc |
| diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc |
| index d0fa2add3603b3f574dfa9ef9e5ee2e6b152aafc..8959472bb83904c56fee4ce80fc7a2b8f7b03d6f 100644 |
| --- a/base/metrics/statistics_recorder.cc |
| +++ b/base/metrics/statistics_recorder.cc |
| @@ -22,6 +22,8 @@ namespace { |
| base::LazyInstance<base::StatisticsRecorder>::Leaky g_statistics_recorder_ = |
| LAZY_INSTANCE_INITIALIZER; |
| +bool g_vlog_initialized = false; |
|
Alexei Svitkine (slow)
2016/04/14 20:47:39
Can this just be a member of the StatisticsRecorde
|
| + |
| bool HistogramNameLesser(const base::HistogramBase* a, |
| const base::HistogramBase* b) { |
| return a->histogram_name() < b->histogram_name(); |
| @@ -298,6 +300,19 @@ StatisticsRecorder::HistogramIterator StatisticsRecorder::end() { |
| } |
| // static |
| +void StatisticsRecorder::InitLogOnShutdown() { |
| + if (lock_ == nullptr) |
| + return; |
| + base::AutoLock auto_lock(*lock_); |
| + g_statistics_recorder_.Get().InitLogOnShutdownWithoutLock(); |
| +} |
| + |
| +// static |
| +bool StatisticsRecorder::VLogInitializedForTesting() { |
| + return g_vlog_initialized; |
| +} |
| + |
| +// static |
| void StatisticsRecorder::GetSnapshot(const std::string& query, |
| Histograms* snapshot) { |
| if (lock_ == NULL) |
| @@ -399,8 +414,7 @@ StatisticsRecorder::StatisticsRecorder() { |
| callbacks_ = new CallbackMap; |
| ranges_ = new RangesMap; |
| - if (VLOG_IS_ON(1)) |
| - AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); |
| + InitLogOnShutdownWithoutLock(); |
| } |
| StatisticsRecorder::~StatisticsRecorder() { |
| @@ -410,6 +424,13 @@ StatisticsRecorder::~StatisticsRecorder() { |
| Reset(); |
| } |
| +void StatisticsRecorder::InitLogOnShutdownWithoutLock() { |
| + if (!g_vlog_initialized && VLOG_IS_ON(1)) { |
| + g_vlog_initialized = true; |
| + AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); |
| + } |
| +} |
| + |
| // static |
| void StatisticsRecorder::Reset() { |
| // If there's no lock then there is nothing to reset. |