Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012
Public Member Functions | Private Types | Private Member Functions | Private Attributes

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:
Inheritance graph
[legend]
Collaboration diagram for TimingAuditor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void before (StandardEventType evt, INamedInterface *alg)
 The following methods are meant to be implemented by the child class...
virtual void after (StandardEventType evt, INamedInterface *alg, const StatusCode &sc)
virtual void before (CustomEventTypeRef evt, const std::string &name)
virtual void after (CustomEventTypeRef evt, const std::string &name, const StatusCode &sc)
virtual void handle (const Incident &)
 Inform that a new incident has occurred.
virtual StatusCode initialize ()
 factory:
virtual StatusCode finalize ()
 TimingAuditor (const std::string &name, ISvcLocator *pSvc)
 standard constructor
virtual ~TimingAuditor ()
 virtual destructor

Private Types

typedef GaudiUtils::VectorMap
< const INamedInterface *, int > 
Map
typedef GaudiUtils::HashMap
< std::string, int > 
MapUser

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)
 TimingAuditor ()
 TimingAuditor (const TimingAuditor &)
TimingAuditoroperator= (const TimingAuditor &)

Private Attributes

IToolSvcm_toolSvc
 tool service
IIncidentSvcm_incSvc
 incident service
ISequencerTimerToolm_timer
 the timer tool
INamedInterfacem_appMgr
 ApplicationManager.
Map m_map
int m_indent
 indentation level
bool m_inEvent
 "In event" flag
bool m_goodForDOD
 "optimized for DOD"
MapUser m_mapUser
 map used to record user timing events
bool m_histoSaved

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 ibelyaev@physics.syr.edu
Date:
2007-01-31

Definition at line 33 of file TimingAuditor.cpp.


Member Typedef Documentation

Definition at line 101 of file TimingAuditor.cpp.

Definition at line 110 of file TimingAuditor.cpp.


Constructor & Destructor Documentation

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

standard constructor

Definition at line 62 of file TimingAuditor.cpp.

    : base_class ( name , pSvc )
    //
    , m_toolSvc    ( 0 )
    , m_incSvc     ( 0 )
    //
    , m_timer      ( 0 )
    //
    , m_appMgr     ( 0 )
    //
    , m_map        (       )
    , m_indent     ( 0     )
    , m_inEvent    ( false )
    , m_goodForDOD ( false )
    , m_mapUser    (       )
    , m_histoSaved ( false )
  {
    declareProperty ( "OptimizedForDOD" , m_goodForDOD ) ;
  } ;
virtual TimingAuditor::~TimingAuditor (  ) [inline, virtual]

virtual destructor

Definition at line 83 of file TimingAuditor.cpp.

{}
TimingAuditor::TimingAuditor (  ) [private]
TimingAuditor::TimingAuditor ( const TimingAuditor  ) [private]

Member Function Documentation

void TimingAuditor::after ( StandardEventType  evt,
INamedInterface alg,
const StatusCode sc 
) [virtual]

Reimplemented from Auditor.

Definition at line 220 of file TimingAuditor.cpp.

{
  switch (evt) {
  case IAuditor::Initialize : i_afterInitialize( alg ); break;
  case IAuditor::Execute    : i_afterExecute( alg ); break;
  default: break;
  }
}
void TimingAuditor::after ( CustomEventTypeRef  evt,
const std::string name,
const StatusCode sc 
) [virtual]

Reimplemented from Auditor.

Definition at line 326 of file TimingAuditor.cpp.

{
  // Ignore obvious mistakes
  if ( name.empty() && evt.empty() ) { return; }

  // look for the user timer in the map
  std::string nick = name + ":" + evt;
  MapUser::iterator found = m_mapUser.find( nick );

  // We cannot do much if the timer is not available
  if ( m_mapUser.end() == found ) {
    MsgStream log(msgSvc(), this->name());
    log << MSG::WARNING << "Trying to stop the measure  of the timing for '"
                        << nick << "' but it was never started. Check the code"
                        << endmsg;
    return;
  }
  m_timer->stop( found->second );
}
void TimingAuditor::before ( StandardEventType  evt,
INamedInterface obj 
) [virtual]

The following methods are meant to be implemented by the child class...

Reimplemented from Auditor.

Definition at line 210 of file TimingAuditor.cpp.

{
  switch (evt) {
  case IAuditor::Initialize : i_beforeInitialize( alg ); break;
  case IAuditor::Execute    : i_beforeExecute( alg );    break;
  case IAuditor::Finalize   : i_beforeFinalize( alg );   break;
  default: break;
  }
}
void TimingAuditor::before ( CustomEventTypeRef  evt,
const std::string name 
) [virtual]

Reimplemented from Auditor.

Definition at line 304 of file TimingAuditor.cpp.

{
  // Ignore obvious mistakes
  if ( name.empty() && evt.empty() ) { return; }

  // look for the user timer in the map
  int timer = 0;
  std::string nick = name + ":" + evt;
  MapUser::iterator found = m_mapUser.find( nick );

  if ( m_mapUser.end() == found ) {
    // add a new timer if not yet available
    timer = m_timer->addTimer( nick ) ;
    m_mapUser[nick] = timer;
  }
  else {
    timer = found->second;
  }

  m_timer->start( timer );
}
StatusCode TimingAuditor::finalize (  ) [virtual]

Reimplemented from Auditor.

Definition at line 184 of file TimingAuditor.cpp.

{
  if ( 0 != m_incSvc )
  {
    m_incSvc -> removeListener ( this , IncidentType::BeginEvent ) ;
    m_incSvc -> removeListener ( this , IncidentType::EndEvent   ) ;
    m_incSvc -> release () ;
    m_incSvc = 0 ;
  }
  if ( 0 != m_toolSvc )
  {
    // the 2 following line are commented out: it is
    // is a temporary hack which prevent a crash due to a problem in
    // the reference counting
    //     if ( 0 != m_timer )
    //     { m_toolSvc -> releaseTool ( m_timer ) . ignore() ; m_timer = 0 ; }
    m_toolSvc -> release () ;
    m_toolSvc = 0 ;
  }
  if ( 0 != m_appMgr ) { m_appMgr -> release () ;  m_appMgr = 0 ; }
  // clear the map
  m_map.clear() ;
  // finalize the base class
  return Auditor::finalize () ;
}
void TimingAuditor::handle ( const Incident i ) [virtual]

Inform that a new incident has occurred.

Implements IIncidentListener.

Definition at line 346 of file TimingAuditor.cpp.

{
  if      ( IncidentType::BeginEvent == i.type () )
  {
    m_timer -> start ( m_map[ m_appMgr ] ) ;
    ++m_indent ;
    m_inEvent = true ;
  }
  else if ( IncidentType::EndEvent   == i.type () )
  {
    m_timer -> stop  ( m_map[ m_appMgr ] ) ;
    --m_indent ;
    m_inEvent = false ;
  }
}
void TimingAuditor::i_afterExecute ( INamedInterface alg ) [private]

Definition at line 295 of file TimingAuditor.cpp.

{
  if ( 0 == alg ) { return ; }
  Map::iterator found = m_map.find( alg ) ;
  if ( m_map.end() == found ) { return ; }
  m_timer->stop( found->second ) ;
  --m_indent ;
}
void TimingAuditor::i_afterInitialize ( INamedInterface alg ) [private]

Definition at line 264 of file TimingAuditor.cpp.

{
  if ( m_goodForDOD ) { return ; }
  if ( 0 == alg     ) { return ; }
  --m_indent ;
}
void TimingAuditor::i_beforeExecute ( INamedInterface alg ) [private]

Definition at line 271 of file TimingAuditor.cpp.

{
  if ( 0 == alg ) { return ; }
  ++m_indent ;
  Map::iterator found = m_map.find( alg ) ;
  if ( m_map.end() == found )
  {
    MsgStream log( msgSvc() , name() ) ;
    log << MSG::DEBUG
        << "Insert non-structural component '"
        << alg->name() << "' of type '"
        << System::typeinfoName(typeid(*alg)) << "' at level "
        << m_indent << endmsg ;
    std::string nick = alg->name() ;
    if ( 0 < m_indent  ) { nick = std::string ( m_indent , ' ') + nick ; }
    if ( !m_goodForDOD ) { nick[0]='*' ;}
    int timer = m_timer->addTimer( nick ) ;
    m_map.insert ( alg , timer ) ;
    m_timer->start( timer ) ;
    return ;
  }
  m_timer->start( found->second ) ;
}
void TimingAuditor::i_beforeFinalize ( INamedInterface alg ) [private]

Definition at line 229 of file TimingAuditor.cpp.

{
  if (!m_histoSaved)
  {
    m_timer->saveHistograms();
    m_histoSaved = true;
  }
}
void TimingAuditor::i_beforeInitialize ( INamedInterface alg ) [private]

Definition at line 239 of file TimingAuditor.cpp.

{
  if ( m_goodForDOD ) { return ; }
  //
  if ( 0 == alg ) { return ; }
  Map::iterator found = m_map.find( alg ) ;
  if ( m_map.end() != found ) { return ; }
  ++m_indent ;
  std::string nick = alg->name() ;
  if ( 0 < m_indent ) { nick = std::string ( m_indent , ' ') + nick ; }
  if ( m_inEvent )
  {
    nick[0] = '*' ;
    MsgStream log( msgSvc() , name() ) ;
    log << MSG::DEBUG
        << "Insert non-structural component '"
        << alg->name() << "' of type '"
        << System::typeinfoName(typeid(*alg)) << "' at level "
        << m_indent << endmsg ;
  }
  int timer = m_timer->addTimer( nick ) ;
  m_map.insert ( alg , timer ) ;
  m_timer->start( timer ) ;
}
StatusCode TimingAuditor::initialize (  ) [virtual]

factory:

Reimplemented from Auditor.

Definition at line 123 of file TimingAuditor.cpp.

{
  StatusCode sc = Auditor::initialize() ;
  if ( sc.isFailure() ) { return sc ; }                  // RETURN

  MsgStream log ( msgSvc() , name() ) ;

  // get tool service
  if ( 0 == m_toolSvc )
  {
    sc = Auditor::service ( "ToolSvc" , m_toolSvc ) ;
    if ( sc.isFailure() )
    {
      log << "Could not retrieve 'ToolSvc' " << sc << endmsg ;
      return sc ;                                        // RETURN
    }
    if ( 0 == m_timer )
    {
      sc = m_toolSvc->retrieveTool
        ( "SequencerTimerTool/TIMER" , m_timer , this  , true ) ;
      if ( sc.isFailure() )
      {
        log << MSG::ERROR
            << "Could not retrieve ISequencerTimerTool" << endmsg ;
        return sc ;
      }
    }
  }
  // get incident service
  if ( 0 == m_incSvc )
  {
    sc = Auditor::service ( "IncidentSvc" , m_incSvc ) ;
    if ( sc.isFailure() )
    {
      log << MSG::ERROR
          << "Could not retrieve 'IncidentSvc'" << sc << endmsg ;
      return sc ;
    }
    m_incSvc -> addListener ( this , IncidentType::BeginEvent ) ;
    m_incSvc -> addListener ( this , IncidentType::EndEvent   ) ;
  }
  // get the application manager
  if ( 0 == m_appMgr )
  {
    sc = Auditor::service ( "ApplicationMgr" , m_appMgr ) ;
    if ( sc.isFailure() )
    {
      log << MSG::ERROR
          << "Could not retrieve 'ApplicationMgr'" << sc << endmsg ;
      return sc ;
    }
    if ( m_map.end() == m_map.find( m_appMgr ) )
    {
      int timer = m_timer->addTimer( "EVENT LOOP" ) ;
      m_map.insert ( m_appMgr , timer ) ;
    }
  }
  //
  return StatusCode::SUCCESS ;
}
TimingAuditor& TimingAuditor::operator= ( const TimingAuditor  ) [private]

Member Data Documentation

ApplicationManager.

Definition at line 99 of file TimingAuditor.cpp.

"optimized for DOD"

Definition at line 108 of file TimingAuditor.cpp.

Definition at line 114 of file TimingAuditor.cpp.

incident service

Definition at line 95 of file TimingAuditor.cpp.

int TimingAuditor::m_indent [private]

indentation level

Definition at line 104 of file TimingAuditor.cpp.

bool TimingAuditor::m_inEvent [private]

"In event" flag

Definition at line 106 of file TimingAuditor.cpp.

Definition at line 102 of file TimingAuditor.cpp.

map used to record user timing events

Definition at line 111 of file TimingAuditor.cpp.

the timer tool

Definition at line 97 of file TimingAuditor.cpp.

tool service

Definition at line 93 of file TimingAuditor.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:52 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004