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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 // static | 424 // static |
425 size_t StatisticsRecorder::GetHistogramCount() { | 425 size_t StatisticsRecorder::GetHistogramCount() { |
426 base::AutoLock auto_lock(lock_.Get()); | 426 base::AutoLock auto_lock(lock_.Get()); |
427 if (!histograms_) | 427 if (!histograms_) |
428 return 0; | 428 return 0; |
429 return histograms_->size(); | 429 return histograms_->size(); |
430 } | 430 } |
431 | 431 |
432 // static | 432 // static |
433 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { | 433 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { |
434 if (histograms_) | 434 if (!histograms_) |
435 histograms_->erase(name); | 435 return; |
436 | |
437 HistogramMap::iterator found = histograms_->find(name); | |
438 if (found == histograms_->end()) | |
439 return; | |
440 | |
441 HistogramBase* base = found->second; | |
442 if (base->GetHistogramType() != SPARSE_HISTOGRAM) { | |
Alexei Svitkine (slow)
2017/04/04 17:45:09
Nit: Add a comment about this logic.
bcwhite
2017/04/05 13:41:30
Done.
| |
443 Histogram* histogram = static_cast<Histogram*>(base); | |
444 histogram->bucket_ranges()->set_persistent_reference(0); | |
445 } | |
446 | |
447 histograms_->erase(found); | |
436 } | 448 } |
437 | 449 |
438 // static | 450 // static |
439 std::unique_ptr<StatisticsRecorder> | 451 std::unique_ptr<StatisticsRecorder> |
440 StatisticsRecorder::CreateTemporaryForTesting() { | 452 StatisticsRecorder::CreateTemporaryForTesting() { |
441 return WrapUnique(new StatisticsRecorder()); | 453 return WrapUnique(new StatisticsRecorder()); |
442 } | 454 } |
443 | 455 |
444 // static | 456 // static |
445 void StatisticsRecorder::UninitializeForTesting() { | 457 void StatisticsRecorder::UninitializeForTesting() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = nullptr; | 545 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = nullptr; |
534 // static | 546 // static |
535 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = nullptr; | 547 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = nullptr; |
536 // static | 548 // static |
537 StatisticsRecorder::HistogramProviders* StatisticsRecorder::providers_; | 549 StatisticsRecorder::HistogramProviders* StatisticsRecorder::providers_; |
538 // static | 550 // static |
539 base::LazyInstance<base::Lock>::Leaky StatisticsRecorder::lock_ = | 551 base::LazyInstance<base::Lock>::Leaky StatisticsRecorder::lock_ = |
540 LAZY_INSTANCE_INITIALIZER; | 552 LAZY_INSTANCE_INITIALIZER; |
541 | 553 |
542 } // namespace base | 554 } // namespace base |
OLD | NEW |