ATLAS Offline Software
Public Member Functions | List of all members
ValgrindAuditor Class Reference

Valgrind auditor. More...

#include <ValgrindAuditor.h>

Inheritance diagram for ValgrindAuditor:
Collaboration diagram for ValgrindAuditor:

Public Member Functions

 ValgrindAuditor (const std::string &name, ISvcLocator *pSvcLocator)
 
virtual ~ValgrindAuditor ()
 
virtual StatusCode initialize ()
 
virtual void handle (const Incident &incident)
 Incident handler. More...
 
before Auditor hooks
virtual void before (StandardEventType evt, const std::string &name)
 
virtual void before (StandardEventType evt, INamedInterface *alg)
 
virtual void before (CustomEventTypeRef evt, INamedInterface *alg)
 
virtual void before (CustomEventTypeRef evt, const std::string &name)
 

after Auditor hooks

typedef std::pair< boost::regex, std::string > NameEvt
 Typedef for algorithm/event pair, e.g. ("MyAlg","initialize") More...
 
ServiceHandle< IValgrindSvcm_valSvc
 Handle to ValgrindSvc. More...
 
std::vector< std::string > m_algs
 List of algorithms to profile. More...
 
std::vector< std::string > m_intervals
 List of auditor intervals to profile. More...
 
unsigned int m_ignoreFirstNEvents
 Don't profile on the first N events. More...
 
bool m_dumpAfterEachInterval
 Dump profile after each interval. More...
 
unsigned int m_eventCounter
 Internal event counter for BeginEvent incident. More...
 
std::vector< boost::regex > m_algsRegEx
 Regular expressions for algorithm name matching. More...
 
std::vector< std::pair< NameEvt, NameEvt > > m_hooks
 Internal storage of intervals. More...
 
virtual void after (StandardEventType evt, const std::string &name, const StatusCode &sc)
 
virtual void after (StandardEventType evt, INamedInterface *alg, const StatusCode &sc)
 
virtual void after (CustomEventTypeRef evt, INamedInterface *alg, const StatusCode &sc)
 
virtual void after (CustomEventTypeRef evt, const std::string &name, const StatusCode &)
 
virtual void do_beforeExecute (const std::string &name)
 Start callgrind instrumentation. More...
 
virtual void do_afterExecute (const std::string &name)
 Stop callgrind instrumentation. More...
 
void do_before (const std::string &name, const std::string &hook)
 
void do_after (const std::string &name, const std::string &hook)
 
StatusCode decodeIntervals ()
 
bool algMatch (const std::string &name)
 

Detailed Description

Valgrind auditor.

Gaudi auditor to programmatically control valgrind. Currently only callgrind controls are implemented. Turns callgrind instrumentation on/off before/afterExecute.

Author
Frank Winklmeier
Id
ValgrindAuditor.h,v 1.4 2008-10-14 12:31:40 fwinkl Exp

Definition at line 35 of file ValgrindAuditor.h.

Member Typedef Documentation

◆ NameEvt

typedef std::pair<boost::regex,std::string> ValgrindAuditor::NameEvt

Typedef for algorithm/event pair, e.g. ("MyAlg","initialize")

Definition at line 85 of file ValgrindAuditor.h.

Constructor & Destructor Documentation

◆ ValgrindAuditor()

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

Definition at line 26 of file ValgrindAuditor.cxx.

28  : Auditor(name, pSvcLocator),
29  m_valSvc("ValgrindSvc", this->name()),
31 {
32  declareProperty("ProfiledAlgs", m_algs,
33  "List of algorithms to run in valgrind");
34 
35  declareProperty("ProfiledIntervals", m_intervals,
36  "Intervals to profile (e.g. 'MyAlg.initialize:MyAlg.finalize'" );
37 
38  declareProperty("IgnoreFirstNEvents", m_ignoreFirstNEvents = 0,
39  "Do not profile the first N events");
40 
41  declareProperty("DumpAfterEachInterval", m_dumpAfterEachInterval = true,
42  "Dump separate profile after each interval in ProfiledIntervals" );
43 }

◆ ~ValgrindAuditor()

ValgrindAuditor::~ValgrindAuditor ( )
virtual

Definition at line 46 of file ValgrindAuditor.cxx.

47 {
48 }

Member Function Documentation

◆ after() [1/4]

virtual void ValgrindAuditor::after ( CustomEventTypeRef  evt,
const std::string &  name,
const StatusCode &   
)
inlinevirtual

Definition at line 72 of file ValgrindAuditor.h.

73  { do_after(name, evt); }

◆ after() [2/4]

virtual void ValgrindAuditor::after ( CustomEventTypeRef  evt,
INamedInterface *  alg,
const StatusCode &  sc 
)
inlinevirtual

Definition at line 69 of file ValgrindAuditor.h.

70  { if (alg) after(evt, alg->name(), sc); }

◆ after() [3/4]

void ValgrindAuditor::after ( StandardEventType  evt,
const std::string &  name,
const StatusCode &  sc 
)
virtual

Definition at line 175 of file ValgrindAuditor.cxx.

176 {
178  else {
179  std::ostringstream os;
180  os << evt;
181  do_after(name, boost::to_lower_copy(os.str()));
182  }
183 }

◆ after() [4/4]

virtual void ValgrindAuditor::after ( StandardEventType  evt,
INamedInterface *  alg,
const StatusCode &  sc 
)
inlinevirtual

Definition at line 66 of file ValgrindAuditor.h.

67  { if (alg) after(evt, alg->name(), sc); }

◆ algMatch()

bool ValgrindAuditor::algMatch ( const std::string &  name)
private

Definition at line 322 of file ValgrindAuditor.cxx.

323 {
324  std::vector<boost::regex>::const_iterator iter;
325  for ( iter=m_algsRegEx.begin(); iter!=m_algsRegEx.end(); ++iter ) {
326  if ( boost::regex_match(name,*iter) ) return true;
327  }
328  return false;
329 }

◆ before() [1/4]

virtual void ValgrindAuditor::before ( CustomEventTypeRef  evt,
const std::string &  name 
)
inlinevirtual

Definition at line 58 of file ValgrindAuditor.h.

59  { do_before(name, evt); }

◆ before() [2/4]

virtual void ValgrindAuditor::before ( CustomEventTypeRef  evt,
INamedInterface *  alg 
)
inlinevirtual

Definition at line 55 of file ValgrindAuditor.h.

56  { if (alg) before(evt, alg->name()); }

◆ before() [3/4]

void ValgrindAuditor::before ( StandardEventType  evt,
const std::string &  name 
)
virtual

Definition at line 165 of file ValgrindAuditor.cxx.

166 {
168  else {
169  std::ostringstream os;
170  os << evt;
171  do_before(name, boost::to_lower_copy(os.str()));
172  }
173 }

◆ before() [4/4]

virtual void ValgrindAuditor::before ( StandardEventType  evt,
INamedInterface *  alg 
)
inlinevirtual

Definition at line 52 of file ValgrindAuditor.h.

53  { if (alg) before(evt, alg->name()); }

◆ decodeIntervals()

StatusCode ValgrindAuditor::decodeIntervals ( )
private

Definition at line 287 of file ValgrindAuditor.cxx.

288 {
289  m_hooks.clear();
290  m_hooks.reserve(m_intervals.size());
291 
292  std::vector<string>::const_iterator iter = m_intervals.begin();
293  for (; iter!=m_intervals.end(); ++iter) {
294  const string& spec = *iter;
295  string::size_type loc = spec.find(':');
296 
297  // If there is no delimiter interpret as [a,a]
298  string s1, s2;
299  if (loc==string::npos) s1 = s2 = spec;
300  else { // Extract interval
301  s1 = spec.substr(0,loc);
302  s2 = spec.substr(loc+1);
303  }
304 
305  NameEvt ne1, ne2;
306  if ( s1=="" || s2=="" ||
307  decodeNameEvt(s1,ne1).isFailure() || decodeNameEvt(s2,ne2).isFailure() ) {
308  msgStream() << MSG::ERROR << "Invalid profiling interval [" << spec << "]" << endmsg;
309  return StatusCode::FAILURE;
310  }
311 
312  std::pair<NameEvt,NameEvt> p(ne1,ne2);
313  m_hooks.push_back(p);
314  }
315 
316  return StatusCode::SUCCESS;
317 }

◆ do_after()

void ValgrindAuditor::do_after ( const std::string &  name,
const std::string &  hook 
)
private

Definition at line 240 of file ValgrindAuditor.cxx.

241 {
242  std::vector< std::pair<NameEvt,NameEvt> >::const_iterator iter;
243 
244  for (iter=m_hooks.begin(); iter!=m_hooks.end(); ++iter) {
245  if ( boost::regex_match(name, iter->second.first) &&
246  iter->second.second == hook ) {
247  m_valSvc->callgrindStopInstrumentation();
248  if ( msgLevel() <= MSG::DEBUG )
249  msgStream() << MSG::DEBUG << "Stopping callgrind after " << hook
250  << " of " << name << endmsg;
251 
252  if ( m_dumpAfterEachInterval ) {
253  m_valSvc->callgrindDumpStats(msgStream().stream());
254  msgStream() << MSG::INFO << "Creating callgrind profile #" << m_valSvc->profileCount()
255  << " after " << hook << " of " << name << endmsg;
256  }
257  }
258  }
259 }

◆ do_afterExecute()

void ValgrindAuditor::do_afterExecute ( const std::string &  name)
virtual

Stop callgrind instrumentation.

Definition at line 206 of file ValgrindAuditor.cxx.

207 {
208  if ( algMatch(name) ) {
210  m_valSvc->callgrindStopInstrumentation();
211  if ( msgLevel() <= MSG::DEBUG )
212  msgStream() << MSG::DEBUG << "Stopping callgrind after execute of " << name
213  << " [event #" << m_eventCounter << "]" << endmsg;
214  }
215  }
216 }

◆ do_before()

void ValgrindAuditor::do_before ( const std::string &  name,
const std::string &  hook 
)
private

Definition at line 222 of file ValgrindAuditor.cxx.

223 {
224  std::vector< std::pair<NameEvt,NameEvt> >::const_iterator iter;
225 
226  for (iter=m_hooks.begin(); iter!=m_hooks.end(); ++iter) {
227  if ( boost::regex_match(name, iter->first.first) &&
228  iter->first.second == hook ) {
229  m_valSvc->callgrindStartInstrumentation();
230  if ( msgLevel() <= MSG::DEBUG )
231  msgStream() << MSG::DEBUG << "Starting callgrind before " << hook
232  << " of " << name << endmsg;
233  }
234  }
235 }

◆ do_beforeExecute()

void ValgrindAuditor::do_beforeExecute ( const std::string &  name)
virtual

Start callgrind instrumentation.

Definition at line 189 of file ValgrindAuditor.cxx.

190 {
191  if ( algMatch(name) ) {
193  if ( msgLevel() <= MSG::DEBUG )
194  msgStream() << MSG::DEBUG << "Starting callgrind before execute of " << name
195  << " [event #" << m_eventCounter << "]" << endmsg;
196 
197  m_valSvc->callgrindStartInstrumentation();
198  }
199  }
200 }

◆ handle()

void ValgrindAuditor::handle ( const Incident &  incident)
virtual

Incident handler.

Definition at line 146 of file ValgrindAuditor.cxx.

147 {
148  // Internal event counter
149  if ( inc.type() == IncidentType::BeginEvent ) {
150  m_eventCounter++;
151  }
152 
153  // Check if the incident appears at beginning or end of interval
154  std::vector< std::pair<NameEvt,NameEvt> >::const_iterator h;
155  for (h=m_hooks.begin(); h!=m_hooks.end(); ++h) {
156  if ( h->first.second=="incident" ) do_before(inc.type(), "incident");
157  if ( h->second.second=="incident" ) do_after(inc.type(), "incident");
158  }
159 }

◆ initialize()

StatusCode ValgrindAuditor::initialize ( )
virtual

Definition at line 51 of file ValgrindAuditor.cxx.

52 {
53  if ( !m_valSvc.retrieve().isSuccess()) {
54  msgStream() << MSG::ERROR << "Could not retrieve the ValgrindSvc" << endmsg;
55  return StatusCode::FAILURE;
56  }
57 
58  const IProperty* valSvcProp = dynamic_cast<const IProperty*>(&(*m_valSvc));
59  if ( !valSvcProp ) {
60  msgStream() << MSG::ERROR
61  << "Could not retrieve IProperty interface to ValgrindSvc."
62  << endmsg;
63  return StatusCode::FAILURE;
64  }
65 
66  // We inherit the OutputLevel from ValgrindSvc
67  ATH_CHECK(setProperty(valSvcProp->getProperty("OutputLevel")));
68 
69  msgStream() << MSG::VERBOSE
70  << "Initializing " << name() << "..."
71  << endmsg;
72 
73  // Copy some properties from ValgrindSvc
74  std::string properties[] = {"ProfiledAlgs",
75  "ProfiledIntervals",
76  "IgnoreFirstNEvents",
77  "DumpAfterEachInterval"};
78 
79  for( std::string prop : properties ) {
80  if ( !setProperty(valSvcProp->getProperty(prop)) ) {
81  msgStream() << MSG::ERROR << "Cannot set " << prop << " property." << endmsg;
82  return StatusCode::FAILURE;
83  }
84  }
85 
86  // Reset internal event counter
87  m_eventCounter = 0;
88 
89  // Create regular expressions from algorithm names
90  for( const std::string& re : m_algs ) {
91  try {
92  m_algsRegEx.push_back( boost::regex(re) );
93  }
94  catch ( const boost::regex_error& ) {
95  msgStream() << MSG::ERROR << "Ignoring invalid regular expression: " << re << endmsg;
96  }
97  }
98 
99  if ( msgLevel() <= MSG::INFO ) {
100  std::ostringstream out;
101  out << "[ ";
102  std::copy( m_algs.begin(), m_algs.end(),
103  std::ostream_iterator<std::string>( out, " " ) );
104  out << "]";
105  msgStream() << MSG::INFO << "Profiled algorithms: " << out.str() << endmsg;
106 
107  out.str("");
108  out << "[ ";
109  std::copy( m_intervals.begin(), m_intervals.end(),
110  std::ostream_iterator<std::string>( out, " " ) );
111  out << "]";
112  msgStream() << MSG::INFO << "Profiled intervals: " << out.str() << endmsg;
113  }
114 
115  if (!m_intervals.empty()) {
116  if ( decodeIntervals().isFailure() ) {
117  msgStream() << MSG::ERROR << "Syntax error in ProfiledIntervals" << endmsg;
118  return StatusCode::FAILURE;
119  }
120  }
121 
122  // Register incidents
123  ServiceHandle<IIncidentSvc> incSvc("IncidentSvc", this->name());
124  if ( !incSvc.retrieve().isSuccess() ) {
125  msgStream() << MSG::ERROR << "Unable to get the IncidentSvc" << endmsg;
126  return StatusCode::FAILURE;
127  }
128  // Try to be the first incident handler to be called
129  const long prio = std::numeric_limits<long>::max();
130 
131  incSvc->addListener( this, IncidentType::BeginEvent, prio );
132 
133  for( const std::pair<NameEvt,NameEvt>& h : m_hooks ) {
134  // No regular expressions allowed for incidents. Take the original string.
135  if ( h.first.second=="incident" ) incSvc->addListener( this, h.first.first.str(), prio );
136  if ( h.second.second=="incident" ) incSvc->addListener( this, h.second.first.str(), prio );
137  }
138 
139  return StatusCode::SUCCESS;
140 }

Member Data Documentation

◆ m_algs

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

List of algorithms to profile.

Definition at line 93 of file ValgrindAuditor.h.

◆ m_algsRegEx

std::vector<boost::regex> ValgrindAuditor::m_algsRegEx
private

Regular expressions for algorithm name matching.

Definition at line 108 of file ValgrindAuditor.h.

◆ m_dumpAfterEachInterval

bool ValgrindAuditor::m_dumpAfterEachInterval
private

Dump profile after each interval.

Definition at line 102 of file ValgrindAuditor.h.

◆ m_eventCounter

unsigned int ValgrindAuditor::m_eventCounter
private

Internal event counter for BeginEvent incident.

Definition at line 105 of file ValgrindAuditor.h.

◆ m_hooks

std::vector< std::pair<NameEvt,NameEvt> > ValgrindAuditor::m_hooks
private

Internal storage of intervals.

Definition at line 111 of file ValgrindAuditor.h.

◆ m_ignoreFirstNEvents

unsigned int ValgrindAuditor::m_ignoreFirstNEvents
private

Don't profile on the first N events.

Definition at line 99 of file ValgrindAuditor.h.

◆ m_intervals

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

List of auditor intervals to profile.

Definition at line 96 of file ValgrindAuditor.h.

◆ m_valSvc

ServiceHandle<IValgrindSvc> ValgrindAuditor::m_valSvc
private

Handle to ValgrindSvc.

Definition at line 90 of file ValgrindAuditor.h.


The documentation for this class was generated from the following files:
ValgrindAuditor::decodeIntervals
StatusCode decodeIntervals()
Definition: ValgrindAuditor.cxx:287
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
SGout2dot.alg
alg
Definition: SGout2dot.py:243
python.TestDriveDummies.properties
dictionary properties
Definition: TestDriveDummies.py:14
ValgrindAuditor::after
virtual void after(StandardEventType evt, const std::string &name, const StatusCode &sc)
Definition: ValgrindAuditor.cxx:175
CaloCondBlobAlgs_fillNoiseFromASCII.spec
spec
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:47
ValgrindAuditor::m_algs
std::vector< std::string > m_algs
List of algorithms to profile.
Definition: ValgrindAuditor.h:93
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
ValgrindAuditor::m_algsRegEx
std::vector< boost::regex > m_algsRegEx
Regular expressions for algorithm name matching.
Definition: ValgrindAuditor.h:108
ValgrindAuditor::m_valSvc
ServiceHandle< IValgrindSvc > m_valSvc
Handle to ValgrindSvc.
Definition: ValgrindAuditor.h:90
ValgrindAuditor::m_ignoreFirstNEvents
unsigned int m_ignoreFirstNEvents
Don't profile on the first N events.
Definition: ValgrindAuditor.h:99
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
ValgrindAuditor::m_hooks
std::vector< std::pair< NameEvt, NameEvt > > m_hooks
Internal storage of intervals.
Definition: ValgrindAuditor.h:111
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ValgrindAuditor::m_dumpAfterEachInterval
bool m_dumpAfterEachInterval
Dump profile after each interval.
Definition: ValgrindAuditor.h:102
ValgrindAuditor::NameEvt
std::pair< boost::regex, std::string > NameEvt
Typedef for algorithm/event pair, e.g. ("MyAlg","initialize")
Definition: ValgrindAuditor.h:85
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
ValgrindAuditor::m_eventCounter
unsigned int m_eventCounter
Internal event counter for BeginEvent incident.
Definition: ValgrindAuditor.h:105
LArPulseShapeRunConfig.Execute
Execute
Definition: LArPulseShapeRunConfig.py:62
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
extractSporadic.h
list h
Definition: extractSporadic.py:97
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ValgrindAuditor::algMatch
bool algMatch(const std::string &name)
Definition: ValgrindAuditor.cxx:322
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
ValgrindAuditor::do_after
void do_after(const std::string &name, const std::string &hook)
Definition: ValgrindAuditor.cxx:240
ValgrindAuditor::do_before
void do_before(const std::string &name, const std::string &hook)
Definition: ValgrindAuditor.cxx:222
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ValgrindAuditor::before
virtual void before(StandardEventType evt, const std::string &name)
Definition: ValgrindAuditor.cxx:165
ValgrindAuditor::m_intervals
std::vector< std::string > m_intervals
List of auditor intervals to profile.
Definition: ValgrindAuditor.h:96
h
re
const boost::regex re(r_e)
DEBUG
#define DEBUG
Definition: page_access.h:11
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
ValgrindAuditor::do_beforeExecute
virtual void do_beforeExecute(const std::string &name)
Start callgrind instrumentation.
Definition: ValgrindAuditor.cxx:189
calibdata.copy
bool copy
Definition: calibdata.py:27
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
ValgrindAuditor::do_afterExecute
virtual void do_afterExecute(const std::string &name)
Stop callgrind instrumentation.
Definition: ValgrindAuditor.cxx:206
ServiceHandle< IIncidentSvc >