| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // registered). | 29 // registered). |
| 30 InitializeStatisticsRecorder(); | 30 InitializeStatisticsRecorder(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void TearDown() override { | 33 void TearDown() override { |
| 34 UninitializeStatisticsRecorder(); | 34 UninitializeStatisticsRecorder(); |
| 35 GlobalHistogramAllocator::ReleaseForTesting(); | 35 GlobalHistogramAllocator::ReleaseForTesting(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void InitializeStatisticsRecorder() { | 38 void InitializeStatisticsRecorder() { |
| 39 statistics_recorder_ = new StatisticsRecorder(); | 39 DCHECK(!statistics_recorder_); |
| 40 StatisticsRecorder::UninitializeForTesting(); |
| 41 statistics_recorder_.reset(new StatisticsRecorder()); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void UninitializeStatisticsRecorder() { | 44 void UninitializeStatisticsRecorder() { |
| 43 delete statistics_recorder_; | 45 statistics_recorder_.reset(); |
| 44 statistics_recorder_ = NULL; | 46 StatisticsRecorder::UninitializeForTesting(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 Histogram* CreateHistogram(const std::string& name, | 49 Histogram* CreateHistogram(const std::string& name, |
| 48 HistogramBase::Sample min, | 50 HistogramBase::Sample min, |
| 49 HistogramBase::Sample max, | 51 HistogramBase::Sample max, |
| 50 size_t bucket_count) { | 52 size_t bucket_count) { |
| 51 BucketRanges* ranges = new BucketRanges(bucket_count + 1); | 53 BucketRanges* ranges = new BucketRanges(bucket_count + 1); |
| 52 Histogram::InitializeBucketRanges(min, max, ranges); | 54 Histogram::InitializeBucketRanges(min, max, ranges); |
| 53 const BucketRanges* registered_ranges = | 55 const BucketRanges* registered_ranges = |
| 54 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); | 56 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); |
| 55 return new Histogram(name, min, max, registered_ranges); | 57 return new Histogram(name, min, max, registered_ranges); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void DeleteHistogram(HistogramBase* histogram) { | 60 void DeleteHistogram(HistogramBase* histogram) { |
| 59 delete histogram; | 61 delete histogram; |
| 60 } | 62 } |
| 61 | 63 |
| 62 StatisticsRecorder* statistics_recorder_; | 64 std::unique_ptr<StatisticsRecorder> statistics_recorder_; |
| 63 }; | 65 }; |
| 64 | 66 |
| 65 TEST_F(StatisticsRecorderTest, NotInitialized) { | 67 TEST_F(StatisticsRecorderTest, NotInitialized) { |
| 66 UninitializeStatisticsRecorder(); | 68 UninitializeStatisticsRecorder(); |
| 67 | 69 |
| 68 ASSERT_FALSE(StatisticsRecorder::IsActive()); | 70 ASSERT_FALSE(StatisticsRecorder::IsActive()); |
| 69 | 71 |
| 70 StatisticsRecorder::Histograms registered_histograms; | 72 StatisticsRecorder::Histograms registered_histograms; |
| 71 std::vector<const BucketRanges*> registered_ranges; | 73 std::vector<const BucketRanges*> registered_ranges; |
| 72 | 74 |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, | 509 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, |
| 508 HistogramBase::kNoFlags); | 510 HistogramBase::kNoFlags); |
| 509 EXPECT_TRUE(histogram); | 511 EXPECT_TRUE(histogram); |
| 510 histogram->Add(1); | 512 histogram->Add(1); |
| 511 | 513 |
| 512 EXPECT_TRUE(callback_wrapper.called); | 514 EXPECT_TRUE(callback_wrapper.called); |
| 513 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); | 515 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); |
| 514 } | 516 } |
| 515 | 517 |
| 516 } // namespace base | 518 } // namespace base |
| OLD | NEW |