Skip to content

Commit

Permalink
Update for OPENPMD_VERBOSE logging (#1574)
Browse files Browse the repository at this point in the history
* Log intercepted I/O exceptions in verbose mode

* Fix undefined behavior in verbose logging of deregister task
  • Loading branch information
franzpoeschel authored Dec 18, 2023
1 parent c34bcea commit 8e8d88e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
13 changes: 11 additions & 2 deletions include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "openPMD/backend/Attribute.hpp"
#include "openPMD/backend/ParsePreference.hpp"

#include <cstddef>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -680,15 +681,23 @@ template <>
struct OPENPMDAPI_EXPORT Parameter<Operation::DEREGISTER>
: public AbstractParameter
{
Parameter() = default;
Parameter(Parameter const &) : AbstractParameter()
Parameter(void const *ptr_in) : former_parent(ptr_in)
{}

Parameter(Parameter const &) = default;
Parameter(Parameter &&) = default;

Parameter &operator=(Parameter const &) = default;
Parameter &operator=(Parameter &&) = default;

std::unique_ptr<AbstractParameter> to_heap() && override
{
return std::make_unique<Parameter<Operation::DEREGISTER>>(
std::move(*this));
}

// Just for verbose logging.
void const *former_parent = nullptr;
};

/** @brief Self-contained description of a single IO operation.
Expand Down
50 changes: 41 additions & 9 deletions src/IO/AbstractIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,24 +358,56 @@ std::future<void> AbstractIOHandlerImpl::flush()
auto &parameter = deref_dynamic_cast<Parameter<O::DEREGISTER>>(
i.parameter.get());
writeToStderr(
"[", i.writable->parent, "->", i.writable, "] DEREGISTER");
"[",
parameter.former_parent,
"->",
i.writable,
"] DEREGISTER");
deregister(i.writable, parameter);
break;
}
}
}
catch (...)
{
std::cerr << "[AbstractIOHandlerImpl] IO Task "
<< internal::operationAsString(i.operation)
<< " failed with exception. Clearing IO queue and "
"passing on the exception."
<< std::endl;
while (!m_handler->m_work.empty())
auto base_handler = [&i, this]() {
std::cerr << "[AbstractIOHandlerImpl] IO Task "
<< internal::operationAsString(i.operation)
<< " failed with exception. Clearing IO queue and "
"passing on the exception."
<< std::endl;
while (!m_handler->m_work.empty())
{
m_handler->m_work.pop();
}
};

if (m_verboseIOTasks)
{
try
{
// Throw again so we can distinguish between std::exception
// and other exception types.
throw;
}
catch (std::exception const &e)
{
base_handler();
std::cerr << "Original exception: " << e.what()
<< std::endl;
throw;
}
catch (...)
{
base_handler();
throw;
}
}
else
{
m_handler->m_work.pop();
base_handler();
throw;
}
throw;
}
(*m_handler).m_work.pop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/Writable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Writable::~Writable()
* remove references to this object from internal data structures.
*/
IOHandler->value()->enqueue(
IOTask(this, Parameter<Operation::DEREGISTER>()));
IOTask(this, Parameter<Operation::DEREGISTER>(parent)));
}

void Writable::seriesFlush(std::string backendConfig)
Expand Down

0 comments on commit 8e8d88e

Please sign in to comment.