18 #include "GaudiKernel/FileIncident.h"
19 #include "GaudiKernel/ISvcLocator.h"
20 #include "GaudiKernel/Incident.h"
21 #include "GaudiKernel/System.h"
29 static const std::string levelNames[
MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
30 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
34 char* AthenaSummarySvc::s_block =
nullptr;
35 bool AthenaSummarySvc::s_badalloc =
false;
36 const char*
const II(
"\001");
48 void add(
const string&
a,
const char*
b) {
51 void add(
const string&
a,
const string&
b) {
52 m_dat[
a].push_back(
b );
55 m_dat[
a].push_back(
p.dump() );
58 void add(
const string&
a,
const T t) {
65 m_dat[
a].push_back( m_ofs.str() );
68 operator const string ()
const
75 map<string,vector<string> >::const_iterator itr;
77 for (itr=m_dat.begin(); itr != m_dat.end(); ++itr) {
78 if (
x.length() > 1) {
x+=
','; }
79 x +=
"\"" + itr->first +
"\":";
80 vector<string>
v = itr->second;
81 if (
v.size() > 1) {
x +=
'['; }
82 for (iv = 0; iv <
v.size(); ++iv) {
83 if (iv > 0) {
x +=
','; }
84 if (
v[iv][0] ==
'{') {
89 x +=
"\"" +
v[iv] +
"\"";
92 if (
v.size() > 1) {
x +=
']'; }
106 ostringstream PD::m_ofs(
"nothing");
112 [](
unsigned char c){ return std::tolower(c); } );
121 p_incSvc(
"IncidentSvc",
name),
133 p_incSvc->addListener(
this,
"BeginInputFile", pri,
true);
134 p_incSvc->addListener(
this,
"EndInputFile", pri,
true);
135 p_incSvc->addListener(
this,
"BeginOutputFile", pri,
true);
136 p_incSvc->addListener(
this,
"FailOutputFile", pri,
true);
137 p_incSvc->addListener(
this,
"WroteToOutputFile", pri,
true);
138 p_incSvc->addListener(
this,
"EndOutputFile", pri,
true);
140 p_incSvc->addListener(
this,
"AbortEvent", pri,
true);
142 p_incSvc->addListener(
this,
"BeginEvent", pri,
true);
143 p_incSvc->addListener(
this,
"EndEvent", pri,
true);
144 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
145 p_incSvc->addListener(
this,
"EndRun", pri,
true);
147 p_incSvc->addListener(
this,
"FirstInputFile", pri,
true );
149 vector<string>::const_iterator itr;
157 ATH_MSG_INFO(
"unable dcast IMessageSvc to ILoggedMessageSvc: "
158 "not scanning for keywords in logs, or printing logged messages");
162 IProperty *
ip =
dynamic_cast<IProperty*
>(
p_logMsg );
165 ATH_MSG_ERROR(
"could not set keywords property of LoggedMessageSvc");
168 <<
"\". CAVEAT EMPTOR - THIS IS VERY SLOW!!");
171 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
182 const long pageSize = sysconf( _SC_PAGESIZE );
183 if (pageSize < 1 || pageSize > 1024*1024*1024) {
185 return StatusCode::FAILURE;
187 s_block =
new char[ pageSize * 100 ];
198 delete[] s_block; s_block =
nullptr;
199 long pageSize = sysconf( _SC_PAGESIZE );
200 if (pageSize < 1 || pageSize > 1024*1024*1024) {
202 return StatusCode::FAILURE;
204 s_block =
new char[ pageSize * 100 ];
205 return s_block ? StatusCode::SUCCESS : StatusCode::FAILURE;
215 delete[] s_block; s_block =
nullptr;
216 std::set_new_handler(
m_new );
218 return StatusCode::SUCCESS;
229 p_incSvc->addListener(
this, inc, 100,
true);
257 throw std::bad_alloc();
260 delete[] s_block; s_block =
nullptr;
263 std::cerr <<
"AthenaSummarySvc FATAL out of memory: saving summary ..."
266 SmartIF<IAthenaSummarySvc> ipa(Gaudi::svcLocator()->service(
"AthenaSummarySvc"));
270 if ( System::backTrace(btrace,5,3) ) {
271 ipa->addSummary(
"badalloc backtrace",btrace);
275 ipa->createSummary().ignore();
277 std::cerr <<
"AthenaSummarySvc ERROR unable to get hold of myself and print summary"
285 throw std::bad_alloc();
294 ATH_MSG_DEBUG(
"handle incident: " << inc.type() <<
" " << inc.source());
298 const FileIncident *fi =
dynamic_cast<const FileIncident*
>( &inc );
301 ATH_MSG_INFO(
" -> file incident: " << fi->fileName() <<
" [GUID: " << fi->fileGuid() <<
"]");
307 if (inc.type() ==
"BeginInputFile" ) {
309 }
else if (inc.type() ==
"BeginOutputFile") {
311 }
else if (inc.type() ==
"FailOutputFile") {
313 }
else if (inc.type() ==
"BeginEvent") {
315 }
else if (inc.type() ==
"SkipEvent") {
317 }
else if (inc.type() ==
"WriteEvent") {
319 }
else if (inc.type() ==
"BeginRun") {
321 }
else if (inc.type() ==
"EndRun") {
324 map<std::string, map<string,int> >
::iterator itr
329 if (
it != itr->second.end()) {
350 return StatusCode::FAILURE;
365 return StatusCode::SUCCESS;
377 list<string>::const_iterator itr;
381 ofs <<
" " << *itr << endl;
384 ofs <<
"Files written: " <<
m_outputFiles.size() << std::endl;
386 ofs <<
" " << *itr << endl;
391 ofs <<
" " << *itr << endl;
398 ofs <<
"Runs: " <<
m_runs << endl;
401 ofs <<
"Message Count: " << endl;
403 ofs <<
" ERROR: " <<
msgSvc()->messageCount( MSG::ERROR ) << endl;
404 ofs <<
" WARNING: " <<
msgSvc()->messageCount( MSG::WARNING ) << endl;
410 IProperty *
ip =
dynamic_cast<IProperty*
>(
p_logMsg );
412 if (
ip->getProperty(&
thresh).isFailure()) {
413 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
416 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
421 ofs <<
"Message Log: " << endl;
422 vector<pair<string,string> > msgs;
423 vector<pair<string,string> >::const_iterator mitr;
425 ofs <<
" " << levelNames[
l];
427 ofs <<
" " << msgs.size() << endl;
428 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
429 ofs <<
" " << mitr->first <<
" : " << mitr->second << endl;
433 ofs <<
"Keyword tracked messages: " << endl;
435 ofs <<
" " << levelNames[
msg.level]
437 <<
" " <<
msg.message
444 ofs <<
"Extra Summary Info:" << endl;
445 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
447 ofs <<
" " << itr->first <<
" : " << itr->second << endl;
452 ofs <<
"Extra Incident Counts:" << endl;
453 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
455 ofs <<
" " << itr->first;
456 if (itr->second.begin() == itr->second.end()) {
457 ofs <<
" : 0" << endl;
459 for (map<string,int>::const_iterator
it=itr->second.begin();
460 it != itr->second.end(); ++
it) {
461 ofs <<
" :: " <<
it->first <<
":" <<
it->second;
469 ofs <<
"std::bad_alloc caught: out of memory condition detected"
473 ofs <<
"Exit Status: " <<
m_status << endl;
484 list<string>::const_iterator itr;
491 if (
f.length() > 0) {
f +=
","; }
498 if (
f.length() > 0) {
f +=
","; }
505 if (
f.length() > 0) {
f +=
","; }
508 files.add(
"write error",
f);
523 msg.add(
"ERROR",
msgSvc()->messageCount( MSG::ERROR ));
524 msg.add(
"WARNING",
msgSvc()->messageCount( MSG::WARNING ));
527 p.add(
"message count",
msg);
532 IProperty *
ip =
dynamic_cast<IProperty*
>(
p_logMsg );
534 if (
ip->getProperty(&
thresh).isFailure()) {
535 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
538 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
542 vector<pair<string,string> > msgs;
543 vector<pair<string,string> >::const_iterator mitr;
547 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
548 slog.
add(mitr->first, mitr->second);
550 mlog.add(levelNames[
l],slog);
553 p.add(
"messages",
mlog);
559 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
561 string dat = itr->second;
562 while( dat.find(
"\n") != string::npos) {
563 dat.erase(dat.find(
"\n"),1);
565 user.add(itr->first, dat);
567 p.add(
"user data",
user);
572 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
574 if (itr->second.begin() == itr->second.end()) {
575 inc.
add(itr->first,0);
578 for (map<string,int>::const_iterator
it=itr->second.begin();
579 it != itr->second.end(); ++
it) {
580 inc2.
add(
it->first,
it->second);
582 inc.
add(itr->first, inc2);
592 p.add(
"extra incidents",inc);
596 p.add(
"bad_alloc",s_badalloc);
598 ofd <<
p.dump() << endl;