14#include "GaudiKernel/IScheduler.h"
15#include "GaudiKernel/ServiceHandle.h"
27 incSvc->addListener(
this,
"EndAlgorithms", 0);
29 return StatusCode::SUCCESS;
37 [[maybe_unused]]
static const bool initThread = [&](){
46 *m_eventStartTime.get(ctx) = clock_t::now();
48 return StatusCode::SUCCESS;
54 if (inc.type() ==
"EndAlgorithms") {
55 ATH_MSG_DEBUG(
"Resetting event timeout for slot " << inc.context().slot());
57 *m_eventStartTime.get(inc.context()) = {};
64 if (m_thread.joinable() && !
m_stopped.exchange(
true)) {
71 return StatusCode::SUCCESS;
77 ATH_MSG_INFO(std::format(
"Setting per-event timeout of {}",
78 std::chrono::duration<double>(
m_timeout)));
81 const std::chrono::nanoseconds wakeup_interval =
86 while ( stop_signal.wait_for(wakeup_interval) == std::future_status::timeout ) {
89 const auto now = clock_t::now();
90 for (EventContext::ContextID_t slot = 0;
91 const auto& startTime : m_eventStartTime) {
93 if (startTime.time_since_epoch().count() > 0 && now > startTime +
m_timeout) {
109 const EventContext ctx(0, slot);
115 const std::string
msg = std::format(
"Event timeout ({}) in slot {} reached",
116 std::chrono::duration<double>(
m_timeout), slot);
125 if (schedulerSvc.retrieve().isSuccess()) {
126 schedulerSvc->dumpState();
137 if ( coreDumpSvc.retrieve().isSuccess() ) {
141 std::cerr <<
msg << std::endl;
#define ATH_CHECK
Evaluate an expression and check for errors.
Interface of a core dump service.
void setTimeout(Timeout &instance)
Set timeout.
static Timeout & instance()
Get reference to Timeout singleton.
virtual void setCoreDumpInfo(const std::string &name, const std::string &value) override
Set a name/value pair in the core dump record.
Algorithm to monitor event timeouts.
std::promise< void > m_stop_thread
Signal to stop watchdog thread.
void handleTimeout(EventContext::ContextID_t slot)
Handle timeout.
Gaudi::Property< bool > m_dumpState
virtual void handle(const Incident &inc) override
std::mutex m_handleMutex
Mutex for handleTimeout.
virtual StatusCode stop() override
Gaudi::Property< bool > m_abort
std::atomic< bool > m_stopped
Has watchdog thread already been stopped? (to avoid setting future twice)
Gaudi::Property< unsigned long long > m_timeoutProp
void timeoutThread()
Watchdog thread.
virtual StatusCode execute(const EventContext &ctx) const override
std::chrono::nanoseconds m_timeout
Timeout property as duration.
SG::SlotSpecificObj< clock_t::time_point > m_eventStartTime ATLAS_THREAD_SAFE
Start time of each event per slot.
Gaudi::Property< unsigned long long > m_checkInterval
virtual StatusCode initialize() override
Algorithm to monitor event timeouts.