diff --git a/src/umpire/ResourceManager.cpp b/src/umpire/ResourceManager.cpp index 8c31492a4..af01124db 100644 --- a/src/umpire/ResourceManager.cpp +++ b/src/umpire/ResourceManager.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "umpire/Umpire.hpp" #include "umpire/config.hpp" @@ -1093,9 +1095,38 @@ int ResourceManager::getNextId() noexcept std::string ResourceManager::getAllocatorInformation() const noexcept { std::ostringstream info; + std::unordered_set seen_names; + bool has_names{false}; - for (auto& it : m_allocators_by_name) { - info << *it.second << " "; + const auto append_name = [&](const std::string& name) { + if (name == s_null_resource_name || name == s_zero_byte_pool_name) { + return; + } + + if (seen_names.insert(name).second) { + info << "\n - " << name; + has_names = true; + } + }; + + for (const auto& name : resource::MemoryResourceRegistry::getInstance().getResourceNames()) { + append_name(name); + } + + std::vector extra_names; + extra_names.reserve(m_allocators_by_name.size()); + + for (const auto& it : m_allocators_by_name) { + extra_names.push_back(it.first); + } + + std::sort(extra_names.begin(), extra_names.end()); + for (const auto& name : extra_names) { + append_name(name); + } + + if (!has_names) { + info << " (none)"; } return info.str(); diff --git a/tests/unit/resource_manager_tests.cpp b/tests/unit/resource_manager_tests.cpp index 30e5cb5ca..33b1af833 100644 --- a/tests/unit/resource_manager_tests.cpp +++ b/tests/unit/resource_manager_tests.cpp @@ -55,6 +55,21 @@ TEST(ResourceManager, getAllocatorByName) ASSERT_THROW(rm.getAllocator("BANANA"), umpire::runtime_error); } +TEST(ResourceManager, getAllocatorByNameErrorListsAvailableAllocators) +{ + auto& rm = umpire::ResourceManager::getInstance(); + + try { + UMPIRE_USE_VAR(rm.getAllocator("BANANA")); + FAIL() << "Expected getAllocator to throw"; + } catch (const umpire::runtime_error& e) { + const std::string message{e.what()}; + EXPECT_NE(message.find("Available allocators:"), std::string::npos); + EXPECT_NE(message.find("\n - HOST"), std::string::npos); + EXPECT_EQ(message.find("__umpire_internal_null"), std::string::npos); + } +} + TEST(ResourceManager, getAllocatorById) { auto& rm = umpire::ResourceManager::getInstance();