| 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 14 matching lines...) Expand all Loading... |
| 25 // Get this first so it never gets created in persistent storage and will | 25 // Get this first so it never gets created in persistent storage and will |
| 26 // not appear in the StatisticsRecorder after it is re-initialized. | 26 // not appear in the StatisticsRecorder after it is re-initialized. |
| 27 PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); | 27 PersistentHistogramAllocator::GetCreateHistogramResultHistogram(); |
| 28 // Each test will have a clean state (no Histogram / BucketRanges | 28 // Each test will have a clean state (no Histogram / BucketRanges |
| 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 PersistentHistogramAllocator::ReleaseGlobalAllocatorForTesting(); | 35 GlobalHistogramAllocator::ReleaseForTesting(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void InitializeStatisticsRecorder() { | 38 void InitializeStatisticsRecorder() { |
| 39 statistics_recorder_ = new StatisticsRecorder(); | 39 statistics_recorder_ = new StatisticsRecorder(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void UninitializeStatisticsRecorder() { | 42 void UninitializeStatisticsRecorder() { |
| 43 delete statistics_recorder_; | 43 delete statistics_recorder_; |
| 44 statistics_recorder_ = NULL; | 44 statistics_recorder_ = NULL; |
| 45 } | 45 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 UninitializeStatisticsRecorder(); | 319 UninitializeStatisticsRecorder(); |
| 320 | 320 |
| 321 // No data should be returned. | 321 // No data should be returned. |
| 322 json = StatisticsRecorder::ToJSON(query); | 322 json = StatisticsRecorder::ToJSON(query); |
| 323 EXPECT_TRUE(json.empty()); | 323 EXPECT_TRUE(json.empty()); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TEST_F(StatisticsRecorderTest, IterationTest) { | 326 TEST_F(StatisticsRecorderTest, IterationTest) { |
| 327 StatisticsRecorder::Histograms registered_histograms; | 327 StatisticsRecorder::Histograms registered_histograms; |
| 328 LOCAL_HISTOGRAM_COUNTS("TestHistogram.IterationTest1", 30); | 328 LOCAL_HISTOGRAM_COUNTS("TestHistogram.IterationTest1", 30); |
| 329 PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory( | 329 GlobalHistogramAllocator::CreateWithLocalMemory(64 << 10 /* 64 KiB */, 0, ""); |
| 330 64 << 10 /* 64 KiB */, 0, ""); | |
| 331 LOCAL_HISTOGRAM_COUNTS("TestHistogram.IterationTest2", 30); | 330 LOCAL_HISTOGRAM_COUNTS("TestHistogram.IterationTest2", 30); |
| 332 | 331 |
| 333 StatisticsRecorder::HistogramIterator i1 = StatisticsRecorder::begin(true); | 332 StatisticsRecorder::HistogramIterator i1 = StatisticsRecorder::begin(true); |
| 334 EXPECT_NE(StatisticsRecorder::end(), i1); | 333 EXPECT_NE(StatisticsRecorder::end(), i1); |
| 335 EXPECT_NE(StatisticsRecorder::end(), ++i1); | 334 EXPECT_NE(StatisticsRecorder::end(), ++i1); |
| 336 EXPECT_EQ(StatisticsRecorder::end(), ++i1); | 335 EXPECT_EQ(StatisticsRecorder::end(), ++i1); |
| 337 | 336 |
| 338 StatisticsRecorder::HistogramIterator i2 = StatisticsRecorder::begin(false); | 337 StatisticsRecorder::HistogramIterator i2 = StatisticsRecorder::begin(false); |
| 339 EXPECT_NE(StatisticsRecorder::end(), i2); | 338 EXPECT_NE(StatisticsRecorder::end(), i2); |
| 340 EXPECT_EQ(StatisticsRecorder::end(), ++i2); | 339 EXPECT_EQ(StatisticsRecorder::end(), ++i2); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, | 507 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, |
| 509 HistogramBase::kNoFlags); | 508 HistogramBase::kNoFlags); |
| 510 EXPECT_TRUE(histogram); | 509 EXPECT_TRUE(histogram); |
| 511 histogram->Add(1); | 510 histogram->Add(1); |
| 512 | 511 |
| 513 EXPECT_TRUE(callback_wrapper.called); | 512 EXPECT_TRUE(callback_wrapper.called); |
| 514 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); | 513 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); |
| 515 } | 514 } |
| 516 | 515 |
| 517 } // namespace base | 516 } // namespace base |
| OLD | NEW |