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

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

Issue 2794073002: De-duplicate ranges information in persistent memory. (Closed)
Patch Set: addressed final review comments Created 3 years, 8 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
« no previous file with comments | « base/metrics/persistent_histogram_allocator.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 found = StatisticsRecorder::FindHistogram(SparseHistogramName); 274 found = StatisticsRecorder::FindHistogram(SparseHistogramName);
275 snapshot = found->SnapshotSamples(); 275 snapshot = found->SnapshotSamples();
276 EXPECT_EQ(found->SnapshotSamples()->TotalCount(), snapshot->TotalCount()); 276 EXPECT_EQ(found->SnapshotSamples()->TotalCount(), snapshot->TotalCount());
277 EXPECT_EQ(1, snapshot->GetCount(3)); 277 EXPECT_EQ(1, snapshot->GetCount(3));
278 EXPECT_EQ(8, snapshot->GetCount(1)); 278 EXPECT_EQ(8, snapshot->GetCount(1));
279 EXPECT_EQ(1, snapshot->GetCount(4)); 279 EXPECT_EQ(1, snapshot->GetCount(4));
280 EXPECT_EQ(1, snapshot->GetCount(6)); 280 EXPECT_EQ(1, snapshot->GetCount(6));
281 EXPECT_EQ(1, snapshot->GetCount(7)); 281 EXPECT_EQ(1, snapshot->GetCount(7));
282 } 282 }
283 283
284 TEST_F(PersistentHistogramAllocatorTest, RangesDeDuplication) {
285 // This corresponds to the "ranges_ref" field of the PersistentHistogramData
286 // structure defined (privately) inside persistent_histogram_allocator.cc.
287 const int kRangesRefIndex = 5;
288
289 // Create two histograms with the same ranges.
290 HistogramBase* histogram1 =
291 Histogram::FactoryGet("TestHistogram1", 1, 1000, 10, 0);
292 HistogramBase* histogram2 =
293 Histogram::FactoryGet("TestHistogram2", 1, 1000, 10, 0);
294 const uint32_t ranges_ref = static_cast<Histogram*>(histogram1)
295 ->bucket_ranges()
296 ->persistent_reference();
297 ASSERT_NE(0U, ranges_ref);
298 EXPECT_EQ(ranges_ref, static_cast<Histogram*>(histogram2)
299 ->bucket_ranges()
300 ->persistent_reference());
301
302 // Make sure that the persistent data record is also correct. Two histograms
303 // will be fetched; other allocations are not "iterable".
304 PersistentMemoryAllocator::Iterator iter(allocator_);
305 uint32_t type;
306 uint32_t ref1 = iter.GetNext(&type);
307 uint32_t ref2 = iter.GetNext(&type);
308 EXPECT_EQ(0U, iter.GetNext(&type));
309 EXPECT_NE(0U, ref1);
310 EXPECT_NE(0U, ref2);
311 EXPECT_NE(ref1, ref2);
312
313 uint32_t* data1 =
314 allocator_->GetAsArray<uint32_t>(ref1, 0, kRangesRefIndex + 1);
315 uint32_t* data2 =
316 allocator_->GetAsArray<uint32_t>(ref2, 0, kRangesRefIndex + 1);
317 EXPECT_EQ(ranges_ref, data1[kRangesRefIndex]);
318 EXPECT_EQ(ranges_ref, data2[kRangesRefIndex]);
319 }
320
284 } // namespace base 321 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_histogram_allocator.cc ('k') | base/metrics/statistics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698