| 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> |
| 8 |
| 7 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 8 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| 9 #include "base/json/string_escape.h" | 11 #include "base/json/string_escape.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "base/metrics/metrics_hashes.h" | 14 #include "base/metrics/metrics_hashes.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Initialize histogram statistics gathering system. | 22 // Initialize histogram statistics gathering system. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 141 } |
| 141 } | 142 } |
| 142 delete histogram_to_delete; | 143 delete histogram_to_delete; |
| 143 return histogram_to_return; | 144 return histogram_to_return; |
| 144 } | 145 } |
| 145 | 146 |
| 146 // static | 147 // static |
| 147 const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges( | 148 const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges( |
| 148 const BucketRanges* ranges) { | 149 const BucketRanges* ranges) { |
| 149 DCHECK(ranges->HasValidChecksum()); | 150 DCHECK(ranges->HasValidChecksum()); |
| 150 scoped_ptr<const BucketRanges> ranges_deleter; | 151 std::unique_ptr<const BucketRanges> ranges_deleter; |
| 151 | 152 |
| 152 if (lock_ == NULL) { | 153 if (lock_ == NULL) { |
| 153 ANNOTATE_LEAKING_OBJECT_PTR(ranges); | 154 ANNOTATE_LEAKING_OBJECT_PTR(ranges); |
| 154 return ranges; | 155 return ranges; |
| 155 } | 156 } |
| 156 | 157 |
| 157 base::AutoLock auto_lock(*lock_); | 158 base::AutoLock auto_lock(*lock_); |
| 158 if (ranges_ == NULL) { | 159 if (ranges_ == NULL) { |
| 159 ANNOTATE_LEAKING_OBJECT_PTR(ranges); | 160 ANNOTATE_LEAKING_OBJECT_PTR(ranges); |
| 160 return ranges; | 161 return ranges; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (VLOG_IS_ON(1)) | 423 if (VLOG_IS_ON(1)) |
| 423 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); | 424 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); |
| 424 } | 425 } |
| 425 | 426 |
| 426 // static | 427 // static |
| 427 void StatisticsRecorder::Reset() { | 428 void StatisticsRecorder::Reset() { |
| 428 // If there's no lock then there is nothing to reset. | 429 // If there's no lock then there is nothing to reset. |
| 429 if (!lock_) | 430 if (!lock_) |
| 430 return; | 431 return; |
| 431 | 432 |
| 432 scoped_ptr<HistogramMap> histograms_deleter; | 433 std::unique_ptr<HistogramMap> histograms_deleter; |
| 433 scoped_ptr<CallbackMap> callbacks_deleter; | 434 std::unique_ptr<CallbackMap> callbacks_deleter; |
| 434 scoped_ptr<RangesMap> ranges_deleter; | 435 std::unique_ptr<RangesMap> ranges_deleter; |
| 435 // We don't delete lock_ on purpose to avoid having to properly protect | 436 // We don't delete lock_ on purpose to avoid having to properly protect |
| 436 // against it going away after we checked for NULL in the static methods. | 437 // against it going away after we checked for NULL in the static methods. |
| 437 { | 438 { |
| 438 base::AutoLock auto_lock(*lock_); | 439 base::AutoLock auto_lock(*lock_); |
| 439 histograms_deleter.reset(histograms_); | 440 histograms_deleter.reset(histograms_); |
| 440 callbacks_deleter.reset(callbacks_); | 441 callbacks_deleter.reset(callbacks_); |
| 441 ranges_deleter.reset(ranges_); | 442 ranges_deleter.reset(ranges_); |
| 442 histograms_ = NULL; | 443 histograms_ = NULL; |
| 443 callbacks_ = NULL; | 444 callbacks_ = NULL; |
| 444 ranges_ = NULL; | 445 ranges_ = NULL; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 457 // static | 458 // static |
| 458 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 459 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
| 459 // static | 460 // static |
| 460 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 461 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
| 461 // static | 462 // static |
| 462 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 463 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
| 463 // static | 464 // static |
| 464 base::Lock* StatisticsRecorder::lock_ = NULL; | 465 base::Lock* StatisticsRecorder::lock_ = NULL; |
| 465 | 466 |
| 466 } // namespace base | 467 } // namespace base |
| OLD | NEW |