11 #include "GaudiKernel/IIncidentSvc.h"
21 #include <boost/algorithm/string.hpp>
27 ISvcLocator* pSvcLocator)
28 : Auditor(
name, pSvcLocator),
29 m_valSvc(
"ValgrindSvc", this->
name()),
32 declareProperty(
"ProfiledAlgs",
m_algs,
33 "List of algorithms to run in valgrind");
36 "Intervals to profile (e.g. 'MyAlg.initialize:MyAlg.finalize'" );
39 "Do not profile the first N events");
42 "Dump separate profile after each interval in ProfiledIntervals" );
53 if ( !
m_valSvc.retrieve().isSuccess()) {
54 msgStream() << MSG::ERROR <<
"Could not retrieve the ValgrindSvc" <<
endmsg;
55 return StatusCode::FAILURE;
58 const IProperty* valSvcProp =
dynamic_cast<const IProperty*
>(&(*m_valSvc));
60 msgStream() << MSG::ERROR
61 <<
"Could not retrieve IProperty interface to ValgrindSvc."
63 return StatusCode::FAILURE;
67 ATH_CHECK(setProperty(valSvcProp->getProperty(
"OutputLevel")));
70 <<
"Initializing " <<
name() <<
"..."
77 "DumpAfterEachInterval"};
80 if ( !setProperty(valSvcProp->getProperty(prop)) ) {
81 msgStream() << MSG::ERROR <<
"Cannot set " << prop <<
" property." <<
endmsg;
82 return StatusCode::FAILURE;
90 for(
const std::string&
re :
m_algs ) {
94 catch (
const boost::regex_error& ) {
95 msgStream() << MSG::ERROR <<
"Ignoring invalid regular expression: " <<
re <<
endmsg;
99 if ( msgLevel() <= MSG::INFO ) {
100 std::ostringstream
out;
103 std::ostream_iterator<std::string>(
out,
" " ) );
105 msgStream() << MSG::INFO <<
"Profiled algorithms: " <<
out.str() <<
endmsg;
110 std::ostream_iterator<std::string>(
out,
" " ) );
112 msgStream() << MSG::INFO <<
"Profiled intervals: " <<
out.str() <<
endmsg;
117 msgStream() << MSG::ERROR <<
"Syntax error in ProfiledIntervals" <<
endmsg;
118 return StatusCode::FAILURE;
124 if ( !incSvc.retrieve().isSuccess() ) {
125 msgStream() << MSG::ERROR <<
"Unable to get the IncidentSvc" <<
endmsg;
126 return StatusCode::FAILURE;
131 incSvc->addListener(
this, IncidentType::BeginEvent, prio );
133 for(
const std::pair<NameEvt,NameEvt>&
h :
m_hooks ) {
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 );
139 return StatusCode::SUCCESS;
149 if ( inc.type() == IncidentType::BeginEvent ) {
154 std::vector< std::pair<NameEvt,NameEvt> >::const_iterator
h;
156 if (
h->first.second==
"incident" )
do_before(inc.type(),
"incident");
157 if (
h->second.second==
"incident" )
do_after(inc.type(),
"incident");
169 std::ostringstream
os;
179 std::ostringstream
os;
194 msgStream() <<
MSG::DEBUG <<
"Starting callgrind before execute of " <<
name
197 m_valSvc->callgrindStartInstrumentation();
210 m_valSvc->callgrindStopInstrumentation();
212 msgStream() <<
MSG::DEBUG <<
"Stopping callgrind after execute of " <<
name
224 std::vector< std::pair<NameEvt,NameEvt> >::const_iterator iter;
227 if ( boost::regex_match(
name, iter->first.first) &&
228 iter->first.second == hook ) {
229 m_valSvc->callgrindStartInstrumentation();
231 msgStream() <<
MSG::DEBUG <<
"Starting callgrind before " << hook
242 std::vector< std::pair<NameEvt,NameEvt> >::const_iterator iter;
245 if ( boost::regex_match(
name, iter->second.first) &&
246 iter->second.second == hook ) {
247 m_valSvc->callgrindStopInstrumentation();
249 msgStream() <<
MSG::DEBUG <<
"Stopping callgrind after " << hook
254 msgStream() << MSG::INFO <<
"Creating callgrind profile #" <<
m_valSvc->profileCount()
255 <<
" after " << hook <<
" of " <<
name <<
endmsg;
271 string::size_type loc =
s.rfind(
'.');
272 if ( loc==string::npos )
return StatusCode::FAILURE;
277 catch (
const boost::regex_error& ) {
278 return StatusCode::FAILURE;
281 nameEvt.second =
s.substr(loc+1);
283 return StatusCode::SUCCESS;
292 std::vector<string>::const_iterator iter =
m_intervals.begin();
294 const string&
spec = *iter;
295 string::size_type loc =
spec.find(
':');
299 if (loc==string::npos)
s1 =
s2 =
spec;
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;
312 std::pair<NameEvt,NameEvt>
p(ne1,ne2);
316 return StatusCode::SUCCESS;
324 std::vector<boost::regex>::const_iterator iter;
326 if ( boost::regex_match(
name,*iter) )
return true;