OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/persistent_histogram_allocator.h" | 5 #include "base/metrics/persistent_histogram_allocator.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/bucket_ranges.h" | 9 #include "base/metrics/bucket_ranges.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 custom_ranges.push_back(1); | 79 custom_ranges.push_back(1); |
80 custom_ranges.push_back(5); | 80 custom_ranges.push_back(5); |
81 HistogramBase* custom_histogram = CustomHistogram::FactoryGet( | 81 HistogramBase* custom_histogram = CustomHistogram::FactoryGet( |
82 "TestCustomHistogram", custom_ranges, HistogramBase::kIsPersistent); | 82 "TestCustomHistogram", custom_ranges, HistogramBase::kIsPersistent); |
83 EXPECT_TRUE(custom_histogram); | 83 EXPECT_TRUE(custom_histogram); |
84 custom_histogram->CheckName("TestCustomHistogram"); | 84 custom_histogram->CheckName("TestCustomHistogram"); |
85 PersistentMemoryAllocator::MemoryInfo meminfo4; | 85 PersistentMemoryAllocator::MemoryInfo meminfo4; |
86 allocator_->GetMemoryInfo(&meminfo4); | 86 allocator_->GetMemoryInfo(&meminfo4); |
87 EXPECT_GT(meminfo3.free, meminfo4.free); | 87 EXPECT_GT(meminfo3.free, meminfo4.free); |
88 | 88 |
89 PersistentMemoryAllocator::Iterator iter; | 89 PersistentMemoryAllocator::Iterator iter(allocator_); |
90 uint32_t type; | 90 uint32_t type; |
91 allocator_->CreateIterator(&iter); | 91 EXPECT_NE(0U, iter.GetNext(&type)); // Histogram |
92 EXPECT_NE(0U, allocator_->GetNextIterable(&iter, &type)); // Histogram | 92 EXPECT_NE(0U, iter.GetNext(&type)); // LinearHistogram |
93 EXPECT_NE(0U, allocator_->GetNextIterable(&iter, &type)); // LinearHistogram | 93 EXPECT_NE(0U, iter.GetNext(&type)); // BooleanHistogram |
94 EXPECT_NE(0U, allocator_->GetNextIterable(&iter, &type)); // BooleanHistogram | 94 EXPECT_NE(0U, iter.GetNext(&type)); // CustomHistogram |
95 EXPECT_NE(0U, allocator_->GetNextIterable(&iter, &type)); // CustomHistogram | 95 EXPECT_EQ(0U, iter.GetNext(&type)); |
96 EXPECT_EQ(0U, allocator_->GetNextIterable(&iter, &type)); | |
97 | 96 |
98 // Create a second allocator and have it access the memory of the first. | 97 // Create a second allocator and have it access the memory of the first. |
99 std::unique_ptr<HistogramBase> recovered; | 98 std::unique_ptr<HistogramBase> recovered; |
100 PersistentHistogramAllocator recovery( | 99 PersistentHistogramAllocator recovery( |
101 WrapUnique(new PersistentMemoryAllocator( | 100 WrapUnique(new PersistentMemoryAllocator( |
102 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, "", false))); | 101 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, "", false))); |
103 PersistentHistogramAllocator::Iterator histogram_iter; | 102 PersistentHistogramAllocator::Iterator histogram_iter(&recovery); |
104 recovery.CreateIterator(&histogram_iter); | |
105 | 103 |
106 recovered = recovery.GetNextHistogram(&histogram_iter); | 104 recovered = histogram_iter.GetNext(); |
107 ASSERT_TRUE(recovered); | 105 ASSERT_TRUE(recovered); |
108 recovered->CheckName("TestHistogram"); | 106 recovered->CheckName("TestHistogram"); |
109 | 107 |
110 recovered = recovery.GetNextHistogram(&histogram_iter); | 108 recovered = histogram_iter.GetNext(); |
111 ASSERT_TRUE(recovered); | 109 ASSERT_TRUE(recovered); |
112 recovered->CheckName("TestLinearHistogram"); | 110 recovered->CheckName("TestLinearHistogram"); |
113 | 111 |
114 recovered = recovery.GetNextHistogram(&histogram_iter); | 112 recovered = histogram_iter.GetNext(); |
115 ASSERT_TRUE(recovered); | 113 ASSERT_TRUE(recovered); |
116 recovered->CheckName("TestBooleanHistogram"); | 114 recovered->CheckName("TestBooleanHistogram"); |
117 | 115 |
118 recovered = recovery.GetNextHistogram(&histogram_iter); | 116 recovered = histogram_iter.GetNext(); |
119 ASSERT_TRUE(recovered); | 117 ASSERT_TRUE(recovered); |
120 recovered->CheckName("TestCustomHistogram"); | 118 recovered->CheckName("TestCustomHistogram"); |
121 | 119 |
122 recovered = recovery.GetNextHistogram(&histogram_iter); | 120 recovered = histogram_iter.GetNext(); |
123 EXPECT_FALSE(recovered); | 121 EXPECT_FALSE(recovered); |
124 } | 122 } |
125 | 123 |
126 } // namespace base | 124 } // namespace base |
OLD | NEW |