18 #include "GaudiKernel/FileIncident.h"
19 #include "GaudiKernel/ISvcLocator.h"
20 #include "GaudiKernel/Incident.h"
21 #include "GaudiKernel/IIncidentListener.h"
22 #include "GaudiKernel/System.h"
32 static const std::string levelNames[
MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
33 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
37 char* AthenaSummarySvc::s_block =
nullptr;
38 bool AthenaSummarySvc::s_badalloc =
false;
39 const char*
const II(
"\001");
51 void add(
const string&
a,
const char*
b) {
54 void add(
const string&
a,
const string&
b) {
55 m_dat[
a].push_back(
b );
58 m_dat[
a].push_back(
p.dump() );
61 void add(
const string&
a,
const T t) {
68 m_dat[
a].push_back( m_ofs.str() );
71 operator const string ()
const
78 map<string,vector<string> >::const_iterator itr;
80 for (itr=m_dat.begin(); itr != m_dat.end(); ++itr) {
81 if (
x.length() > 1) {
x+=
','; }
82 x +=
"\"" + itr->first +
"\":";
83 vector<string>
v = itr->second;
84 if (
v.size() > 1) {
x +=
'['; }
85 for (iv = 0; iv <
v.size(); ++iv) {
86 if (iv > 0) {
x +=
','; }
87 if (
v[iv][0] ==
'{') {
92 x +=
"\"" +
v[iv] +
"\"";
95 if (
v.size() > 1) {
x +=
']'; }
109 ostringstream PD::m_ofs(
"nothing");
115 [](
unsigned char c){ return std::tolower(c); } );
124 p_incSvc(
"IncidentSvc",
name),
136 p_incSvc->addListener(
this,
"BeginInputFile", pri,
true);
137 p_incSvc->addListener(
this,
"EndInputFile", pri,
true);
138 p_incSvc->addListener(
this,
"BeginOutputFile", pri,
true);
139 p_incSvc->addListener(
this,
"FailOutputFile", pri,
true);
140 p_incSvc->addListener(
this,
"WroteToOutputFile", pri,
true);
141 p_incSvc->addListener(
this,
"EndOutputFile", pri,
true);
143 p_incSvc->addListener(
this,
"AbortEvent", pri,
true);
145 p_incSvc->addListener(
this,
"BeginEvent", pri,
true);
146 p_incSvc->addListener(
this,
"EndEvent", pri,
true);
147 p_incSvc->addListener(
this,
"BeginRun", pri,
true);
148 p_incSvc->addListener(
this,
"EndRun", pri,
true);
150 p_incSvc->addListener(
this,
"FirstInputFile", pri,
true );
152 vector<string>::const_iterator itr;
160 ATH_MSG_INFO(
"unable dcast IMessageSvc to ILoggedMessageSvc: "
161 "not scanning for keywords in logs, or printing logged messages");
165 IProperty *
ip =
dynamic_cast<IProperty*
>(
p_logMsg );
168 ATH_MSG_ERROR(
"could not set keywords property of LoggedMessageSvc");
171 <<
"\". CAVEAT EMPTOR - THIS IS VERY SLOW!!");
174 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
185 s_block =
new char[ sysconf( _SC_PAGESIZE ) * 100 ];
196 delete[] s_block; s_block =
nullptr;
197 s_block =
new char[ sysconf( _SC_PAGESIZE ) * 100 ];
198 return s_block ? StatusCode::SUCCESS : StatusCode::FAILURE;
208 delete[] s_block; s_block =
nullptr;
209 std::set_new_handler(
m_new );
211 return StatusCode::SUCCESS;
222 p_incSvc->addListener(
this, inc, 100,
true);
250 throw std::bad_alloc();
253 delete[] s_block; s_block =
nullptr;
256 std::cerr <<
"AthenaSummarySvc FATAL out of memory: saving summary ..."
259 SmartIF<IAthenaSummarySvc> ipa(Gaudi::svcLocator()->service(
"AthenaSummarySvc"));
263 if ( System::backTrace(btrace,5,3) ) {
264 ipa->addSummary(
"badalloc backtrace",btrace);
268 ipa->createSummary().ignore();
270 std::cerr <<
"AthenaSummarySvc ERROR unable to get hold of myself and print summary"
278 throw std::bad_alloc();
287 ATH_MSG_DEBUG(
"handle incident: " << inc.type() <<
" " << inc.source());
291 const FileIncident *
fi =
dynamic_cast<const FileIncident*
>( &inc );
294 ATH_MSG_INFO(
" -> file incident: " <<
fi->fileName() <<
" [GUID: " <<
fi->fileGuid() <<
"]");
300 if (inc.type() ==
"BeginInputFile" ) {
302 }
else if (inc.type() ==
"BeginOutputFile") {
304 }
else if (inc.type() ==
"FailOutputFile") {
306 }
else if (inc.type() ==
"BeginEvent") {
308 }
else if (inc.type() ==
"SkipEvent") {
310 }
else if (inc.type() ==
"WriteEvent") {
312 }
else if (inc.type() ==
"BeginRun") {
314 }
else if (inc.type() ==
"EndRun") {
317 map<std::string, map<string,int> >
::iterator itr
322 if (
it != itr->second.end()) {
343 return StatusCode::FAILURE;
358 return StatusCode::SUCCESS;
370 list<string>::const_iterator itr;
374 ofs <<
" " << *itr << endl;
377 ofs <<
"Files written: " <<
m_outputFiles.size() << std::endl;
379 ofs <<
" " << *itr << endl;
384 ofs <<
" " << *itr << endl;
391 ofs <<
"Runs: " <<
m_runs << endl;
394 ofs <<
"Message Count: " << endl;
396 ofs <<
" ERROR: " <<
msgSvc()->messageCount( MSG::ERROR ) << endl;
397 ofs <<
" WARNING: " <<
msgSvc()->messageCount( MSG::WARNING ) << endl;
398 ofs <<
" INFO: " <<
msgSvc()->messageCount( MSG::INFO ) << endl;
403 IProperty *
ip =
dynamic_cast<IProperty*
>(
p_logMsg );
405 if (
ip->getProperty(&
thresh).isFailure()) {
406 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
409 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
414 ofs <<
"Message Log: " << endl;
415 vector<pair<string,string> > msgs;
416 vector<pair<string,string> >::const_iterator mitr;
418 ofs <<
" " << levelNames[
l];
420 ofs <<
" " << msgs.size() << endl;
421 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
422 ofs <<
" " << mitr->first <<
" : " << mitr->second << endl;
426 ofs <<
"Keyword tracked messages: " << endl;
429 ofs <<
" " << levelNames[ilm->level] <<
" " << ilm->source <<
" " << ilm->message
436 ofs <<
"Extra Summary Info:" << endl;
437 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
439 ofs <<
" " << itr->first <<
" : " << itr->second << endl;
444 ofs <<
"Extra Incident Counts:" << endl;
445 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
447 ofs <<
" " << itr->first;
448 if (itr->second.begin() == itr->second.end()) {
449 ofs <<
" : 0" << endl;
451 for (map<string,int>::const_iterator
it=itr->second.begin();
452 it != itr->second.end(); ++
it) {
453 ofs <<
" :: " <<
it->first <<
":" <<
it->second;
461 ofs <<
"std::bad_alloc caught: out of memory condition detected"
465 ofs <<
"Exit Status: " <<
m_status << endl;
476 list<string>::const_iterator itr;
483 if (
f.length() > 0) {
f +=
","; }
490 if (
f.length() > 0) {
f +=
","; }
497 if (
f.length() > 0) {
f +=
","; }
500 files.add(
"write error",
f);
515 msg.add(
"ERROR",
msgSvc()->messageCount( MSG::ERROR ));
516 msg.add(
"WARNING",
msgSvc()->messageCount( MSG::WARNING ));
517 msg.add(
"INFO",
msgSvc()->messageCount( MSG::INFO ));
519 p.add(
"message count",
msg);
524 IProperty *
ip =
dynamic_cast<IProperty*
>(
p_logMsg );
526 if (
ip->getProperty(&
thresh).isFailure()) {
527 ATH_MSG_ERROR(
"could not get loggingLevel property of LoggedMessageSvc");
530 ATH_MSG_ERROR(
"could not dcast LoggedMessageSvc to IProperty");
534 vector<pair<string,string> > msgs;
535 vector<pair<string,string> >::const_iterator mitr;
539 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
540 slog.
add(mitr->first, mitr->second);
542 mlog.add(levelNames[
l],slog);
545 p.add(
"messages",
mlog);
551 vector<pair<string,string> >::const_iterator itr (
m_extraInfo.begin() );
553 string dat = itr->second;
554 while( dat.find(
"\n") != string::npos) {
555 dat.erase(dat.find(
"\n"),1);
557 user.add(itr->first, dat);
559 p.add(
"user data",
user);
564 map<string, map<string,int> >::const_iterator itr(
m_extraIncidents.begin());
566 if (itr->second.begin() == itr->second.end()) {
567 inc.
add(itr->first,0);
570 for (map<string,int>::const_iterator
it=itr->second.begin();
571 it != itr->second.end(); ++
it) {
572 inc2.
add(
it->first,
it->second);
574 inc.
add(itr->first, inc2);
584 p.add(
"extra incidents",inc);
588 p.add(
"bad_alloc",s_badalloc);
590 ofd <<
p.dump() << endl;