Skip to content

Commit

Permalink
Integrate std::prm memory tracking for class Enumeration. (TileDB-I…
Browse files Browse the repository at this point in the history
…nc#4735)

All member vector variables of the Enumeration class have PMR tracking.

---
TYPE: NO_HISTORY
DESC: Integrate std::prm memory tracking for class `Enumeration`.

---------

Co-authored-by: Luc Rancourt <[email protected]>
  • Loading branch information
2 people authored and davisp committed Mar 3, 2024
1 parent 5d00114 commit ae27122
Show file tree
Hide file tree
Showing 18 changed files with 227 additions and 76 deletions.
135 changes: 99 additions & 36 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ QueryCondition create_qc(
TEST_CASE_METHOD(
EnumerationFx, "Create Empty Enumeration", "[enumeration][empty]") {
Enumeration::create(
default_enmr_name, Datatype::INT32, 1, false, nullptr, 0, nullptr, 0);
default_enmr_name,
Datatype::INT32,
1,
false,
nullptr,
0,
nullptr,
0,
memory_tracker_);
}

TEST_CASE_METHOD(
Expand All @@ -179,7 +187,8 @@ TEST_CASE_METHOD(
nullptr,
0,
nullptr,
0);
0,
memory_tracker_);
}

TEST_CASE_METHOD(
Expand Down Expand Up @@ -259,7 +268,9 @@ TEST_CASE_METHOD(
nullptr,
0,
&offsets,
sizeof(uint64_t));
sizeof(uint64_t),
memory_tracker_);

std::vector<std::string> values = {""};
check_enumeration(
enmr,
Expand Down Expand Up @@ -328,7 +339,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
nullptr,
0);
0,
memory_tracker_);
check_enumeration(enmr, default_enmr_name, values, Datatype::INT32, 2, false);
}

Expand All @@ -347,7 +359,8 @@ TEST_CASE_METHOD(
nullptr,
10,
nullptr,
0),
0,
memory_tracker_),
matcher);
}

Expand All @@ -360,7 +373,15 @@ TEST_CASE_METHOD(
"Invalid data size; must be non-zero for fixed size data.");
REQUIRE_THROWS_WITH(
Enumeration::create(
default_enmr_name, Datatype::INT32, 1, false, &val, 0, nullptr, 0),
default_enmr_name,
Datatype::INT32,
1,
false,
&val,
0,
nullptr,
0,
memory_tracker_),
matcher);
}

Expand All @@ -380,7 +401,8 @@ TEST_CASE_METHOD(
val,
strlen(val),
nullptr,
8),
8,
memory_tracker_),
matcher);
}

Expand All @@ -401,7 +423,8 @@ TEST_CASE_METHOD(
val,
strlen(val),
&offset,
0),
0,
memory_tracker_),
matcher);
}

Expand All @@ -422,7 +445,8 @@ TEST_CASE_METHOD(
nullptr,
5,
&offsets,
sizeof(uint64_t)),
sizeof(uint64_t),
memory_tracker_),
matcher);
}

Expand All @@ -443,7 +467,8 @@ TEST_CASE_METHOD(
nullptr,
5,
&offsets,
sizeof(uint64_t)),
sizeof(uint64_t),
memory_tracker_),
matcher);
}

Expand All @@ -465,7 +490,8 @@ TEST_CASE_METHOD(
data,
2,
&offsets,
sizeof(uint64_t)),
sizeof(uint64_t),
memory_tracker_),
matcher);
}

Expand All @@ -482,7 +508,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -498,7 +525,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -515,7 +543,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -531,7 +560,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -547,7 +577,8 @@ TEST_CASE_METHOD(
nullptr,
values.size() * sizeof(int),
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -563,7 +594,8 @@ TEST_CASE_METHOD(
values.data(),
0,
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -580,7 +612,8 @@ TEST_CASE_METHOD(
data,
strlen(data),
nullptr,
offsets.size() * sizeof(uint64_t)));
offsets.size() * sizeof(uint64_t),
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -597,7 +630,8 @@ TEST_CASE_METHOD(
data,
strlen(data),
offsets.data(),
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -614,7 +648,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
offsets.data(),
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -630,7 +665,8 @@ TEST_CASE_METHOD(
values.data(),
values.size() * sizeof(int),
nullptr,
100));
100,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -649,7 +685,8 @@ TEST_CASE_METHOD(
data,
strlen(data),
offsets.data(),
3));
3,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -667,7 +704,8 @@ TEST_CASE_METHOD(
data,
strlen(data),
offsets.data(),
offsets.size() * sizeof(uint64_t)));
offsets.size() * sizeof(uint64_t),
memory_tracker_));
}

TEST_CASE_METHOD(
Expand All @@ -685,7 +723,8 @@ TEST_CASE_METHOD(
values.data(),
3,
nullptr,
0));
0,
memory_tracker_));
}

TEST_CASE_METHOD(
Expand Down Expand Up @@ -755,7 +794,8 @@ TEST_CASE_METHOD(
init_values.data(),
init_values.size() * sizeof(int),
nullptr,
0);
0,
memory_tracker_);
auto enmr2 = extend_enumeration(enmr1, extend_values);
check_enumeration(
enmr2, default_enmr_name, final_values, Datatype::INT32, 2, false);
Expand Down Expand Up @@ -952,7 +992,7 @@ TEST_CASE_METHOD(
memset(data, 1, 4);

Deserializer deserializer(tile.data(), tile.size());
REQUIRE_THROWS(Enumeration::deserialize(deserializer));
REQUIRE_THROWS(Enumeration::deserialize(deserializer, memory_tracker_));
}

TEST_CASE_METHOD(
Expand Down Expand Up @@ -1402,7 +1442,8 @@ TEST_CASE_METHOD(
data.data(),
data.size(),
offsets.data(),
offsets.size() * constants::cell_var_offset_size);
offsets.size() * constants::cell_var_offset_size,
memory_tracker_);

schema->add_enumeration(enmr);

Expand Down Expand Up @@ -1431,7 +1472,8 @@ TEST_CASE_METHOD(
data.data(),
data.size(),
offsets.data(),
offsets.size() * constants::cell_var_offset_size);
offsets.size() * constants::cell_var_offset_size,
memory_tracker_);
schema->add_enumeration(enmr);
}

Expand Down Expand Up @@ -1561,7 +1603,8 @@ TEST_CASE_METHOD(
enmr2->data().data(),
enmr2->data().size(),
enmr2->offsets().data(),
enmr2->offsets().size());
enmr2->offsets().size(),
memory_tracker_);

auto matcher = Catch::Matchers::ContainsSubstring(
"Enumeration path name for 'test_enmr' already exists in this schema.");
Expand Down Expand Up @@ -2224,7 +2267,15 @@ TEST_CASE_METHOD(
auto schema1 = create_schema();

auto enmr1 = Enumeration::create(
"empty_fixed", Datatype::INT32, 1, false, nullptr, 0, nullptr, 0);
"empty_fixed",
Datatype::INT32,
1,
false,
nullptr,
0,
nullptr,
0,
memory_tracker_);
auto enmr2 = Enumeration::create(
"empty_var",
Datatype::STRING_ASCII,
Expand All @@ -2233,7 +2284,8 @@ TEST_CASE_METHOD(
nullptr,
0,
nullptr,
0);
0,
memory_tracker_);

schema1->add_enumeration(enmr1);
schema1->add_enumeration(enmr2);
Expand Down Expand Up @@ -2529,7 +2581,8 @@ shared_ptr<const Enumeration> EnumerationFx::create_enumeration(
raw_values.data(),
raw_values.size() * sizeof(uint8_t),
nullptr,
0);
0,
memory_tracker_);
} else if constexpr (std::is_pod_v<T>) {
return Enumeration::create(
name,
Expand All @@ -2539,7 +2592,8 @@ shared_ptr<const Enumeration> EnumerationFx::create_enumeration(
values.data(),
values.size() * sizeof(T),
nullptr,
0);
0,
memory_tracker_);
} else {
uint64_t total_size = 0;
for (auto v : values) {
Expand All @@ -2565,14 +2619,23 @@ shared_ptr<const Enumeration> EnumerationFx::create_enumeration(
data.data(),
total_size,
offsets.data(),
offsets.size() * sizeof(uint64_t));
offsets.size() * sizeof(uint64_t),
memory_tracker_);
}
}

shared_ptr<const Enumeration> EnumerationFx::create_empty_enumeration(
Datatype type, uint32_t cell_val_num, bool ordered, std::string name) {
return Enumeration::create(
name, type, cell_val_num, ordered, nullptr, 0, nullptr, 0);
name,
type,
cell_val_num,
ordered,
nullptr,
0,
nullptr,
0,
memory_tracker_);
}

template <typename T>
Expand Down Expand Up @@ -2646,7 +2709,7 @@ void EnumerationFx::check_storage_deserialization(
auto tile = serialize_to_tile(enmr);

Deserializer deserializer(tile.data(), tile.size());
auto deserialized = Enumeration::deserialize(deserializer);
auto deserialized = Enumeration::deserialize(deserializer, memory_tracker_);

REQUIRE(deserialized->name() == enmr->name());
REQUIRE(deserialized->path_name().empty() == false);
Expand Down
3 changes: 2 additions & 1 deletion test/src/unit-request-handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ HandleLoadArraySchemaRequestFx::create_string_enumeration(
data.data(),
total_size,
offsets.data(),
offsets.size() * sizeof(uint64_t));
offsets.size() * sizeof(uint64_t),
tiledb::test::create_test_memory_tracker());
}

shared_ptr<ArraySchema> HandleLoadArraySchemaRequestFx::create_schema() {
Expand Down
Loading

0 comments on commit ae27122

Please sign in to comment.