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