ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ValgrindSvc Class Reference

#include <ValgrindSvc.h>

Inheritance diagram for ValgrindSvc:
Collaboration diagram for ValgrindSvc:

Public Member Functions

 ValgrindSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters: More...
 
virtual ~ValgrindSvc ()
 Destructor: More...
 
StatusCode initialize ()
 Gaudi Service Implementation. More...
 
StatusCode finalize ()
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 
void handle (const Incident &incident)
 incident service handle for Begin/EndEvent More...
 
virtual void callgrindStartInstrumentation ()
 Start callgrind instrumentation. More...
 
virtual void callgrindStopInstrumentation ()
 Stop callgrind instrumentation. More...
 
virtual void callgrindDumpStats (std::ostream &out)
 Dump callgrind profiling stats. More...
 
virtual void callgrindToggleCollect ()
 Toggle callgrind event collection. More...
 
virtual void valgrindDoLeakCheck ()
 Do a leak check now. More...
 
virtual unsigned int profileCount ()
 Number of created callgrind profiles. More...
 
MsgStream & msg () const
 
MsgStream & msg (const MSG::Level lvl) const
 
bool msgLvl (const MSG::Level lvl) const
 

Static Public Member Functions

static const InterfaceID & interfaceID ()
 I/O operators. More...
 

Private Member Functions

StatusCode makeAuditor (const std::string &audName, IAuditorSvc *audSvc)
 helper method to create auditors More...
 
 ValgrindSvc ()
 Default constructor: More...
 

Private Attributes

std::vector< std::string > m_algs
 List of algorithms to profile If list is empty, profile between begin/end event. More...
 
std::vector< std::string > m_intervals
 List of auditor intervals to profile Syntax: "MessageSvc.initialize:MessageSvc.finalize". More...
 
bool m_dumpAfterEachEvent
 Dump separate profile after each event. More...
 
bool m_dumpAfterEachInterval
 Dump separate profile after each interval. More...
 
unsigned int m_ignoreFirstNEvents
 Don't profile on the first N events. More...
 
std::vector< std::string > m_dumpAfterIncident
 List of incidents on which to create a profile dump. More...
 
unsigned int m_eventCounter
 Internal event counter for BeginEvent incident. More...
 
unsigned int m_profileCounter
 Counter of created profiles. More...
 

Friends

class SvcFactory< ValgrindSvc >
 

Detailed Description

Definition at line 31 of file ValgrindSvc.h.

Constructor & Destructor Documentation

◆ ValgrindSvc() [1/2]

ValgrindSvc::ValgrindSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor with parameters:

Definition at line 35 of file ValgrindSvc.cxx.

36  :
37  AthService(name, pSvcLocator),
38  m_eventCounter(0),
40 {
41  //
42  // Property declaration
43  //
44  declareProperty( "ProfiledAlgs", m_algs,
45  "List of profiled algorithms" );
46 
47  declareProperty( "ProfiledIntervals", m_intervals,
48  "Intervals to profile (e.g. 'MyAlg.initialize:MyAlg.finalize'" );
49 
50  declareProperty( "DumpAfterEachEvent", m_dumpAfterEachEvent = false,
51  "Dump separate profile after each event" );
52 
53  declareProperty( "DumpAfterEachInterval", m_dumpAfterEachInterval = true,
54  "Dump separate profile after each interval in ProfiledIntervals" );
55 
56  declareProperty( "DumpAfterIncident", m_dumpAfterIncident,
57  "List of incidents on which to dump a profile");
58 
59  declareProperty( "IgnoreFirstNEvents", m_ignoreFirstNEvents = 0,
60  "Do not profile the first N events");
61 
62  // for SvcHandle ? someday ?
63  //declareInterface<IValgrindSvc>(this);
64 }

◆ ~ValgrindSvc()

ValgrindSvc::~ValgrindSvc ( )
virtual

Destructor:

Definition at line 68 of file ValgrindSvc.cxx.

69 {}

◆ ValgrindSvc() [2/2]

ValgrindSvc::ValgrindSvc ( )
private

Default constructor:

Member Function Documentation

◆ callgrindDumpStats()

void ValgrindSvc::callgrindDumpStats ( std::ostream &  out)
virtual

Dump callgrind profiling stats.

Implements IValgrindSvc.

Definition at line 210 of file ValgrindSvc.cxx.

211 {
212  CALLGRIND_DUMP_STATS;
214 }

◆ callgrindStartInstrumentation()

void ValgrindSvc::callgrindStartInstrumentation ( )
virtual

Start callgrind instrumentation.

Implements IValgrindSvc.

Definition at line 195 of file ValgrindSvc.cxx.

196 {
197  CALLGRIND_START_INSTRUMENTATION;
198 }

◆ callgrindStopInstrumentation()

void ValgrindSvc::callgrindStopInstrumentation ( )
virtual

Stop callgrind instrumentation.

Implements IValgrindSvc.

Definition at line 200 of file ValgrindSvc.cxx.

201 {
202  CALLGRIND_STOP_INSTRUMENTATION;
203 }

◆ callgrindToggleCollect()

void ValgrindSvc::callgrindToggleCollect ( )
virtual

Toggle callgrind event collection.

Implements IValgrindSvc.

Definition at line 205 of file ValgrindSvc.cxx.

206 {
207  CALLGRIND_TOGGLE_COLLECT;
208 }

◆ finalize()

StatusCode ValgrindSvc::finalize ( )

Definition at line 117 of file ValgrindSvc.cxx.

118 {
119  ATH_MSG_INFO ("Finalizing " << name() << "...");
120  return StatusCode::SUCCESS;
121 }

◆ handle()

void ValgrindSvc::handle ( const Incident &  incident)

incident service handle for Begin/EndEvent

Definition at line 144 of file ValgrindSvc.cxx.

145 {
146  // Only use Begin/EndEvent incident if no profiled algorithm or interval is set
147  bool useEventIncident = m_intervals.empty() && m_algs.empty();
148 
149  // BeginEvent
150  if ( inc.type() == IncidentType::BeginEvent ) {
151  m_eventCounter++;
152  if ( useEventIncident && m_eventCounter > m_ignoreFirstNEvents) {
153  ATH_MSG_DEBUG ("[BeginEvent] Callgrind instrumentation ON.");
155  }
156  }
157 
158  // EndEvent
159  if ( inc.type() == IncidentType::EndEvent && (m_eventCounter > m_ignoreFirstNEvents) ) {
160  if ( useEventIncident ) {
162  ATH_MSG_DEBUG ("[EndEvent] Callgrind instrumentation OFF.");
163  }
164  if ( !m_algs.empty() && m_dumpAfterEachEvent ) {
166  ATH_MSG_INFO ("Creating callgrind profile #" << profileCount()
167  << " for event #" << m_eventCounter);
168  }
169  }
170 
171  // Optional additional dumps for user specified incidents
172  if ( std::find(m_dumpAfterIncident.begin(),
173  m_dumpAfterIncident.end(),
174  inc.type()) != m_dumpAfterIncident.end() ) {
176  ATH_MSG_INFO (" Creating callgrind profile #" << profileCount()
177  << " after incident [" << inc.type() << "].");
178  }
179 
180 }

◆ initialize()

StatusCode ValgrindSvc::initialize ( )

Gaudi Service Implementation.

Definition at line 73 of file ValgrindSvc.cxx.

74 {
75  ATH_MSG_DEBUG ("Initializing " << name());
76 
77  ATH_MSG_INFO ("My process ID is [" << System::procID() << "]");
78 
79  const bool insideValgrind = static_cast<bool>(RUNNING_ON_VALGRIND);
80  if ( insideValgrind ) {
81  ATH_MSG_INFO ("=== Running from inside Valgrind ! Hi there! ===");
82  }
83  else {
84  ATH_MSG_WARNING ("=== Valgrind is not running! ===");
85  }
86 
87  // Use incidents in case there is no auditor configured
88  if (!m_algs.empty() || !m_intervals.empty()) {
89 
90  // FIXME: We create the auditor here in C++ due to the lack of a
91  // configurable auditor.
92  makeAuditor("ValgrindAuditor",auditorSvc()).ignore();
93 
94  if ((auditorSvc()==0) || auditorSvc()->getAuditor("ValgrindAuditor")==0) {
95  ATH_MSG_ERROR ("Cannot find [ValgrindAuditor]. ");
96  return StatusCode::FAILURE;
97  }
98  else {
99  ATH_MSG_VERBOSE ("Found [ValgrindAuditor].");
100  }
101  }
102 
103  // Register incidents
104  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
105  ATH_CHECK(incSvc.retrieve());
106  incSvc->addListener( this, IncidentType::BeginEvent );
107  incSvc->addListener( this, IncidentType::EndEvent );
108 
109  for(const std::string& incident : m_dumpAfterIncident) {
110  incSvc->addListener( this, incident );
111  }
112 
113  return StatusCode::SUCCESS;
114 
115 }

◆ interfaceID()

const InterfaceID & ValgrindSvc::interfaceID ( )
inlinestatic

I/O operators.

Inline methods:

Definition at line 145 of file ValgrindSvc.h.

146 {
147  return IValgrindSvc::interfaceID();
148 }

◆ makeAuditor()

StatusCode ValgrindSvc::makeAuditor ( const std::string &  audName,
IAuditorSvc *  audSvc 
)
private

helper method to create auditors

Definition at line 224 of file ValgrindSvc.cxx.

226 {
227  if ( 0 == audSvc ) {
228  ATH_MSG_ERROR ("Null pointer to IAuditorSvc !!");
229  return StatusCode::FAILURE;
230  }
231 
232  if ( 0 != audSvc->getAuditor( audName ) ) {
233  ATH_MSG_VERBOSE ("AuditorSvc already knows about ["
234  << audName << "]... good.");
235  return StatusCode::SUCCESS;
236  }
237 
238  const std::string propName = "Auditors";
239  IProperty * audSvcProp = dynamic_cast<IProperty*>(audSvc);
240 
241  if ( 0 == audSvcProp ) {
242  ATH_MSG_ERROR ("Could not dyn-cast IAuditorSvc to an IProperty !!");
243  return StatusCode::FAILURE;
244  }
245 
246  StringArrayProperty audNames;
247  audNames.assign( audSvcProp->getProperty(propName) );
248  std::vector<std::string> updatedNames( audNames.value() );
249  updatedNames.push_back( audName );
250  audNames.set( updatedNames );
251  audNames.setName( propName );
252  if ( !audSvcProp->setProperty( audNames ).isSuccess() ) {
254  ("Could not add [" << audName
255  << "] to the list of auditors of [AuditorSvc] !!"
256  << endmsg
257  << audSvcProp->getProperty(propName));
258  return StatusCode::FAILURE;
259  }
260 
261  // make sure the auditor has been created...
262  if ( 0 == audSvc->getAuditor( audName ) ) {
263  ATH_MSG_ERROR ("Failed to make AuditorSvc instantiating ["
264  << audName << "] !!");
265  return StatusCode::FAILURE;
266  }
267 
268  ATH_MSG_VERBOSE ("[" << audName << "] successfully created.");
269  return StatusCode::SUCCESS;
270 }

◆ msg() [1/2]

MsgStream& AthCommonMsg< Service >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24  {
25  return this->msgStream();
26  }

◆ msg() [2/2]

MsgStream& AthCommonMsg< Service >::msg ( const MSG::Level  lvl) const
inlineinherited

Definition at line 27 of file AthCommonMsg.h.

27  {
28  return this->msgStream(lvl);
29  }

◆ msgLvl()

bool AthCommonMsg< Service >::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30  {
31  return this->msgLevel(lvl);
32  }

◆ profileCount()

virtual unsigned int ValgrindSvc::profileCount ( )
inlinevirtual

Number of created callgrind profiles.

Implements IValgrindSvc.

Definition at line 91 of file ValgrindSvc.h.

91 { return m_profileCounter; }

◆ queryInterface()

StatusCode ValgrindSvc::queryInterface ( const InterfaceID &  riid,
void **  ppvInterface 
)
virtual

Definition at line 124 of file ValgrindSvc.cxx.

125 {
126  if ( IValgrindSvc::interfaceID().versionMatch(riid) ) {
127  *ppvInterface = dynamic_cast<IValgrindSvc*>(this);
128  } else {
129  // Interface is not directly available : try out a base class
130  return AthService::queryInterface(riid, ppvInterface);
131  }
132  addRef();
133  return StatusCode::SUCCESS;
134 }

◆ valgrindDoLeakCheck()

void ValgrindSvc::valgrindDoLeakCheck ( )
virtual

Do a leak check now.

Implements IValgrindSvc.

Definition at line 216 of file ValgrindSvc.cxx.

217 {
218  VALGRIND_DO_LEAK_CHECK;
219 }

Friends And Related Function Documentation

◆ SvcFactory< ValgrindSvc >

friend class SvcFactory< ValgrindSvc >
friend

Definition at line 145 of file ValgrindSvc.h.

Member Data Documentation

◆ m_algs

std::vector<std::string> ValgrindSvc::m_algs
private

List of algorithms to profile If list is empty, profile between begin/end event.

Definition at line 113 of file ValgrindSvc.h.

◆ m_dumpAfterEachEvent

bool ValgrindSvc::m_dumpAfterEachEvent
private

Dump separate profile after each event.

Definition at line 120 of file ValgrindSvc.h.

◆ m_dumpAfterEachInterval

bool ValgrindSvc::m_dumpAfterEachInterval
private

Dump separate profile after each interval.

Definition at line 123 of file ValgrindSvc.h.

◆ m_dumpAfterIncident

std::vector<std::string> ValgrindSvc::m_dumpAfterIncident
private

List of incidents on which to create a profile dump.

Definition at line 129 of file ValgrindSvc.h.

◆ m_eventCounter

unsigned int ValgrindSvc::m_eventCounter
private

Internal event counter for BeginEvent incident.

Definition at line 132 of file ValgrindSvc.h.

◆ m_ignoreFirstNEvents

unsigned int ValgrindSvc::m_ignoreFirstNEvents
private

Don't profile on the first N events.

Definition at line 126 of file ValgrindSvc.h.

◆ m_intervals

std::vector<std::string> ValgrindSvc::m_intervals
private

List of auditor intervals to profile Syntax: "MessageSvc.initialize:MessageSvc.finalize".

Definition at line 117 of file ValgrindSvc.h.

◆ m_profileCounter

unsigned int ValgrindSvc::m_profileCounter
private

Counter of created profiles.

Definition at line 135 of file ValgrindSvc.h.


The documentation for this class was generated from the following files:
AthService::AthService
AthService()
ValgrindSvc::m_dumpAfterIncident
std::vector< std::string > m_dumpAfterIncident
List of incidents on which to create a profile dump.
Definition: ValgrindSvc.h:129
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
ValgrindSvc::m_eventCounter
unsigned int m_eventCounter
Internal event counter for BeginEvent incident.
Definition: ValgrindSvc.h:132
ValgrindSvc::callgrindStopInstrumentation
virtual void callgrindStopInstrumentation()
Stop callgrind instrumentation.
Definition: ValgrindSvc.cxx:200
ValgrindSvc::callgrindDumpStats
virtual void callgrindDumpStats(std::ostream &out)
Dump callgrind profiling stats.
Definition: ValgrindSvc.cxx:210
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ValgrindSvc::profileCount
virtual unsigned int profileCount()
Number of created callgrind profiles.
Definition: ValgrindSvc.h:91
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
ValgrindSvc::m_intervals
std::vector< std::string > m_intervals
List of auditor intervals to profile Syntax: "MessageSvc.initialize:MessageSvc.finalize".
Definition: ValgrindSvc.h:117
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ValgrindSvc::makeAuditor
StatusCode makeAuditor(const std::string &audName, IAuditorSvc *audSvc)
helper method to create auditors
Definition: ValgrindSvc.cxx:224
ValgrindSvc::m_dumpAfterEachInterval
bool m_dumpAfterEachInterval
Dump separate profile after each interval.
Definition: ValgrindSvc.h:123
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ValgrindSvc::m_ignoreFirstNEvents
unsigned int m_ignoreFirstNEvents
Don't profile on the first N events.
Definition: ValgrindSvc.h:126
ValgrindSvc::callgrindStartInstrumentation
virtual void callgrindStartInstrumentation()
Start callgrind instrumentation.
Definition: ValgrindSvc.cxx:195
IValgrindSvc
Abstract interface for ValgrindSvc. FIXME.
Definition: IValgrindSvc.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ValgrindSvc::m_dumpAfterEachEvent
bool m_dumpAfterEachEvent
Dump separate profile after each event.
Definition: ValgrindSvc.h:120
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
L1CaloPhase1Monitoring.propName
propName
Definition: L1CaloPhase1Monitoring.py:349
ValgrindSvc::m_algs
std::vector< std::string > m_algs
List of algorithms to profile If list is empty, profile between begin/end event.
Definition: ValgrindSvc.h:113
ValgrindSvc::m_profileCounter
unsigned int m_profileCounter
Counter of created profiles.
Definition: ValgrindSvc.h:135
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< Service >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
IValgrindSvc::interfaceID
static const InterfaceID & interfaceID()
Definition: IValgrindSvc.h:71
ServiceHandle< IIncidentSvc >