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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/metrics/histogram_persistence.h" | 13 #include "base/metrics/persistent_histogram_allocator.h" |
14 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
15 #include "base/metrics/statistics_recorder.h" | 15 #include "base/metrics/statistics_recorder.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 | 20 |
21 class StatisticsRecorderTest : public testing::Test { | 21 class StatisticsRecorderTest : public testing::Test { |
22 protected: | 22 protected: |
23 void SetUp() override { | 23 void SetUp() override { |
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 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 delete ReleasePersistentHistogramMemoryAllocatorForTesting(); | 34 PersistentHistogramAllocator::ReleaseGlobalAllocatorForTesting(); |
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 SetPersistentHistogramMemoryAllocator( | 328 PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory( |
329 new LocalPersistentMemoryAllocator(64 << 10, 0, std::string())); | 329 64 << 10 /* 64 KiB */, 0, ""); |
330 LOCAL_HISTOGRAM_COUNTS("TestHistogram.IterationTest2", 30); | 330 LOCAL_HISTOGRAM_COUNTS("TestHistogram.IterationTest2", 30); |
331 | 331 |
332 StatisticsRecorder::HistogramIterator i1 = StatisticsRecorder::begin(true); | 332 StatisticsRecorder::HistogramIterator i1 = StatisticsRecorder::begin(true); |
333 EXPECT_NE(StatisticsRecorder::end(), i1); | 333 EXPECT_NE(StatisticsRecorder::end(), i1); |
334 EXPECT_NE(StatisticsRecorder::end(), ++i1); | 334 EXPECT_NE(StatisticsRecorder::end(), ++i1); |
335 EXPECT_EQ(StatisticsRecorder::end(), ++i1); | 335 EXPECT_EQ(StatisticsRecorder::end(), ++i1); |
336 | 336 |
337 StatisticsRecorder::HistogramIterator i2 = StatisticsRecorder::begin(false); | 337 StatisticsRecorder::HistogramIterator i2 = StatisticsRecorder::begin(false); |
338 EXPECT_NE(StatisticsRecorder::end(), i2); | 338 EXPECT_NE(StatisticsRecorder::end(), i2); |
339 EXPECT_EQ(StatisticsRecorder::end(), ++i2); | 339 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, | 507 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, |
508 HistogramBase::kNoFlags); | 508 HistogramBase::kNoFlags); |
509 EXPECT_TRUE(histogram); | 509 EXPECT_TRUE(histogram); |
510 histogram->Add(1); | 510 histogram->Add(1); |
511 | 511 |
512 EXPECT_TRUE(callback_wrapper.called); | 512 EXPECT_TRUE(callback_wrapper.called); |
513 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); | 513 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); |
514 } | 514 } |
515 | 515 |
516 } // namespace base | 516 } // namespace base |
OLD | NEW |