14#include "valgrind/valgrind.h"
15#include "valgrind/memcheck.h"
16#include "valgrind/callgrind.h"
19#include "Gaudi/Property.h"
20#include "GaudiKernel/IIncidentSvc.h"
21#include "GaudiKernel/Incident.h"
22#include "GaudiKernel/ServiceHandle.h"
23#include "GaudiKernel/Memory.h"
36 ISvcLocator* pSvcLocator ) :
37 base_class(name, pSvcLocator),
44 declareProperty(
"ProfiledAlgs",
m_algs,
45 "List of profiled algorithms" );
48 "Intervals to profile (e.g. 'MyAlg.initialize:MyAlg.finalize'" );
51 "Dump separate profile after each event" );
54 "Dump separate profile after each interval in ProfiledIntervals" );
57 "List of incidents on which to dump a profile");
60 "Do not profile the first N events");
74 ATH_MSG_INFO (
"My process ID is [" << System::procID() <<
"]");
76 const bool insideValgrind =
static_cast<bool>(RUNNING_ON_VALGRIND);
77 if ( insideValgrind ) {
78 ATH_MSG_INFO (
"=== Running from inside Valgrind ! Hi there! ===");
86 ATH_CHECK( auditorSvc()->addAuditor(
"ValgrindAuditor") );
92 incSvc->addListener(
this, IncidentType::BeginEvent );
93 incSvc->addListener(
this, IncidentType::EndEvent );
96 incSvc->addListener(
this, incident );
99 return StatusCode::SUCCESS;
106 return StatusCode::SUCCESS;
123 if ( inc.type() == IncidentType::BeginEvent ) {
126 ATH_MSG_DEBUG (
"[BeginEvent] Callgrind instrumentation ON.");
133 if ( useEventIncident ) {
150 <<
" after incident [" << inc.type() <<
"].");
170 CALLGRIND_START_INSTRUMENTATION;
175 CALLGRIND_STOP_INSTRUMENTATION;
180 CALLGRIND_TOGGLE_COLLECT;
185 CALLGRIND_DUMP_STATS;
191 VALGRIND_DO_LEAK_CHECK;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::vector< std::string > m_intervals
List of auditor intervals to profile Syntax: "MessageSvc.initialize:MessageSvc.finalize".
virtual void callgrindDumpStats(std::ostream &out) override
Dump callgrind profiling stats.
virtual void callgrindStopInstrumentation() override
Stop callgrind instrumentation.
bool m_dumpAfterEachInterval
Dump separate profile after each interval.
std::vector< std::string > m_dumpAfterIncident
List of incidents on which to create a profile dump.
virtual ~ValgrindSvc()
Destructor:
virtual void valgrindDoLeakCheck() override
Do a leak check now.
bool m_dumpAfterEachEvent
Dump separate profile after each event.
virtual void handle(const Incident &incident) override
incident service handle for Begin/EndEvent
unsigned int m_eventCounter
Internal event counter for BeginEvent incident.
virtual void callgrindToggleCollect() override
Toggle callgrind event collection.
virtual void callgrindStartInstrumentation() override
Start callgrind instrumentation.
virtual StatusCode finalize() override
virtual unsigned int profileCount() override
Number of created callgrind profiles.
std::vector< std::string > m_algs
List of algorithms to profile If list is empty, profile between begin/end event.
ValgrindSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
unsigned int m_ignoreFirstNEvents
Don't profile on the first N events.
unsigned int m_profileCounter
Counter of created profiles.
virtual StatusCode initialize() override
Gaudi Service Implementation.