TimingAuditor Class Reference

Simple auditor which uses SequencerTimerTool for ALL algorithms, including the algorithm from main Gaudi "TopAlg" list and algorithms managed by Data-On-Demand Service. More...

Inheritance diagram for TimingAuditor:
Collaboration diagram for TimingAuditor:

Public Member Functions

void before (StandardEventType evt, INamedInterface *alg) override
 
void after (StandardEventType evt, INamedInterface *alg, const StatusCode &sc) override
 
void before (CustomEventTypeRef evt, const std::string &name) override
 
void after (CustomEventTypeRef evt, const std::string &name, const StatusCode &sc) override
 
void handle (const Incident &) override
 Inform that a new incident has occurred. More...
 
StatusCode initialize () override
 factory: More...
 
StatusCode finalize () override
 
 TimingAuditor (const std::string &name, ISvcLocator *pSvc)
 standard constructor More...
 
 ~TimingAuditor () override=default
 destructor More...
 
 TimingAuditor ()=delete
 
 TimingAuditor (const TimingAuditor &)=delete
 
TimingAuditoroperator= (const TimingAuditor &)=delete
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Member Functions

void i_beforeInitialize (INamedInterface *alg)
 
void i_afterInitialize (INamedInterface *alg)
 
void i_beforeFinalize (INamedInterface *alg)
 
void i_beforeExecute (INamedInterface *alg)
 
void i_afterExecute (INamedInterface *alg)
 

Private Attributes

SmartIF< IToolSvcm_toolSvc = nullptr
 tool service More...
 
SmartIF< IIncidentSvcm_incSvc = nullptr
 incident service More...
 
ISequencerTimerToolm_timer = nullptr
 the timer tool More...
 
SmartIF< INamedInterfacem_appMgr = nullptr
 ApplicationManager. More...
 
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
 
int m_indent = 0
 indentation level More...
 
bool m_inEvent = false
 "In event" flag More...
 
bool m_goodForDOD = false
 "optimized for DOD" More...
 
GaudiUtils::HashMap< std::string, int > m_mapUser
 map used to record user timing events More...
 
bool m_histoSaved = false
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

Simple auditor which uses SequencerTimerTool for ALL algorithms, including the algorithm from main Gaudi "TopAlg" list and algorithms managed by Data-On-Demand Service.

Author
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-01-31

Definition at line 28 of file TimingAuditor.cpp.

Constructor & Destructor Documentation

TimingAuditor::TimingAuditor ( const std::string &  name,
ISvcLocator pSvc 
)
inline

standard constructor

Definition at line 56 of file TimingAuditor.cpp.

57  : base_class ( name , pSvc )
58  {
59  declareProperty ( "OptimizedForDOD" , m_goodForDOD ) ;
60  }
extends base_class
Typedef to this class.
Definition: extends.h:14
bool m_goodForDOD
"optimized for DOD"
TimingAuditor::~TimingAuditor ( )
overridedefault

destructor

TimingAuditor::TimingAuditor ( )
delete
TimingAuditor::TimingAuditor ( const TimingAuditor )
delete

Member Function Documentation

void TimingAuditor::after ( StandardEventType  evt,
INamedInterface alg,
const StatusCode sc 
)
override

Definition at line 192 of file TimingAuditor.cpp.

193 {
194  switch (evt) {
195  case IAuditor::Initialize : i_afterInitialize( alg ); break;
196  case IAuditor::Execute : i_afterExecute( alg ); break;
197  default: break;
198  }
199 }
void i_afterInitialize(INamedInterface *alg)
void i_afterExecute(INamedInterface *alg)
void TimingAuditor::after ( CustomEventTypeRef  evt,
const std::string &  name,
const StatusCode sc 
)
override

Definition at line 295 of file TimingAuditor.cpp.

296 {
297  // Ignore obvious mistakes
298  if ( name.empty() && evt.empty() ) { return; }
299 
300  // look for the user timer in the map
301  std::string nick = name + ":" + evt;
302  auto found = m_mapUser.find( nick );
303 
304  // We cannot do much if the timer is not available
305  if ( m_mapUser.end() == found ) {
306  MsgStream log(msgSvc(), this->name());
307  log << MSG::WARNING << "Trying to stop the measure of the timing for '"
308  << nick << "' but it was never started. Check the code"
309  << endmsg;
310  return;
311  }
312  m_timer->stop( found->second );
313 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
GaudiUtils::HashMap< std::string, int > m_mapUser
map used to record user timing events
iterator end()
Definition: Map.h:132
iterator find(const key_type &key)
Definition: Map.h:149
ISequencerTimerTool * m_timer
the timer tool
virtual double stop(int index)=0
stop the counter, return the elapsed time
void TimingAuditor::before ( StandardEventType  evt,
INamedInterface alg 
)
override

Definition at line 182 of file TimingAuditor.cpp.

183 {
184  switch (evt) {
185  case IAuditor::Initialize : i_beforeInitialize( alg ); break;
186  case IAuditor::Execute : i_beforeExecute( alg ); break;
187  case IAuditor::Finalize : i_beforeFinalize( alg ); break;
188  default: break;
189  }
190 }
void i_beforeInitialize(INamedInterface *alg)
void i_beforeExecute(INamedInterface *alg)
void i_beforeFinalize(INamedInterface *alg)
void TimingAuditor::before ( CustomEventTypeRef  evt,
const std::string &  name 
)
override

Definition at line 275 of file TimingAuditor.cpp.

276 {
277  // Ignore obvious mistakes
278  if ( name.empty() && evt.empty() ) { return; }
279 
280  // look for the user timer in the map
281  int timer = 0;
282  std::string nick = name + ":" + evt;
283  auto found = m_mapUser.find( nick );
284 
285  if ( m_mapUser.end() == found ) {
286  // add a new timer if not yet available
287  timer = m_timer->addTimer( nick ) ;
288  m_mapUser[nick] = timer;
289  } else {
290  timer = found->second;
291  }
292  m_timer->start( timer );
293 }
virtual int addTimer(const std::string &name)=0
add a timer entry with the specified name
GaudiUtils::HashMap< std::string, int > m_mapUser
map used to record user timing events
iterator end()
Definition: Map.h:132
iterator find(const key_type &key)
Definition: Map.h:149
virtual void start(int index)=0
start the counter, i.e.
ISequencerTimerTool * m_timer
the timer tool
StatusCode TimingAuditor::finalize ( )
override

Definition at line 158 of file TimingAuditor.cpp.

159 {
160  if ( m_incSvc )
161  {
162  m_incSvc -> removeListener ( this , IncidentType::BeginEvent ) ;
163  m_incSvc -> removeListener ( this , IncidentType::EndEvent ) ;
164  m_incSvc.reset();
165  }
166  if ( m_toolSvc )
167  {
168  // the 2 following line are commented out: it is
169  // is a temporary hack which prevent a crash due to a problem in
170  // the reference counting
171  // if ( 0 != m_timer )
172  // { m_toolSvc -> releaseTool ( m_timer ) . ignore() ; m_timer = 0 ; }
173  m_toolSvc.reset();
174  }
175  m_appMgr.reset();
176  // clear the map
177  m_map.clear() ;
178  // finalize the base class
179  return Auditor::finalize () ;
180 }
virtual StatusCode finalize()
Definition: Auditor.cpp:207
SmartIF< INamedInterface > m_appMgr
ApplicationManager.
SmartIF< IIncidentSvc > m_incSvc
incident service
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
void clear()
clear the container
Definition: VectorMap.h:497
SmartIF< IToolSvc > m_toolSvc
tool service
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
void TimingAuditor::handle ( const Incident i)
override

Inform that a new incident has occurred.

Definition at line 315 of file TimingAuditor.cpp.

316 {
317  if ( IncidentType::BeginEvent == i.type () ) {
318  m_timer -> start ( m_map[ m_appMgr.get() ] ) ;
319  ++m_indent ;
320  m_inEvent = true ;
321  } else if ( IncidentType::EndEvent == i.type () ) {
322  m_timer -> stop ( m_map[ m_appMgr.get() ] ) ;
323  --m_indent ;
324  m_inEvent = false ;
325  }
326 }
const std::string & type() const
Access to the incident type.
Definition: Incident.h:34
bool m_inEvent
"In event" flag
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
int m_indent
indentation level
SmartIF< INamedInterface > m_appMgr
ApplicationManager.
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
ISequencerTimerTool * m_timer
the timer tool
tuple start
Definition: IOTest.py:88
void TimingAuditor::i_afterExecute ( INamedInterface alg)
private

Definition at line 266 of file TimingAuditor.cpp.

267 {
268  if ( !alg ) { return ; }
269  auto found = m_map.find( alg ) ;
270  if ( m_map.end() == found ) { return ; }
271  m_timer->stop( found->second ) ;
272  --m_indent ;
273 }
iterator find(const key_type &key) const
find the element by key
Definition: VectorMap.h:455
int m_indent
indentation level
iterator end() const
"end" iterator for sequential access (const-only version!)
Definition: VectorMap.h:198
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
ISequencerTimerTool * m_timer
the timer tool
virtual double stop(int index)=0
stop the counter, return the elapsed time
void TimingAuditor::i_afterInitialize ( INamedInterface alg)
private

Definition at line 236 of file TimingAuditor.cpp.

237 {
238  if ( m_goodForDOD || !alg ) { return ; }
239  --m_indent ;
240 }
int m_indent
indentation level
bool m_goodForDOD
"optimized for DOD"
void TimingAuditor::i_beforeExecute ( INamedInterface alg)
private

Definition at line 242 of file TimingAuditor.cpp.

243 {
244  if ( !alg ) { return ; }
245  ++m_indent ;
246  auto found = m_map.find( alg ) ;
247  if ( m_map.end() == found )
248  {
249  MsgStream log( msgSvc() , name() ) ;
250  log << MSG::DEBUG
251  << "Insert non-structural component '"
252  << alg->name() << "' of type '"
253  << System::typeinfoName(typeid(*alg)) << "' at level "
254  << m_indent << endmsg ;
255  std::string nick = alg->name() ;
256  if ( 0 < m_indent ) { nick = std::string ( m_indent , ' ') + nick ; }
257  if ( !m_goodForDOD ) { nick[0]='*' ;}
258  int timer = m_timer->addTimer( nick ) ;
259  m_map.insert ( alg , timer ) ;
260  m_timer->start( timer ) ;
261  return ;
262  }
263  m_timer->start( found->second ) ;
264 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual int addTimer(const std::string &name)=0
add a timer entry with the specified name
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
result_type insert(const key_type &key, const mapped_type &mapped)
insert the (key,value) pair into the container
Definition: VectorMap.h:317
virtual const std::string & name() const =0
Retrieve the name of the instance.
iterator find(const key_type &key) const
find the element by key
Definition: VectorMap.h:455
int m_indent
indentation level
iterator end() const
"end" iterator for sequential access (const-only version!)
Definition: VectorMap.h:198
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
virtual void start(int index)=0
start the counter, i.e.
ISequencerTimerTool * m_timer
the timer tool
bool m_goodForDOD
"optimized for DOD"
void TimingAuditor::i_beforeFinalize ( INamedInterface alg)
private

Definition at line 201 of file TimingAuditor.cpp.

202 {
203  if (!m_histoSaved)
204  {
206  m_histoSaved = true;
207  }
208 }
virtual void saveHistograms()=0
prepares and saves the timing histograms
ISequencerTimerTool * m_timer
the timer tool
void TimingAuditor::i_beforeInitialize ( INamedInterface alg)
private

Definition at line 211 of file TimingAuditor.cpp.

212 {
213  if ( m_goodForDOD ) { return ; }
214  //
215  if ( !alg ) { return ; }
216  auto found = m_map.find( alg ) ;
217  if ( m_map.end() != found ) { return ; }
218  ++m_indent ;
219  std::string nick = alg->name() ;
220  if ( 0 < m_indent ) { nick = std::string ( m_indent , ' ') + nick ; }
221  if ( m_inEvent )
222  {
223  nick[0] = '*' ;
224  MsgStream log( msgSvc() , name() ) ;
225  log << MSG::DEBUG
226  << "Insert non-structural component '"
227  << alg->name() << "' of type '"
228  << System::typeinfoName(typeid(*alg)) << "' at level "
229  << m_indent << endmsg ;
230  }
231  int timer = m_timer->addTimer( nick ) ;
232  m_map.insert ( alg , timer ) ;
233  m_timer->start( timer ) ;
234 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual int addTimer(const std::string &name)=0
add a timer entry with the specified name
bool m_inEvent
"In event" flag
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:297
result_type insert(const key_type &key, const mapped_type &mapped)
insert the (key,value) pair into the container
Definition: VectorMap.h:317
virtual const std::string & name() const =0
Retrieve the name of the instance.
iterator find(const key_type &key) const
find the element by key
Definition: VectorMap.h:455
int m_indent
indentation level
iterator end() const
"end" iterator for sequential access (const-only version!)
Definition: VectorMap.h:198
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
virtual void start(int index)=0
start the counter, i.e.
ISequencerTimerTool * m_timer
the timer tool
bool m_goodForDOD
"optimized for DOD"
StatusCode TimingAuditor::initialize ( )
override

factory:

Definition at line 98 of file TimingAuditor.cpp.

99 {
101  if ( sc.isFailure() ) { return sc ; } // RETURN
102 
103  MsgStream log ( msgSvc() , name() ) ;
104 
105  // get tool service
106  if ( ! m_toolSvc )
107  {
108  m_toolSvc = Auditor::service ( "ToolSvc" );
109  if ( !m_toolSvc )
110  {
111  log << "Could not retrieve 'ToolSvc' " << endmsg ;
112  return StatusCode::FAILURE ; // RETURN
113  }
114  if ( !m_timer )
115  {
116  sc = m_toolSvc->retrieveTool
117  ( "SequencerTimerTool/TIMER" , m_timer , this , true ) ;
118  if ( sc.isFailure() )
119  {
120  log << MSG::ERROR
121  << "Could not retrieve ISequencerTimerTool" << endmsg ;
122  return sc ;
123  }
124  }
125  }
126  // get incident service
127  if ( !m_incSvc )
128  {
129  m_incSvc = Auditor::service ( "IncidentSvc" );
130  if ( !m_incSvc )
131  {
132  log << MSG::ERROR
133  << "Could not retrieve 'IncidentSvc'" << endmsg ;
134  return StatusCode::FAILURE ;
135  }
136  m_incSvc -> addListener ( this , IncidentType::BeginEvent ) ;
137  m_incSvc -> addListener ( this , IncidentType::EndEvent ) ;
138  }
139  // get the application manager
140  if ( !m_appMgr )
141  {
142  m_appMgr = Auditor::service ( "ApplicationMgr" );
143  if ( !m_appMgr )
144  {
145  log << MSG::ERROR
146  << "Could not retrieve 'ApplicationMgr'" << endmsg ;
147  return sc ;
148  }
149  if ( m_map.end() == m_map.find( m_appMgr.get() ) )
150  {
151  m_map.insert ( m_appMgr.get() , m_timer->addTimer( "EVENT LOOP" ) ) ;
152  }
153  }
154  //
155  return StatusCode::SUCCESS ;
156 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode service(const std::string &name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Auditor.h:119
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual int addTimer(const std::string &name)=0
add a timer entry with the specified name
result_type insert(const key_type &key, const mapped_type &mapped)
insert the (key,value) pair into the container
Definition: VectorMap.h:317
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode retrieveTool(const std::string &type, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name automatically assigned...
Definition: IToolSvc.h:145
iterator find(const key_type &key) const
find the element by key
Definition: VectorMap.h:455
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
iterator end() const
"end" iterator for sequential access (const-only version!)
Definition: VectorMap.h:198
SmartIF< INamedInterface > m_appMgr
ApplicationManager.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
SmartIF< IIncidentSvc > m_incSvc
incident service
GaudiUtils::VectorMap< const INamedInterface *, int > m_map
SmartIF< IToolSvc > m_toolSvc
tool service
ISequencerTimerTool * m_timer
the timer tool
virtual StatusCode initialize()
Definition: Auditor.cpp:91
TimingAuditor& TimingAuditor::operator= ( const TimingAuditor )
delete

Member Data Documentation

SmartIF<INamedInterface> TimingAuditor::m_appMgr = nullptr
private

ApplicationManager.

Definition at line 76 of file TimingAuditor.cpp.

bool TimingAuditor::m_goodForDOD = false
private

"optimized for DOD"

Definition at line 84 of file TimingAuditor.cpp.

bool TimingAuditor::m_histoSaved = false
private

Definition at line 89 of file TimingAuditor.cpp.

SmartIF<IIncidentSvc> TimingAuditor::m_incSvc = nullptr
private

incident service

Definition at line 72 of file TimingAuditor.cpp.

int TimingAuditor::m_indent = 0
private

indentation level

Definition at line 80 of file TimingAuditor.cpp.

bool TimingAuditor::m_inEvent = false
private

"In event" flag

Definition at line 82 of file TimingAuditor.cpp.

GaudiUtils::VectorMap<const INamedInterface*,int> TimingAuditor::m_map
private

Definition at line 78 of file TimingAuditor.cpp.

GaudiUtils::HashMap<std::string,int> TimingAuditor::m_mapUser
private

map used to record user timing events

Definition at line 86 of file TimingAuditor.cpp.

ISequencerTimerTool* TimingAuditor::m_timer = nullptr
private

the timer tool

Definition at line 74 of file TimingAuditor.cpp.

SmartIF<IToolSvc> TimingAuditor::m_toolSvc = nullptr
private

tool service

Definition at line 70 of file TimingAuditor.cpp.


The documentation for this class was generated from the following file: