18#include "GaudiKernel/FileIncident.h"
19#include "GaudiKernel/ISvcLocator.h"
20#include "GaudiKernel/Incident.h"
21#include "GaudiKernel/System.h"
29static const std::string
levelNames[MSG::NUM_LEVELS] = {
"NIL",
"VERBOSE",
"DEBUG",
"INFO",
30 "WARNING",
"ERROR",
"FATAL",
"ALWAYS"};
34char* AthenaSummarySvc::s_block =
nullptr;
35bool AthenaSummarySvc::s_badalloc =
false;
36const char*
const II(
"\001");
46 PD(
const string&
a,
const string& b) {
add(
a,b); }
48 void add(
const string&
a,
const char* b) {
51 void add(
const string&
a,
const string& b) {
54 void add(
const string&
a,
const PD& p) {
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] ==
'{') {
86 }
else if (v[iv].compare(0,1,
II)==0) {
87 x.append( v[iv], 1,v[iv].
length());
89 x +=
"\"" + v[iv] +
"\"";
92 if (v.size() > 1) {
x +=
']'; }
106ostringstream PD::m_ofs(
"nothing");
111 std::transform(s.begin(), s.end(), s.begin(),
112 [](
unsigned char c){ return std::tolower(c); } );
120 : base_class( name, svc ),
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 );
164 if (ip->setProperty(
m_keywords).isFailure()) {
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 ];
190 return StatusCode(s_block!=
nullptr);
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() <<
"]");
302 fileName = fi->fileName();
304 fileName = inc.source();
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;
402 ofs <<
" FATAL: " << msgSvc()->messageCount( MSG::FATAL ) << endl;
403 ofs <<
" ERROR: " << msgSvc()->messageCount( MSG::ERROR ) << endl;
404 ofs <<
" WARNING: " << msgSvc()->messageCount( MSG::WARNING ) << endl;
405 ofs <<
" INFO: " << msgSvc()->messageCount( MSG::INFO ) << endl;
409 IntegerProperty thresh(
"loggingLevel",MSG::VERBOSE);
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;
424 for (
unsigned int l=thresh.value(); l < MSG::ALWAYS; l++) {
426 msgs =
p_logMsg->getMessages( MSG::Level(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;
434 for (
const auto&
msg :
p_logMsg->getKeyMessages()) {
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;
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 +=
","; }
501 files.add(
"write",f);
505 if (f.length() > 0) { f +=
","; }
508 files.add(
"write error",f);
510 p.add(
"files",
files);
517 p.add(
"events",events);
522 msg.add(
"FATAL",msgSvc()->messageCount( MSG::FATAL ));
523 msg.add(
"ERROR",msgSvc()->messageCount( MSG::ERROR ));
524 msg.add(
"WARNING",msgSvc()->messageCount( MSG::WARNING ));
525 msg.add(
"INFO",msgSvc()->messageCount( MSG::INFO ));
527 p.add(
"message count",
msg);
531 IntegerProperty thresh(
"loggingLevel",MSG::VERBOSE);
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;
544 for (
unsigned int l=thresh.value(); l < MSG::ALWAYS; l++) {
546 msgs =
p_logMsg->getMessages( MSG::Level(l) );
547 for (mitr=msgs.begin(); mitr != msgs.end(); ++mitr) {
548 slog.
add(mitr->first, mitr->second);
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);
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;
const char *const II("\001")
void tolower(std::string &s)
static const std::string levelNames[MSG::NUM_LEVELS]
std::list< std::string > m_outputFilesError
StringArrayProperty m_extraInc
virtual StatusCode createSummary() override
std::vector< std::pair< std::string, std::string > > m_extraInfo
StringArrayProperty m_keywords
void createASCII(std::ofstream &)
unsigned int m_eventsWritten
ServiceHandle< IIncidentSvc > p_incSvc
std::list< std::string > m_inputFilesRead
virtual void addListener(const std::string &incident_name) override
std::map< std::string, std::map< std::string, int > > m_extraIncidents
StringProperty m_summaryFile
std::list< std::string > m_outputFiles
void createDict(std::ofstream &)
AthenaSummarySvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode initialize() override
virtual StatusCode reinitialize() override
StringProperty m_summaryFormat
virtual StatusCode finalize() override
virtual void handle(const Incident &inc) override
virtual void addSummary(const std::string &dict_key, const std::string &data) override
ILoggedMessageSvc * p_logMsg
unsigned int m_eventsRead
unsigned int m_eventsSkipped
Extends IMessageSvc to get logged messages.
void add(const string &a, const T t)
void add(const string &a, const char *b)
PD(const string &a, const string &b)
static ostringstream m_ofs ATLAS_THREAD_SAFE
void add(const string &a, const string &b)
void add(const string &a, const PD &p)
map< string, vector< string > > m_dat
std::vector< std::string > files
file names and file pointers