Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/umpire/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <iterator>
#include <memory>
#include <sstream>
#include <unordered_set>
#include <algorithm>

#include "umpire/Umpire.hpp"
#include "umpire/config.hpp"
Expand Down Expand Up @@ -1093,9 +1095,38 @@ int ResourceManager::getNextId() noexcept
std::string ResourceManager::getAllocatorInformation() const noexcept
{
std::ostringstream info;
std::unordered_set<std::string> 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()) {
Comment thread
kab163 marked this conversation as resolved.
append_name(name);
}

std::vector<std::string> 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();
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/resource_manager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading