diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-09 10:22:26 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-03-09 14:10:58 +0000 |
commit | 435af93308d985ec4c503d3789a6d48f923dd60a (patch) | |
tree | 7518f182ac15e6802861c122818c69caa34e05ed | |
parent | c96886fe1c28babb62b2e837c6352d77edf3ee7e (diff) |
Test both used and allocated memory.
3 files changed, 24 insertions, 7 deletions
diff --git a/searchlib/src/tests/attribute/attribute_test.cpp b/searchlib/src/tests/attribute/attribute_test.cpp index 18896ca24c1..5a41d738acb 100644 --- a/searchlib/src/tests/attribute/attribute_test.cpp +++ b/searchlib/src/tests/attribute/attribute_test.cpp @@ -898,6 +898,7 @@ AttributeTest::testSingle() AttributePtr ptr = createAttribute("sv-int32", Config(BasicType::INT32, CollectionType::SINGLE)); ptr->updateStat(true); EXPECT_EQ(12288u, ptr->getStatus().getAllocated()); + EXPECT_EQ(0u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testSingle<IntegerAttribute, AttributeVector::largeint_t, int32_t>(ptr, values); } @@ -912,6 +913,7 @@ AttributeTest::testSingle() AttributePtr ptr = createAttribute("sv-post-int32", cfg); ptr->updateStat(true); EXPECT_EQ(231640u, ptr->getStatus().getAllocated()); + EXPECT_EQ(544u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testSingle<IntegerAttribute, AttributeVector::largeint_t, int32_t>(ptr, values); } @@ -923,6 +925,7 @@ AttributeTest::testSingle() AttributePtr ptr = createAttribute("sv-float", Config(BasicType::FLOAT, CollectionType::SINGLE)); ptr->updateStat(true); EXPECT_EQ(12288u, ptr->getStatus().getAllocated()); + EXPECT_EQ(0u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testSingle<FloatingPointAttribute, double, float>(ptr, values); } @@ -932,6 +935,7 @@ AttributeTest::testSingle() AttributePtr ptr = createAttribute("sv-post-float", cfg); ptr->updateStat(true); EXPECT_EQ(231640u, ptr->getStatus().getAllocated()); + EXPECT_EQ(544u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testSingle<FloatingPointAttribute, double, float>(ptr, values); } @@ -944,6 +948,7 @@ AttributeTest::testSingle() AttributePtr ptr = createAttribute("sv-string", Config(BasicType::STRING, CollectionType::SINGLE)); ptr->updateStat(true); EXPECT_EQ(74648u, ptr->getStatus().getAllocated()); + EXPECT_EQ(176u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testSingle<StringAttribute, string, string>(ptr, values); } @@ -953,6 +958,7 @@ AttributeTest::testSingle() AttributePtr ptr = createAttribute("sv-fs-string", cfg); ptr->updateStat(true); EXPECT_EQ(245024u, ptr->getStatus().getAllocated()); + EXPECT_EQ(576, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testSingle<StringAttribute, string, string>(ptr, values); } @@ -1084,6 +1090,7 @@ AttributeTest::testArray() AttributePtr ptr = createAttribute("a-int32", Config(BasicType::INT32, CollectionType::ARRAY)); ptr->updateStat(true); EXPECT_EQ(12320u, ptr->getStatus().getAllocated()); + EXPECT_EQ(32u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<IntegerAttribute, AttributeVector::largeint_t>(ptr, values); } @@ -1093,6 +1100,7 @@ AttributeTest::testArray() AttributePtr ptr = createAttribute("flags", cfg); ptr->updateStat(true); EXPECT_EQ(12320u, ptr->getStatus().getAllocated()); + EXPECT_EQ(32u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<IntegerAttribute, AttributeVector::largeint_t>(ptr, values); } @@ -1102,6 +1110,7 @@ AttributeTest::testArray() AttributePtr ptr = createAttribute("a-fs-int32", cfg); ptr->updateStat(true); EXPECT_EQ(253608u, ptr->getStatus().getAllocated()); + EXPECT_EQ(596u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<IntegerAttribute, AttributeVector::largeint_t>(ptr, values); } @@ -1120,6 +1129,7 @@ AttributeTest::testArray() AttributePtr ptr = createAttribute("a-fs-float", cfg); ptr->updateStat(true); EXPECT_EQ(253608u, ptr->getStatus().getAllocated()); + EXPECT_EQ(596u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<FloatingPointAttribute, double>(ptr, values); } @@ -1131,6 +1141,7 @@ AttributeTest::testArray() AttributePtr ptr = createAttribute("a-string", Config(BasicType::STRING, CollectionType::ARRAY)); ptr->updateStat(true); EXPECT_EQ(74680u, ptr->getStatus().getAllocated()); + EXPECT_EQ(208u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<StringAttribute, string>(ptr, values); } @@ -1140,6 +1151,7 @@ AttributeTest::testArray() AttributePtr ptr = createAttribute("afs-string", cfg); ptr->updateStat(true); EXPECT_EQ(266992u, ptr->getStatus().getAllocated()); + EXPECT_EQ(628u, ptr->getStatus().getUsed()); addDocs(ptr, numDocs); testArray<StringAttribute, string>(ptr, values); } diff --git a/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp b/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp index 4f7a7934d4c..3b233298659 100644 --- a/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp +++ b/searchlib/src/tests/memoryindex/memory_index/memory_index_test.cpp @@ -462,22 +462,26 @@ TEST(MemoryIndexTest, require_that_num_docs_and_doc_id_limit_is_returned) TEST(MemoryIndexTest, require_that_we_understand_the_memory_footprint) { - constexpr size_t BASE_SIZE = 188172u; + constexpr size_t BASE_ALLOCATED = 188172u; + constexpr size_t BASE_USED = 500u; { MySetup setup; Index index(setup); EXPECT_EQ(0u, index.index.getStaticMemoryFootprint()); EXPECT_EQ(index.index.getStaticMemoryFootprint(), index.index.getMemoryUsage().allocatedBytes()); + EXPECT_EQ(0u, index.index.getMemoryUsage().usedBytes()); } { Index index(MySetup().field("f1")); - EXPECT_EQ(BASE_SIZE, index.index.getStaticMemoryFootprint()); + EXPECT_EQ(BASE_ALLOCATED, index.index.getStaticMemoryFootprint()); EXPECT_EQ(index.index.getStaticMemoryFootprint(), index.index.getMemoryUsage().allocatedBytes()); + EXPECT_EQ(BASE_USED, index.index.getMemoryUsage().usedBytes()); } { Index index(MySetup().field("f1").field("f2")); - EXPECT_EQ(2 * BASE_SIZE, index.index.getStaticMemoryFootprint()); + EXPECT_EQ(2 * BASE_ALLOCATED, index.index.getStaticMemoryFootprint()); EXPECT_EQ(index.index.getStaticMemoryFootprint(), index.index.getMemoryUsage().allocatedBytes()); + EXPECT_EQ(2 * BASE_USED, index.index.getMemoryUsage().usedBytes()); } } @@ -511,12 +515,12 @@ TEST(MemoryIndexTest, require_that_we_can_fake_bit_vector) Searchable &searchable = index.index; Blueprint::UP res = searchable.createBlueprint(requestContext, fields, makeTerm(foo)); - EXPECT_TRUE(res.get() != NULL); + EXPECT_TRUE(res); res->fetchPostings(search::queryeval::ExecuteInfo::TRUE); SearchIterator::UP search = res->createSearch(*match_data, true); - EXPECT_TRUE(search.get() != NULL); - EXPECT_TRUE(dynamic_cast<BooleanMatchIteratorWrapper *>(search.get()) != NULL); + EXPECT_TRUE(search); + EXPECT_TRUE(dynamic_cast<BooleanMatchIteratorWrapper *>(search.get()) != nullptr); search->initFullRange(); EXPECT_EQ("1,3", toString(*search)); } diff --git a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp index 76dfdb79c01..40920a8ca1b 100644 --- a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp +++ b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp @@ -471,10 +471,11 @@ TEST_F(DoubleTest, nan_is_handled) TEST_F(DoubleTest, control_memory_usage) { EXPECT_EQ(464, sizeof(store)); + EXPECT_EQ(144u, sizeof(BufferState)); EXPECT_EQ(32u, store.get_values_memory_usage().allocatedBytes()); EXPECT_EQ(98208u, store.get_dictionary_memory_usage().allocatedBytes()); EXPECT_EQ(98240u, store.getMemoryUsage().allocatedBytes()); - EXPECT_EQ(144u, sizeof(BufferState)); + EXPECT_EQ(280u, store.getMemoryUsage().usedBytes()); } GTEST_MAIN_RUN_ALL_TESTS() |