Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: base/metrics/persistent_histogram_allocator_unittest.cc

Issue 2258713003: Re-write many calls to WrapUnique() with MakeUnique() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/bucket_ranges.h" 10 #include "base/metrics/bucket_ranges.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 PersistentMemoryAllocator::Iterator iter(allocator_); 95 PersistentMemoryAllocator::Iterator iter(allocator_);
96 uint32_t type; 96 uint32_t type;
97 EXPECT_NE(0U, iter.GetNext(&type)); // Histogram 97 EXPECT_NE(0U, iter.GetNext(&type)); // Histogram
98 EXPECT_NE(0U, iter.GetNext(&type)); // LinearHistogram 98 EXPECT_NE(0U, iter.GetNext(&type)); // LinearHistogram
99 EXPECT_NE(0U, iter.GetNext(&type)); // BooleanHistogram 99 EXPECT_NE(0U, iter.GetNext(&type)); // BooleanHistogram
100 EXPECT_NE(0U, iter.GetNext(&type)); // CustomHistogram 100 EXPECT_NE(0U, iter.GetNext(&type)); // CustomHistogram
101 EXPECT_EQ(0U, iter.GetNext(&type)); 101 EXPECT_EQ(0U, iter.GetNext(&type));
102 102
103 // Create a second allocator and have it access the memory of the first. 103 // Create a second allocator and have it access the memory of the first.
104 std::unique_ptr<HistogramBase> recovered; 104 std::unique_ptr<HistogramBase> recovered;
105 PersistentHistogramAllocator recovery( 105 PersistentHistogramAllocator recovery(MakeUnique<PersistentMemoryAllocator>(
106 WrapUnique(new PersistentMemoryAllocator( 106 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, "", false));
107 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, "", false)));
108 PersistentHistogramAllocator::Iterator histogram_iter(&recovery); 107 PersistentHistogramAllocator::Iterator histogram_iter(&recovery);
109 108
110 recovered = histogram_iter.GetNext(); 109 recovered = histogram_iter.GetNext();
111 ASSERT_TRUE(recovered); 110 ASSERT_TRUE(recovered);
112 recovered->CheckName("TestHistogram"); 111 recovered->CheckName("TestHistogram");
113 112
114 recovered = histogram_iter.GetNext(); 113 recovered = histogram_iter.GetNext();
115 ASSERT_TRUE(recovered); 114 ASSERT_TRUE(recovered);
116 recovered->CheckName("TestLinearHistogram"); 115 recovered->CheckName("TestLinearHistogram");
117 116
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 histogram->Add(4); 173 histogram->Add(4);
175 histogram->Add(1); 174 histogram->Add(1);
176 histogram->Add(6); 175 histogram->Add(6);
177 176
178 // Destroy the local SR and ensure that we're back to the initial state. 177 // Destroy the local SR and ensure that we're back to the initial state.
179 local_sr.reset(); 178 local_sr.reset();
180 EXPECT_EQ(starting_sr_count, StatisticsRecorder::GetHistogramCount()); 179 EXPECT_EQ(starting_sr_count, StatisticsRecorder::GetHistogramCount());
181 180
182 // Create a second allocator and have it access the memory of the first. 181 // Create a second allocator and have it access the memory of the first.
183 std::unique_ptr<HistogramBase> recovered; 182 std::unique_ptr<HistogramBase> recovered;
184 PersistentHistogramAllocator recovery( 183 PersistentHistogramAllocator recovery(MakeUnique<PersistentMemoryAllocator>(
185 WrapUnique(new PersistentMemoryAllocator( 184 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, "", false));
186 allocator_memory_.get(), kAllocatorMemorySize, 0, 0, "", false)));
187 PersistentHistogramAllocator::Iterator histogram_iter(&recovery); 185 PersistentHistogramAllocator::Iterator histogram_iter(&recovery);
188 186
189 recovered = histogram_iter.GetNext(); 187 recovered = histogram_iter.GetNext();
190 ASSERT_TRUE(recovered); 188 ASSERT_TRUE(recovered);
191 189
192 // Merge the recovered histogram to the SR. It will always be a new object. 190 // Merge the recovered histogram to the SR. It will always be a new object.
193 recovery.MergeHistogramDeltaToStatisticsRecorder(recovered.get()); 191 recovery.MergeHistogramDeltaToStatisticsRecorder(recovered.get());
194 EXPECT_EQ(starting_sr_count + 1, StatisticsRecorder::GetHistogramCount()); 192 EXPECT_EQ(starting_sr_count + 1, StatisticsRecorder::GetHistogramCount());
195 HistogramBase* found = 193 HistogramBase* found =
196 StatisticsRecorder::FindHistogram(recovered->histogram_name()); 194 StatisticsRecorder::FindHistogram(recovered->histogram_name());
197 ASSERT_TRUE(found); 195 ASSERT_TRUE(found);
198 EXPECT_NE(recovered.get(), found); 196 EXPECT_NE(recovered.get(), found);
199 197
200 // Ensure that the data got merged, too. 198 // Ensure that the data got merged, too.
201 std::unique_ptr<HistogramSamples> snapshot = found->SnapshotSamples(); 199 std::unique_ptr<HistogramSamples> snapshot = found->SnapshotSamples();
202 EXPECT_EQ(recovered->SnapshotSamples()->TotalCount(), snapshot->TotalCount()); 200 EXPECT_EQ(recovered->SnapshotSamples()->TotalCount(), snapshot->TotalCount());
203 EXPECT_EQ(1, snapshot->GetCount(3)); 201 EXPECT_EQ(1, snapshot->GetCount(3));
204 EXPECT_EQ(2, snapshot->GetCount(1)); 202 EXPECT_EQ(2, snapshot->GetCount(1));
205 EXPECT_EQ(1, snapshot->GetCount(4)); 203 EXPECT_EQ(1, snapshot->GetCount(4));
206 EXPECT_EQ(1, snapshot->GetCount(6)); 204 EXPECT_EQ(1, snapshot->GetCount(6));
207 } 205 }
208 206
209 } // namespace base 207 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_histogram_allocator.cc ('k') | base/metrics/persistent_sample_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698