Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
StalledEventMonitor.cpp
Go to the documentation of this file.
1 /*
2  * StalledEventMonitor.cpp
3  *
4  * Created on: Apr 19, 2010
5  * Author: Marco Clemencic
6  */
7 
8 // Include files
9 #include "StalledEventMonitor.h"
10 
13 #include "GaudiKernel/Memory.h"
14 
15 namespace {
17  class EventWatchdog: public WatchdogThread {
18  public:
19  EventWatchdog(const SmartIF<IMessageSvc> &msgSvc,
20  const std::string &name,
21  boost::posix_time::time_duration timeout,
22  bool autostart = false):
23  WatchdogThread(timeout, autostart),
24  log(msgSvc, name),
25  m_counter(0) {}
26  virtual ~EventWatchdog() {}
27  private:
28  MsgStream log;
29  long m_counter;
30  void action() {
31  if (!m_counter) {
32  log << MSG::WARNING << "More than " << getTimeout().total_seconds()
33  << "s since the last " << IncidentType::BeginEvent << endmsg;
34  } else {
35  log << MSG::WARNING << "Other " << getTimeout().total_seconds()
36  << "s passed" << endmsg;
37  }
38  log << MSG::INFO << "Current memory usage is"
39  " virtual size = " << System::virtualMemory() / 1024. << " MB"
40  ", resident set size = " << System::pagedMemory() / 1024.<< " MB"
41  << endmsg;
42  ++m_counter;
43  }
44  void onPing() {
45  if (m_counter) {
46  if (m_counter >= 3)
47  log << MSG::INFO << "Starting a new event after ~"
48  << m_counter * getTimeout().total_seconds() << "s" << endmsg;
49  m_counter = 0;
50  }
51  }
52  void onStop() {
53  if (m_counter >= 3)
54  log << MSG::INFO << "The last event took ~"
55  << m_counter * getTimeout().total_seconds() << "s" << endmsg;
56  }
57  };
58 }
59 
60 // Constructor
62  base_class(name, svcLoc) {
63 
64  declareProperty("EventTimeout", m_eventTimeout = 600,
65  "Number of seconds allowed to process a single event (0 to disable the check)");
66 
67 }
68 
69 // Destructor
71 
72 }
73 
74 // Initialization of the service.
77  if (sc.isFailure()) return sc;
78 
79 
80  if (m_eventTimeout) {
81  // create the watchdog thread
83  new EventWatchdog(msgSvc(),
84  "EventWatchdog",
85  boost::posix_time::seconds(m_eventTimeout)));
86 
87  // register to the incident service
88  std::string serviceName = "IncidentSvc";
89  m_incidentSvc = serviceLocator()->service(serviceName);
90  if ( ! m_incidentSvc ) {
91  error() << "Cannot retrieve " << serviceName << endmsg;
92  return StatusCode::FAILURE;
93  }
94  debug() << "Register to the IncidentSvc" << endmsg;
95  m_incidentSvc->addListener(this, IncidentType::BeginEvent);
96  } else {
97  warning() << "StalledEventMonitor/" << name()
98  << " instantiated with 0 time-out: no monitoring performed" << endmsg;
99  }
100 
101  return StatusCode::SUCCESS;
102 }
103 
104 // Start the monitoring.
106  if (m_watchdog.get()) m_watchdog->start();
107  return StatusCode::SUCCESS;
108 }
109 
110 // Notify the watchdog that a new event has been started
111 void StalledEventMonitor::handle(const Incident& /* incident */) {
112  if (m_watchdog.get()) m_watchdog->ping();
113 }
114 
115 // Start the monitoring.
117  if (m_watchdog.get()) m_watchdog->stop();
118  return StatusCode::SUCCESS;
119 }
120 
121 // Finalization of the service.
123  // destroy the watchdog thread (if any)
124  m_watchdog.reset();
125  // unregistering from the IncidentSvc
126  m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
128  return base_class::finalize();
129 }
130 
131 // Declaration of the factory
132 #include "GaudiKernel/SvcFactory.h"

Generated at Wed Jan 30 2013 17:13:41 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004