diff --git a/src/DataStructures/DataBox/DataBox.hpp b/src/DataStructures/DataBox/DataBox.hpp index 5b12b6c0f5b90..f59d42eba3c07 100644 --- a/src/DataStructures/DataBox/DataBox.hpp +++ b/src/DataStructures/DataBox/DataBox.hpp @@ -559,8 +559,19 @@ std::map DataBox>::size_of_items() (void)this; using tag = tmpl::type_from; if constexpr (not db::is_reference_tag_v) { - const auto& item = get_item(); - result[pretty_type::get_name()] = size_of_object_in_bytes(item); + // For item of ItemType::Compute, this will not evaluate its function + // (i.e. if the item has never been evaluated its size will be that of a + // default initialized object) + const auto& item = get_item().get(); + if constexpr (tt::is_a_v) { + if (item == nullptr) { + result[pretty_type::get_name()] = 0; + } else { + result[pretty_type::get_name()] = size_of_object_in_bytes(*item); + } + } else { + result[pretty_type::get_name()] = size_of_object_in_bytes(item); + } } }; tmpl::for_each(add_item_size); diff --git a/src/ParallelAlgorithms/Events/ObserveDataBox.hpp b/src/ParallelAlgorithms/Events/ObserveDataBox.hpp index 1ee7afffd5a0e..601396dd07d01 100644 --- a/src/ParallelAlgorithms/Events/ObserveDataBox.hpp +++ b/src/ParallelAlgorithms/Events/ObserveDataBox.hpp @@ -53,7 +53,7 @@ struct ReduceDataBoxSize { auto& observer_writer_proxy = Parallel::get_parallel_component< observers::ObserverWriter>(cache); const std::string subfile_name = - "/ObserveDataBox/" + pretty_type::name(); + "/DataBoxSizeInMb/" + pretty_type::name(); std::vector legend; legend.reserve(item_sizes.size() + 1); legend.emplace_back("Time"); @@ -95,6 +95,13 @@ struct ContributeDataBoxSize { }; } // namespace detail +/// \brief Event that will collect the size in MBs used by each DataBox item on +/// each parallel component. +/// +/// \details The data will be written to disk in the reductions file under the +/// `/DataBoxSizeInMb/` group. The name of each file is the `pretty_type::name` +/// of each parallel component. There will be a column for each item in the +/// DataBox that is not a subitem or reference item. class ObserveDataBox : public Event { public: /// \cond diff --git a/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp b/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp index 2f57332972ebf..baf7a5a54d253 100644 --- a/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp +++ b/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp @@ -3269,9 +3269,36 @@ void test_output() { CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag1") == 32); CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag2") == 24); CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag4Compute") == - 9); + 8); CHECK(item_size.at("(anonymous namespace)::test_databox_tags::Tag5Compute") == - 29); + 28); + + const auto box_with_ptrs = + db::create, + db::AddComputeTags>( + std::make_unique(3)); + const auto item_size_ptrs = box_with_ptrs.size_of_items(); + CHECK(item_size_ptrs.size() == 3); + CHECK(item_size_ptrs.at( + "(anonymous namespace)::test_databox_tags::Pointer") == 4); + CHECK(item_size_ptrs.at( + "(anonymous " + "namespace)::test_databox_tags::PointerToCounterCompute") == 0); + CHECK(item_size_ptrs.at( + "(anonymous namespace)::test_databox_tags::PointerToSumCompute") == + 0); + db::get(box_with_ptrs); + const auto item_size_ptrs_after = box_with_ptrs.size_of_items(); + CHECK(item_size_ptrs_after.size() == 3); + CHECK(item_size_ptrs_after.at( + "(anonymous namespace)::test_databox_tags::Pointer") == 4); + CHECK(item_size_ptrs_after.at( + "(anonymous " + "namespace)::test_databox_tags::PointerToCounterCompute") == 4); + CHECK(item_size_ptrs_after.at( + "(anonymous namespace)::test_databox_tags::PointerToSumCompute") == + 4); } void test_exception_safety() {