ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | 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...
 
virtual StatusCode initialize () override
 Gaudi Service Implementation. More...
 
virtual StatusCode finalize () override
 
virtual void handle (const Incident &incident) override
 incident service handle for Begin/EndEvent More...
 
virtual void callgrindStartInstrumentation () override
 Start callgrind instrumentation. More...
 
virtual void callgrindStopInstrumentation () override
 Stop callgrind instrumentation. More...
 
virtual void callgrindDumpStats (std::ostream &out) override
 Dump callgrind profiling stats. More...
 
virtual void callgrindToggleCollect () override
 Toggle callgrind event collection. More...
 
virtual void valgrindDoLeakCheck () override
 Do a leak check now. More...
 
virtual unsigned int profileCount () override
 Number of created callgrind profiles. More...
 

Private Member Functions

StatusCode makeAuditor (const std::string &audName, IAuditorSvc *audSvc)
 helper method to create auditors 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...
 

Detailed Description

Definition at line 29 of file ValgrindSvc.h.

Constructor & Destructor Documentation

◆ ValgrindSvc()

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

Constructor with parameters:

Definition at line 35 of file ValgrindSvc.cxx.

36  :
37  base_class(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 }

◆ ~ValgrindSvc()

ValgrindSvc::~ValgrindSvc ( )
virtual

Destructor:

Definition at line 65 of file ValgrindSvc.cxx.

66 {}

Member Function Documentation

◆ callgrindDumpStats()

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

Dump callgrind profiling stats.

Definition at line 194 of file ValgrindSvc.cxx.

195 {
196  CALLGRIND_DUMP_STATS;
198 }

◆ callgrindStartInstrumentation()

void ValgrindSvc::callgrindStartInstrumentation ( )
overridevirtual

Start callgrind instrumentation.

Definition at line 179 of file ValgrindSvc.cxx.

180 {
181  CALLGRIND_START_INSTRUMENTATION;
182 }

◆ callgrindStopInstrumentation()

void ValgrindSvc::callgrindStopInstrumentation ( )
overridevirtual

Stop callgrind instrumentation.

Definition at line 184 of file ValgrindSvc.cxx.

185 {
186  CALLGRIND_STOP_INSTRUMENTATION;
187 }

◆ callgrindToggleCollect()

void ValgrindSvc::callgrindToggleCollect ( )
overridevirtual

Toggle callgrind event collection.

Definition at line 189 of file ValgrindSvc.cxx.

190 {
191  CALLGRIND_TOGGLE_COLLECT;
192 }

◆ finalize()

StatusCode ValgrindSvc::finalize ( )
overridevirtual

Definition at line 114 of file ValgrindSvc.cxx.

115 {
116  ATH_MSG_INFO ("Finalizing " << name() << "...");
117  return StatusCode::SUCCESS;
118 }

◆ handle()

void ValgrindSvc::handle ( const Incident &  incident)
overridevirtual

incident service handle for Begin/EndEvent

Definition at line 128 of file ValgrindSvc.cxx.

129 {
130  // Only use Begin/EndEvent incident if no profiled algorithm or interval is set
131  bool useEventIncident = m_intervals.empty() && m_algs.empty();
132 
133  // BeginEvent
134  if ( inc.type() == IncidentType::BeginEvent ) {
135  m_eventCounter++;
136  if ( useEventIncident && m_eventCounter > m_ignoreFirstNEvents) {
137  ATH_MSG_DEBUG ("[BeginEvent] Callgrind instrumentation ON.");
139  }
140  }
141 
142  // EndEvent
143  if ( inc.type() == IncidentType::EndEvent && (m_eventCounter > m_ignoreFirstNEvents) ) {
144  if ( useEventIncident ) {
146  ATH_MSG_DEBUG ("[EndEvent] Callgrind instrumentation OFF.");
147  }
148  if ( !m_algs.empty() && m_dumpAfterEachEvent ) {
150  ATH_MSG_INFO ("Creating callgrind profile #" << profileCount()
151  << " for event #" << m_eventCounter);
152  }
153  }
154 
155  // Optional additional dumps for user specified incidents
156  if ( std::find(m_dumpAfterIncident.begin(),
157  m_dumpAfterIncident.end(),
158  inc.type()) != m_dumpAfterIncident.end() ) {
160  ATH_MSG_INFO (" Creating callgrind profile #" << profileCount()
161  << " after incident [" << inc.type() << "].");
162  }
163 
164 }

◆ initialize()

StatusCode ValgrindSvc::initialize ( )
overridevirtual

Gaudi Service Implementation.

Definition at line 70 of file ValgrindSvc.cxx.

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

◆ makeAuditor()

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

helper method to create auditors

Definition at line 208 of file ValgrindSvc.cxx.

210 {
211  if ( 0 == audSvc ) {
212  ATH_MSG_ERROR ("Null pointer to IAuditorSvc !!");
213  return StatusCode::FAILURE;
214  }
215 
216  if ( 0 != audSvc->getAuditor( audName ) ) {
217  ATH_MSG_VERBOSE ("AuditorSvc already knows about ["
218  << audName << "]... good.");
219  return StatusCode::SUCCESS;
220  }
221 
222  const std::string propName = "Auditors";
223  IProperty * audSvcProp = dynamic_cast<IProperty*>(audSvc);
224 
225  if ( 0 == audSvcProp ) {
226  ATH_MSG_ERROR ("Could not dyn-cast IAuditorSvc to an IProperty !!");
227  return StatusCode::FAILURE;
228  }
229 
230  StringArrayProperty audNames;
231  audNames.assign( audSvcProp->getProperty(propName) );
232  std::vector<std::string> updatedNames( audNames.value() );
233  updatedNames.push_back( audName );
234  audNames.set( updatedNames );
235  audNames.setName( propName );
236  if ( !audSvcProp->setProperty( audNames ).isSuccess() ) {
238  ("Could not add [" << audName
239  << "] to the list of auditors of [AuditorSvc] !!"
240  << endmsg
241  << audSvcProp->getProperty(propName));
242  return StatusCode::FAILURE;
243  }
244 
245  // make sure the auditor has been created...
246  if ( 0 == audSvc->getAuditor( audName ) ) {
247  ATH_MSG_ERROR ("Failed to make AuditorSvc instantiating ["
248  << audName << "] !!");
249  return StatusCode::FAILURE;
250  }
251 
252  ATH_MSG_VERBOSE ("[" << audName << "] successfully created.");
253  return StatusCode::SUCCESS;
254 }

◆ profileCount()

virtual unsigned int ValgrindSvc::profileCount ( )
inlineoverridevirtual

Number of created callgrind profiles.

Definition at line 69 of file ValgrindSvc.h.

69 { return m_profileCounter; }

◆ valgrindDoLeakCheck()

void ValgrindSvc::valgrindDoLeakCheck ( )
overridevirtual

Do a leak check now.

Definition at line 200 of file ValgrindSvc.cxx.

201 {
202  VALGRIND_DO_LEAK_CHECK;
203 }

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 88 of file ValgrindSvc.h.

◆ m_dumpAfterEachEvent

bool ValgrindSvc::m_dumpAfterEachEvent
private

Dump separate profile after each event.

Definition at line 95 of file ValgrindSvc.h.

◆ m_dumpAfterEachInterval

bool ValgrindSvc::m_dumpAfterEachInterval
private

Dump separate profile after each interval.

Definition at line 98 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 104 of file ValgrindSvc.h.

◆ m_eventCounter

unsigned int ValgrindSvc::m_eventCounter
private

Internal event counter for BeginEvent incident.

Definition at line 107 of file ValgrindSvc.h.

◆ m_ignoreFirstNEvents

unsigned int ValgrindSvc::m_ignoreFirstNEvents
private

Don't profile on the first N events.

Definition at line 101 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 92 of file ValgrindSvc.h.

◆ m_profileCounter

unsigned int ValgrindSvc::m_profileCounter
private

Counter of created profiles.

Definition at line 110 of file ValgrindSvc.h.


The documentation for this class was generated from the following files:
ValgrindSvc::m_dumpAfterIncident
std::vector< std::string > m_dumpAfterIncident
List of incidents on which to create a profile dump.
Definition: ValgrindSvc.h:104
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:107
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
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:92
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:208
ValgrindSvc::m_dumpAfterEachInterval
bool m_dumpAfterEachInterval
Dump separate profile after each interval.
Definition: ValgrindSvc.h:98
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:101
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ValgrindSvc::m_dumpAfterEachEvent
bool m_dumpAfterEachEvent
Dump separate profile after each event.
Definition: ValgrindSvc.h:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
L1CaloPhase1Monitoring.propName
propName
Definition: L1CaloPhase1Monitoring.py:451
ValgrindSvc::callgrindStartInstrumentation
virtual void callgrindStartInstrumentation() override
Start callgrind instrumentation.
Definition: ValgrindSvc.cxx:179
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:88
ValgrindSvc::m_profileCounter
unsigned int m_profileCounter
Counter of created profiles.
Definition: ValgrindSvc.h:110
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ValgrindSvc::callgrindStopInstrumentation
virtual void callgrindStopInstrumentation() override
Stop callgrind instrumentation.
Definition: ValgrindSvc.cxx:184
ValgrindSvc::callgrindDumpStats
virtual void callgrindDumpStats(std::ostream &out) override
Dump callgrind profiling stats.
Definition: ValgrindSvc.cxx:194
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ServiceHandle< IIncidentSvc >
ValgrindSvc::profileCount
virtual unsigned int profileCount() override
Number of created callgrind profiles.
Definition: ValgrindSvc.h:69