8 #include "GaudiKernel/Auditor.h"
9 #include "GaudiKernel/IAuditorSvc.h"
10 #include "GaudiKernel/GaudiException.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/IIncidentListener.h"
13 #include "GaudiKernel/IIncidentSvc.h"
15 #include "GaudiAlg/GaudiSequencer.h"
16 #include "GaudiAlg/Sequencer.h"
18 #include "boost/assign/list_of.hpp"
20 #ifdef TCMALLOC_OLD_GOOGLE_HEADERS
21 #include "google/heap-profiler.h"
22 #include "google/heap-checker.h"
23 #include "google/profiler.h"
25 #include "gperftools/heap-profiler.h"
26 #include "gperftools/heap-checker.h"
27 #include "gperftools/profiler.h"
57 auto inSvc = serviceLocator()->service<
IIncidentSvc>(
"IncidentSvc");
59 inSvc->addListener(
this, IncidentType::BeginEvent );
105 return ( dynamic_cast<GaudiSequencer*>(i) != NULL ||
106 dynamic_cast<Sequencer*>(i) != NULL );
125 const std::string& name )
const
127 std::ostringstream t;
128 t << name <<
"-" <<
type;
129 if ( type ==
"Execute" ) t <<
"-Event" <<
m_nEvts;
142 if ( IncidentType::BeginEvent == incident.
type() )
193 std::ostringstream t;
206 <<
"Starting Auditor for " << s <<
":" << type
214 <<
"Auditor already running. Cannot be started for " << s
224 std::ostringstream t;
240 std::ostringstream t;
315 , m_log (
msgSvc() , name )
318 , m_sampleEventCount( 0 )
319 , m_inFullAudit ( false )
323 const std::vector<std::string> tmp =
324 boost::assign::list_of
334 declareProperty(
"ActivateAt",
m_when,
335 "List of phases to activate the Auditoring during" );
336 declareProperty(
"DisableFor",
m_veto,
337 "List of component names to disable the auditing for" );
338 declareProperty(
"EnableFor",
m_list );
339 declareProperty(
"ProfileFreq",
m_freq = -1,
340 "The frequence to audit events. -1 means all events" );
342 "If true, instead of individually auditing components, the full event (or events) will be audited in one go" );
344 "The number of events to include in a full event audit, if enabled" );
346 "Number of events to skip before activating the auditing" );
348 "If true, auditing will be skipped for Sequencer objects." );
381 HeapProfilerStart(s.c_str());
388 HeapProfilerDump(s.c_str());
392 const char * profile = GetHeapProfile();
442 const char * HEAPCHECK = getenv(
"HEAPCHECK");
446 <<
"Environment variable HEAPCHECK must be set to 'local'"
450 if ( std::string(HEAPCHECK) !=
"local" )
453 <<
"Environment variable HEAPCHECK is set to " << HEAPCHECK
454 <<
" Partial Program Heap Checking is disabled"
468 m_checker =
new HeapLeakChecker(s.c_str());
524 ProfilerStart((s+
".prof").c_str());
StatusCode finalize()
Finalize the auditor base.
HeapLeakChecker * m_checker
void beforeBeginRun(INamedInterface *i)
Definition of the MsgStream class used to transmit messages.
std::string m_startedBy
Name of the component we are currently auditing.
HeapChecker(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
void beforeReinitialize(INamedInterface *i)
void stopAudit()
stop a full event audit
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
bool m_printProfilesToLog
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
const std::string & type() const
Access to the incident type.
virtual void google_before(const std::string &s)=0
Start the google tool.
virtual ~AuditorBase()
Destructor.
bool m_audit
Internal flag to say if auditing is enabled or not for the current event.
void before(CustomEventTypeRef type, const std::string &s)
void startAudit()
Start a full event audit.
unsigned long long m_nSampleEvents
Number of events to include in a full event audit.
virtual bool alreadyRunning()=0
check if we are already running the tool
bool m_inFullAudit
Internal flag to indicate if we are current in a full event audit.
bool isFailure() const
Test for a status code of FAILURE.
unsigned long long m_sampleEventCount
Internal count of the number of events currently processed during an audit.
int m_freq
The frequency to audit events. -1 means all events.
void before(CustomEventTypeRef type, INamedInterface *i)
virtual const std::string & name() const =0
Retrieve the name of the instance.
bool alreadyRunning()
check if we are already running the tool
StatusCode initialize()
Initialize the auditor base.
void google_after(const std::string &)
stop the google tool
void after(CustomEventTypeRef type, const std::string &s, const StatusCode &)
void afterExecute(INamedInterface *i, const StatusCode &s)
unsigned long long m_nEvts
Number of events processed.
void after(CustomEventTypeRef type, INamedInterface *i, const StatusCode &sc)
bool isPhaseEnabled(CustomEventTypeRef type) const
Check if auditing is enabled for the current processing phase.
void beforeExecute(INamedInterface *i)
void google_before(const std::string &s)
Start the google tool.
This class is used for returning status codes from appropriate routines.
#define DECLARE_COMPONENT(type)
void google_after(const std::string &s)
stop the google tool
std::vector< std::string > m_list
Any component in this list will be audited. If empty, all will be done.
Auditor using the Google Heap Checker.
std::string getDumpName(CustomEventTypeRef type, const std::string &name) const
void afterBeginRun(INamedInterface *i)
bool m_fullEventAudit
Flag to indicate if full event auditing is enabled or not.
void google_before(const std::string &s)
Start the google tool.
void google_after(const std::string &s)
stop the google tool
bool alreadyRunning()
check if we are already running the tool
HeapProfiler(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
void afterFinalize(INamedInterface *i)
void afterReinitialize(INamedInterface *i)
void afterInitialize(INamedInterface *i)
std::vector< std::string > m_when
When to audit the algorithms.
void beforeEndRun(INamedInterface *i)
IInterface compliant class extending IInterface with the name() method.
void beforeInitialize(INamedInterface *i)
void beforeFinalize(INamedInterface *i)
Base class used to extend a class implementing other interfaces.
Base class for all Incidents (computing events).
void before(StandardEventType type, INamedInterface *i)
void handle(const Incident &incident)
Implement the handle method for the Incident service.
void google_before(const std::string &s)
Start the google tool.
MsgStream m_log
Messaging object.
void before(StandardEventType type, const std::string &s)
void after(StandardEventType type, INamedInterface *i, const StatusCode &sc)
CPUProfiler(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< std::string > m_veto
Veto list. Any component in this list will not be audited.
AuditorBase(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
void afterEndRun(INamedInterface *i)
unsigned long long m_eventsToSkip
Number of events to skip before auditing.
Base for Google Auditors.
virtual void google_after(const std::string &s)=0
stop the google tool
bool alreadyRunning()
check if we are already running the tool
Auditor using the Google CPU Profiler.
bool m_skipSequencers
Boolean indicating if sequencers should be skipped or not.
The interface implemented by the IncidentSvc service.
void after(StandardEventType type, const std::string &s, const StatusCode &sc)
bool isComponentEnabled(const std::string &name) const
Check if auditing is enabled for the given component.
Auditor based on the Google Heap Profiler.
bool isSequencer(INamedInterface *i) const
Check if the component in question is a GaudiSequencer or a Sequencer.