9 #include "GaudiKernel/IIncidentSvc.h"
19 #include <boost/algorithm/string.hpp>
25 ISvcLocator* pSvcLocator)
26 : Auditor(
name, pSvcLocator),
27 m_valSvc(
"ValgrindSvc", this->
name()),
30 declareProperty(
"ProfiledAlgs",
m_algs,
31 "List of algorithms to run in valgrind");
34 "Intervals to profile (e.g. 'MyAlg.initialize:MyAlg.finalize'" );
37 "Do not profile the first N events");
40 "Dump separate profile after each interval in ProfiledIntervals" );
51 if ( !
m_valSvc.retrieve().isSuccess()) {
52 msgStream() << MSG::ERROR <<
"Could not retrieve the ValgrindSvc" <<
endmsg;
53 return StatusCode::FAILURE;
56 const IProperty* valSvcProp =
dynamic_cast<const IProperty*
>(&(*m_valSvc));
58 msgStream() << MSG::ERROR
59 <<
"Could not retrieve IProperty interface to ValgrindSvc."
61 return StatusCode::FAILURE;
65 ATH_CHECK(setProperty(valSvcProp->getProperty(
"OutputLevel")));
68 <<
"Initializing " <<
name() <<
"..."
75 "DumpAfterEachInterval"};
78 if ( !setProperty(valSvcProp->getProperty(prop)) ) {
79 msgStream() << MSG::ERROR <<
"Cannot set " << prop <<
" property." <<
endmsg;
80 return StatusCode::FAILURE;
88 for(
const std::string&
re :
m_algs ) {
92 catch (
const boost::regex_error& ) {
93 msgStream() << MSG::ERROR <<
"Ignoring invalid regular expression: " <<
re <<
endmsg;
98 std::ostringstream
out;
101 std::ostream_iterator<std::string>(
out,
" " ) );
108 std::ostream_iterator<std::string>(
out,
" " ) );
115 msgStream() << MSG::ERROR <<
"Syntax error in ProfiledIntervals" <<
endmsg;
116 return StatusCode::FAILURE;
122 if ( !incSvc.retrieve().isSuccess() ) {
123 msgStream() << MSG::ERROR <<
"Unable to get the IncidentSvc" <<
endmsg;
124 return StatusCode::FAILURE;
129 incSvc->addListener(
this, IncidentType::BeginEvent, prio );
131 for(
const std::pair<NameEvt,NameEvt>&
h :
m_hooks ) {
133 if (
h.first.second==
"incident" ) incSvc->addListener(
this,
h.first.first.str(), prio );
134 if (
h.second.second==
"incident" ) incSvc->addListener(
this,
h.second.first.str(), prio );
137 return StatusCode::SUCCESS;
147 if ( inc.type() == IncidentType::BeginEvent ) {
152 std::vector< std::pair<NameEvt,NameEvt> >::const_iterator
h;
154 if (
h->first.second==
"incident" )
do_before(inc.type(),
"incident");
155 if (
h->second.second==
"incident" )
do_after(inc.type(),
"incident");
186 msgStream() <<
MSG::DEBUG <<
"Starting callgrind before execute of " <<
name
189 m_valSvc->callgrindStartInstrumentation();
202 m_valSvc->callgrindStopInstrumentation();
204 msgStream() <<
MSG::DEBUG <<
"Stopping callgrind after execute of " <<
name
216 std::vector< std::pair<NameEvt,NameEvt> >::const_iterator
iter;
219 if ( boost::regex_match(
name,
iter->first.first) &&
220 iter->first.second == hook ) {
221 m_valSvc->callgrindStartInstrumentation();
223 msgStream() <<
MSG::DEBUG <<
"Starting callgrind before " << hook
234 std::vector< std::pair<NameEvt,NameEvt> >::const_iterator
iter;
237 if ( boost::regex_match(
name,
iter->second.first) &&
238 iter->second.second == hook ) {
239 m_valSvc->callgrindStopInstrumentation();
241 msgStream() <<
MSG::DEBUG <<
"Stopping callgrind after " << hook
246 msgStream() <<
MSG::INFO <<
"Creating callgrind profile #" <<
m_valSvc->profileCount()
247 <<
" after " << hook <<
" of " <<
name <<
endmsg;
263 string::size_type loc =
s.rfind(
'.');
264 if ( loc==string::npos )
return StatusCode::FAILURE;
269 catch (
const boost::regex_error& ) {
270 return StatusCode::FAILURE;
273 nameEvt.second =
s.substr(loc+1);
275 return StatusCode::SUCCESS;
287 string::size_type loc =
spec.find(
':');
291 if (loc==string::npos)
s1 =
s2 =
spec;
298 if (
s1==
"" ||
s2==
"" ||
299 decodeNameEvt(
s1,ne1).isFailure() || decodeNameEvt(
s2,ne2).isFailure() ) {
300 msgStream() << MSG::ERROR <<
"Invalid profiling interval [" <<
spec <<
"]" <<
endmsg;
301 return StatusCode::FAILURE;
304 std::pair<NameEvt,NameEvt>
p(ne1,ne2);
308 return StatusCode::SUCCESS;
316 std::vector<boost::regex>::const_iterator
iter;
318 if ( boost::regex_match(
name,*
iter) )
return true;