| 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/debug/leak_annotations.h" | 7 #include "base/debug/leak_annotations.h" |
| 8 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 12 | 13 |
| 14 namespace { |
| 15 // Initialize histogram statistics gathering system. |
| 16 base::LazyInstance<base::StatisticsRecorder>::Leaky |
| 17 g_statistics_recorder_ = LAZY_INSTANCE_INITIALIZER; |
| 18 } // namespace |
| 19 |
| 13 namespace base { | 20 namespace base { |
| 14 | 21 |
| 15 // Collect the number of histograms created. | 22 // Collect the number of histograms created. |
| 16 static uint32 number_of_histograms_ = 0; | 23 static uint32 number_of_histograms_ = 0; |
| 17 // Collect the number of vectors saved because of caching ranges. | 24 // Collect the number of vectors saved because of caching ranges. |
| 18 static uint32 number_of_vectors_saved_ = 0; | 25 static uint32 number_of_vectors_saved_ = 0; |
| 19 // Collect the number of ranges_ elements saved because of caching ranges. | 26 // Collect the number of ranges_ elements saved because of caching ranges. |
| 20 static size_t saved_ranges_size_ = 0; | 27 static size_t saved_ranges_size_ = 0; |
| 21 | 28 |
| 22 // This singleton instance should be started during the single threaded portion | 29 // This singleton instance should be started during the single threaded portion |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 ranges_ = NULL; | 67 ranges_ = NULL; |
| 61 } | 68 } |
| 62 // We are going to leak the histograms and the ranges. | 69 // We are going to leak the histograms and the ranges. |
| 63 delete histograms; | 70 delete histograms; |
| 64 delete ranges; | 71 delete ranges; |
| 65 // We don't delete lock_ on purpose to avoid having to properly protect | 72 // We don't delete lock_ on purpose to avoid having to properly protect |
| 66 // against it going away after we checked for NULL in the static methods. | 73 // against it going away after we checked for NULL in the static methods. |
| 67 } | 74 } |
| 68 | 75 |
| 69 // static | 76 // static |
| 77 void StatisticsRecorder::Initialize() { |
| 78 // Ensure that an instance of the StatisticsRecorder object is created. |
| 79 g_statistics_recorder_.Get(); |
| 80 } |
| 81 |
| 82 |
| 83 // static |
| 70 bool StatisticsRecorder::IsActive() { | 84 bool StatisticsRecorder::IsActive() { |
| 71 if (lock_ == NULL) | 85 if (lock_ == NULL) |
| 72 return false; | 86 return false; |
| 73 base::AutoLock auto_lock(*lock_); | 87 base::AutoLock auto_lock(*lock_); |
| 74 return NULL != histograms_; | 88 return NULL != histograms_; |
| 75 } | 89 } |
| 76 | 90 |
| 77 Histogram* StatisticsRecorder::RegisterOrDeleteDuplicate(Histogram* histogram) { | 91 Histogram* StatisticsRecorder::RegisterOrDeleteDuplicate(Histogram* histogram) { |
| 78 // As per crbug.com/79322 the histograms are intentionally leaked, so we need | 92 // As per crbug.com/79322 the histograms are intentionally leaked, so we need |
| 79 // to annotate them. Because ANNOTATE_LEAKING_OBJECT_PTR may be used only once | 93 // to annotate them. Because ANNOTATE_LEAKING_OBJECT_PTR may be used only once |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // static | 290 // static |
| 277 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 291 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
| 278 // static | 292 // static |
| 279 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 293 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
| 280 // static | 294 // static |
| 281 base::Lock* StatisticsRecorder::lock_ = NULL; | 295 base::Lock* StatisticsRecorder::lock_ = NULL; |
| 282 // static | 296 // static |
| 283 bool StatisticsRecorder::dump_on_exit_ = false; | 297 bool StatisticsRecorder::dump_on_exit_ = false; |
| 284 | 298 |
| 285 } // namespace base | 299 } // namespace base |
| OLD | NEW |