Index: base/metrics/persistent_sample_map_unittest.cc |
diff --git a/base/metrics/persistent_sample_map_unittest.cc b/base/metrics/persistent_sample_map_unittest.cc |
index 52c3cef01dca31d44c6b95e00564dc1ab055d3a0..48e9900c0987f1780da96c216f3d2d602858b466 100644 |
--- a/base/metrics/persistent_sample_map_unittest.cc |
+++ b/base/metrics/persistent_sample_map_unittest.cc |
@@ -6,6 +6,7 @@ |
#include <memory> |
+#include "base/metrics/persistent_histogram_allocator.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace base { |
@@ -14,10 +15,9 @@ namespace { |
TEST(PersistentSampleMapTest, AccumulateTest) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples(1, &allocator, meta); |
+ HistogramSamples::Metadata meta; |
+ PersistentSparseHistogramDataManager manager(&allocator); |
+ PersistentSampleMap samples(1, &manager, &meta); |
samples.Accumulate(1, 100); |
samples.Accumulate(2, 200); |
@@ -33,10 +33,9 @@ TEST(PersistentSampleMapTest, AccumulateTest) { |
TEST(PersistentSampleMapTest, Accumulate_LargeValuesDontOverflow) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples(1, &allocator, meta); |
+ HistogramSamples::Metadata meta; |
+ PersistentSparseHistogramDataManager manager(&allocator); |
+ PersistentSampleMap samples(1, &manager, &meta); |
samples.Accumulate(250000000, 100); |
samples.Accumulate(500000000, 200); |
@@ -52,19 +51,16 @@ TEST(PersistentSampleMapTest, Accumulate_LargeValuesDontOverflow) { |
TEST(PersistentSampleMapTest, AddSubtractTest) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta1 = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- HistogramSamples::Metadata* meta2 = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples1(1, &allocator, meta1); |
- PersistentSampleMap samples2(2, &allocator, meta2); |
- |
+ HistogramSamples::Metadata meta1; |
+ PersistentSparseHistogramDataManager manager1(&allocator); |
+ PersistentSampleMap samples1(1, &manager1, &meta1); |
samples1.Accumulate(1, 100); |
samples1.Accumulate(2, 100); |
samples1.Accumulate(3, 100); |
+ HistogramSamples::Metadata meta2; |
+ PersistentSparseHistogramDataManager manager2(&allocator); |
+ PersistentSampleMap samples2(2, &manager2, &meta2); |
samples2.Accumulate(1, 200); |
samples2.Accumulate(2, 200); |
samples2.Accumulate(4, 200); |
@@ -91,10 +87,9 @@ TEST(PersistentSampleMapTest, AddSubtractTest) { |
TEST(PersistentSampleMapTest, PersistenceTest) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta12 = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples1(12, &allocator, meta12); |
+ HistogramSamples::Metadata meta12; |
+ PersistentSparseHistogramDataManager manager1(&allocator); |
+ PersistentSampleMap samples1(12, &manager1, &meta12); |
samples1.Accumulate(1, 100); |
samples1.Accumulate(2, 200); |
samples1.Accumulate(1, -200); |
@@ -104,7 +99,8 @@ TEST(PersistentSampleMapTest, PersistenceTest) { |
EXPECT_EQ(100, samples1.TotalCount()); |
EXPECT_EQ(samples1.redundant_count(), samples1.TotalCount()); |
- PersistentSampleMap samples2(12, &allocator, meta12); |
+ PersistentSparseHistogramDataManager manager2(&allocator); |
+ PersistentSampleMap samples2(12, &manager2, &meta12); |
EXPECT_EQ(samples1.id(), samples2.id()); |
EXPECT_EQ(samples1.sum(), samples2.sum()); |
EXPECT_EQ(samples1.redundant_count(), samples2.redundant_count()); |
@@ -123,15 +119,26 @@ TEST(PersistentSampleMapTest, PersistenceTest) { |
EXPECT_EQ(samples1.sum(), samples2.sum()); |
EXPECT_EQ(samples1.redundant_count(), samples2.redundant_count()); |
EXPECT_EQ(samples1.TotalCount(), samples2.TotalCount()); |
+ |
+ EXPECT_EQ(0, samples2.GetCount(4)); |
+ EXPECT_EQ(0, samples1.GetCount(4)); |
+ samples1.Accumulate(4, 400); |
+ EXPECT_EQ(400, samples2.GetCount(4)); |
+ EXPECT_EQ(400, samples1.GetCount(4)); |
+ samples2.Accumulate(4, 4000); |
+ EXPECT_EQ(4400, samples2.GetCount(4)); |
+ EXPECT_EQ(4400, samples1.GetCount(4)); |
+ EXPECT_EQ(samples1.sum(), samples2.sum()); |
+ EXPECT_EQ(samples1.redundant_count(), samples2.redundant_count()); |
+ EXPECT_EQ(samples1.TotalCount(), samples2.TotalCount()); |
} |
TEST(PersistentSampleMapIteratorTest, IterateTest) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples(1, &allocator, meta); |
+ HistogramSamples::Metadata meta; |
+ PersistentSparseHistogramDataManager manager(&allocator); |
+ PersistentSampleMap samples(1, &manager, &meta); |
samples.Accumulate(1, 100); |
samples.Accumulate(2, 200); |
samples.Accumulate(4, -300); |
@@ -168,27 +175,25 @@ TEST(PersistentSampleMapIteratorTest, IterateTest) { |
TEST(PersistentSampleMapIteratorTest, SkipEmptyRanges) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples(1, &allocator, meta); |
- samples.Accumulate(5, 1); |
- samples.Accumulate(10, 2); |
- samples.Accumulate(15, 3); |
- samples.Accumulate(20, 4); |
- samples.Accumulate(25, 5); |
- |
- HistogramSamples::Metadata* meta2 = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples2(2, &allocator, meta2); |
+ HistogramSamples::Metadata meta1; |
+ PersistentSparseHistogramDataManager manager1(&allocator); |
+ PersistentSampleMap samples1(1, &manager1, &meta1); |
+ samples1.Accumulate(5, 1); |
+ samples1.Accumulate(10, 2); |
+ samples1.Accumulate(15, 3); |
+ samples1.Accumulate(20, 4); |
+ samples1.Accumulate(25, 5); |
+ |
+ HistogramSamples::Metadata meta2; |
+ PersistentSparseHistogramDataManager manager2(&allocator); |
+ PersistentSampleMap samples2(2, &manager2, &meta2); |
samples2.Accumulate(5, 1); |
samples2.Accumulate(20, 4); |
samples2.Accumulate(25, 5); |
- samples.Subtract(samples2); |
+ samples1.Subtract(samples2); |
- std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |
+ std::unique_ptr<SampleCountIterator> it = samples1.Iterator(); |
EXPECT_FALSE(it->Done()); |
HistogramBase::Sample min; |
@@ -217,10 +222,9 @@ TEST(PersistentSampleMapIteratorTest, SkipEmptyRanges) { |
TEST(PersistentSampleMapIteratorDeathTest, IterateDoneTest) { |
LocalPersistentMemoryAllocator allocator(64 << 10, 0, ""); // 64 KiB |
- HistogramSamples::Metadata* meta = |
- allocator.GetAsObject<HistogramSamples::Metadata>( |
- allocator.Allocate(sizeof(HistogramSamples::Metadata), 0), 0); |
- PersistentSampleMap samples(1, &allocator, meta); |
+ HistogramSamples::Metadata meta; |
+ PersistentSparseHistogramDataManager manager(&allocator); |
+ PersistentSampleMap samples(1, &manager, &meta); |
std::unique_ptr<SampleCountIterator> it = samples.Iterator(); |