CMS 3D CMS Logo

ELstatistics.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // ELstatistics.cc
4 //
5 // History:
6 // 7/8/98 mf Created
7 // 7/2/99 jv Added noTerminationSummary() function
8 // 6/7/00 web Reflect consolidation of ELdestination/X;
9 // consolidate ELstatistics/X
10 // 6/14/00 web Remove GNU relic code
11 // 6/15/00 web using -> USING
12 // 10/4/00 mf filterModule() and excludeModule()
13 // 3/13/00 mf statisticsMap()
14 // 4/4/01 mf Simplify filter/exclude logic by useing base class
15 // method thisShouldBeIgnored(). Eliminate
16 // moduleOfinterest and moduleToexclude.
17 // 11/01/01 web Remove last vestige of GNU relic code; reordered
18 // initializers to correspond to order of member
19 // declarations
20 // 1/17/06 mf summary() for use in MessageLogger
21 // 8/16/07 mf Changes to implement grouping of modules in specified
22 // categories
23 // 6/19/08 mf summaryForJobReport()
24 //
25 // ---------------------------------------------------------------------
26 
28 
30 
31 #include <iostream>
32 #include <iomanip>
33 #include <sstream>
34 #include <ios>
35 #include <cassert>
36 
37 // Possible Traces:
38 // #define ELstatisticsCONSTRUCTOR_TRACE
39 // #define ELstatsLOG_TRACE
40 
41 namespace {
42  std::string summarizeContext(const std::string& c) {
43  if (c.substr(0, 4) != "Run:")
44  return c;
45  std::istringstream is(c);
46  std::string runWord;
47  int run;
48  is >> runWord >> run;
49  if (!is)
50  return c;
51  if (runWord != "Run:")
52  return c;
53  std::string eventWord;
54  int event;
55  is >> eventWord >> event;
56  if (!is)
57  return c;
58  if (eventWord != "Event:")
59  return c;
60  std::ostringstream os;
61  os << run << "/" << event;
62  return os.str();
63  }
64 } // namespace
65 
66 namespace edm {
67  namespace service {
68 
69  // ----------------------------------------------------------------------
70  // Constructors
71  // ----------------------------------------------------------------------
72 
74  : ELdestination(),
75  tableLimit(-1),
76  stats(),
77  updatedStats(false),
78  termStream(std::cerr),
79  printAtTermination(true) {
80 #ifdef ELstatisticsCONSTRUCTOR_TRACE
81  std::cerr << "Constructor for ELstatistics()\n";
82 #endif
83 
84  } // ELstatistics()
85 
86  ELstatistics::ELstatistics(std::ostream& osp)
87  : ELdestination(), tableLimit(-1), stats(), updatedStats(false), termStream(osp), printAtTermination(true) {
88 #ifdef ELstatisticsCONSTRUCTOR_TRACE
89  std::cerr << "Constructor for ELstatistics(osp)\n";
90 #endif
91 
92  } // ELstatistics()
93 
95  : ELdestination(),
96  tableLimit(spaceLimit),
97  stats(),
98  updatedStats(false),
99  termStream(std::cerr),
100  printAtTermination(true) {
101 #ifdef ELstatisticsCONSTRUCTOR_TRACE
102  std::cerr << "Constructor for ELstatistics(spaceLimit)\n";
103 #endif
104 
105  } // ELstatistics()
106 
107  ELstatistics::ELstatistics(int spaceLimit, std::ostream& osp)
108  : ELdestination(),
109  tableLimit(spaceLimit),
110  stats(),
111  updatedStats(false),
112  termStream(osp),
113  printAtTermination(true) {
114 #ifdef ELstatisticsCONSTRUCTOR_TRACE
115  std::cerr << "Constructor for ELstatistics(spaceLimit,osp)\n";
116 #endif
117 
118  } // ELstatistics()
119 
121  : ELdestination(),
122  tableLimit(orig.tableLimit),
123  stats(orig.stats),
124  updatedStats(orig.updatedStats),
125  termStream(orig.termStream),
126  printAtTermination(orig.printAtTermination) {
127 #ifdef ELstatisticsCONSTRUCTOR_TRACE
128  std::cerr << "Copy constructor for ELstatistics()\n";
129 #endif
130 
134  ignoreThese = orig.ignoreThese;
135 
136  } // ELstatistics()
137 
139 #ifdef ELstatisticsCONSTRUCTOR_TRACE
140  std::cerr << "Destructor for ELstatistics\n";
141 #endif
142 
144  summary(termStream, "Termination Summary");
145 
146  } // ~ELstatistics()
147 
148  // ----------------------------------------------------------------------
149  // Methods invoked by the ELadministrator
150  // ----------------------------------------------------------------------
151 
153 #ifdef ELstatsLOG_TRACE
154  std::cerr << " =:=:=: Log to an ELstatistics\n";
155 #endif
156 
157  // See if this message is to be counted.
158 
159  if (msg.xid().severity < threshold)
160  return false;
161  if (thisShouldBeIgnored(msg.xid().module))
162  return false;
163 
164  // Account for this message, making a new table entry if needed:
165  //
166  ELmap_stats::iterator s = stats.find(msg.xid());
167  if (s == stats.end()) {
168  if (tableLimit < 0 || static_cast<int>(stats.size()) < tableLimit) {
169  stats[msg.xid()] = StatsCount();
170  s = stats.find(msg.xid());
171  }
172  }
173 #ifdef ELstatsLOG_TRACE
174  std::cerr << " =:=:=: Message accounted for in stats \n";
175 #endif
176  if (s != stats.end()) {
177  (*s).second.add(summarizeContext(msg.context()), msg.reactedTo());
178 
179  updatedStats = true;
180 #ifdef ELstatsLOG_TRACE
181  std::cerr << " =:=:=: Updated stats \n";
182 #endif
183  }
184 
185  // For the purposes of telling whether any log destination has reacted
186  // to the message, the statistics destination does not count:
187  //
188 
189 #ifdef ELstatsLOG_TRACE
190  std::cerr << " =:=:=: log(msg) done (stats) \n";
191 #endif
192 
193  return false;
194 
195  } // log()
196 
198  limits.zero();
199  ELmap_stats::iterator s;
200  for (s = stats.begin(); s != stats.end(); ++s) {
201  (*s).second.n = 0;
202  (*s).second.context1 = (*s).second.context2 = (*s).second.contextLast = "";
203  }
204 
205  } // clearSummary()
206 
208  limits.wipe();
209  stats.erase(stats.begin(), stats.end()); //stats.clear();
210 
211  } // wipe()
212 
213  void ELstatistics::zero() { limits.zero(); } // zero()
214 
216  // Major changes 8/16/07 mf, including making this
217  // a static member function instead of a free function
218 
219  using std::ios; /* _base ? */
220  using std::left;
221  using std::right;
222  using std::setw;
223 
224  std::ostringstream s;
225  int n = 0;
226 
227  // ----- Summary part I:
228  //
229  bool ftnote(false);
230 
231  struct part3 {
232  long n, t;
233  part3() : n(0L), t(0L) { ; }
235 
236  std::set<std::string>::iterator gcEnd = groupedCategories.end();
237  std::set<std::string> gCats = groupedCategories; // TEMP FOR DEBUGGING SANITY
238  for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
239  // If this is a grouped category, wait till later to output its stats
240  std::string cat = (*i).first.id;
241  if (groupedCategories.find(cat) != gcEnd) { // 8/16/07 mf
242  continue; // We will process these categories later
243  }
244 
245  // ----- Emit new process and part I header, if needed:
246  //
247  if (n == 0) {
248  s << "\n";
249  s << " type category sev module "
250  "subroutine count total\n"
251  << " ---- -------------------- -- ---------------- "
252  "---------------- ----- -----\n";
253  }
254  // ----- Emit detailed message information:
255  //
256  s << right << std::setw(5) << ++n << ' ' << left << std::setw(20) << (*i).first.id.substr(0, 20) << ' ' << left
257  << std::setw(2) << (*i).first.severity.getSymbol() << ' ' << left << std::setw(16)
258  << (*i).first.module.substr(0, 16) << ' ' << left << std::setw(16) << (*i).first.subroutine.substr(0, 16)
259  << right << std::setw(7) << (*i).second.n << left << std::setw(1) << ((*i).second.ignoredFlag ? '*' : ' ')
260  << right << std::setw(8) << (*i).second.aggregateN << '\n';
261  ftnote = ftnote || (*i).second.ignoredFlag;
262 
263  // ----- Obtain information for Part III, below:
264  //
265  ELextendedID xid = (*i).first;
266  p3[xid.severity.getLevel()].n += (*i).second.n;
267  p3[xid.severity.getLevel()].t += (*i).second.aggregateN;
268  } // for i
269 
270  // ----- Part Ia: The grouped categories
271  for (std::set<std::string>::iterator g = groupedCategories.begin(); g != gcEnd; ++g) {
272  int groupTotal = 0;
273  int groupAggregateN = 0;
275  bool groupIgnored = true;
276  for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
277  if ((*i).first.id == *g) {
278  if (groupTotal == 0)
279  severityLevel = (*i).first.severity;
280  groupIgnored &= (*i).second.ignoredFlag;
281  groupAggregateN += (*i).second.aggregateN;
282  ++groupTotal;
283  }
284  } // for i
285  if (groupTotal > 0) {
286  // ----- Emit detailed message information:
287  //
288  s << right << std::setw(5) << ++n << ' ' << left << std::setw(20) << (*g).substr(0, 20) << ' ' << left
289  << std::setw(2) << severityLevel.getSymbol() << ' ' << left << std::setw(16) << " <Any Module> " << ' '
290  << left << std::setw(16) << "<Any Function>" << right << std::setw(7) << groupTotal << left << std::setw(1)
291  << (groupIgnored ? '*' : ' ') << right << std::setw(8) << groupAggregateN << '\n';
292  ftnote = ftnote || groupIgnored;
293 
294  // ----- Obtain information for Part III, below:
295  //
296  int lev = severityLevel.getLevel();
297  p3[lev].n += groupTotal;
298  p3[lev].t += groupAggregateN;
299  } // end if groupTotal>0
300  } // for g
301 
302  // ----- Provide footnote to part I, if needed:
303  //
304  if (ftnote)
305  s << "\n* Some occurrences of this message"
306  " were suppressed in all logs, due to limits.\n";
307 
308  // ----- Summary part II:
309  //
310  n = 0;
311  for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
312  std::string cat = (*i).first.id;
313  if (groupedCategories.find(cat) != gcEnd) { // 8/16/07 mf
314  continue; // We will process these categories later
315  }
316  if (n == 0) {
317  s << '\n'
318  << " type category Examples: "
319  "run/evt run/evt run/evt\n"
320  << " ---- -------------------- ----"
321  "------------ ---------------- ----------------\n";
322  }
323  s << right << std::setw(5) << ++n << ' ' << left << std::setw(20) << (*i).first.id.c_str() << ' ' << left
324  << std::setw(16) << (*i).second.context1.c_str() << ' ' << left << std::setw(16)
325  << (*i).second.context2.c_str() << ' ' << (*i).second.contextLast.c_str() << '\n';
326  } // for
327 
328  // ----- Summary part III:
329  //
330  s << "\nSeverity # Occurrences Total Occurrences\n"
331  << "-------- ------------- -----------------\n";
332  for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
333  if (p3[k].n != 0 || p3[k].t != 0) {
334  s << left << std::setw(8) << ELseverityLevel(ELseverityLevel::ELsev_(k)).getName().c_str() << right
335  << std::setw(17) << p3[k].n << right << std::setw(20) << p3[k].t << '\n';
336  }
337  } // for
338 
339  return s.str();
340 
341  } // formSummary()
342 
343  void ELstatistics::summary(std::ostream& os, std::string_view title) {
344  os << title << std::endl << formSummary(stats) << std::flush;
345  updatedStats = false;
346 
347  } // summary()
348 
349  void ELstatistics::summary(unsigned long overfullWaitCount) {
350  termStream << "\n=============================================\n\n"
351  << "MessageLogger Summary" << std::endl
352  << formSummary(stats) << std::endl
353  << "dropped waiting message count " << overfullWaitCount << std::endl
354  << std::flush;
355  updatedStats = false;
356 
357  } // summary()
358 
360 
361  std::map<ELextendedID, StatsCount> ELstatistics::statisticsMap() const {
362  return std::map<ELextendedID, StatsCount>(stats);
363  }
364 
365  // 6/19/08 mf
366  void ELstatistics::summaryForJobReport(std::map<std::string, double>& sm) {
367  struct part3 {
368  long n, t;
369  part3() : n(0L), t(0L) { ; }
371 
372  std::set<std::string>::iterator gcEnd = groupedCategories.end();
373  std::set<std::string> gCats = groupedCategories; // TEMP FOR DEBUGGING SANITY
374 
375  // ----- Part I: The ungrouped categories
376  for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
377  // If this is a grouped category, wait till later to output its stats
378  std::string cat = (*i).first.id;
379  if (groupedCategories.find(cat) != gcEnd) {
380  continue; // We will process these categories later
381  }
382 
383  // ----- Emit detailed message information:
384  //
385  std::ostringstream s;
386  s << "Category_";
387  std::string sevSymbol = (*i).first.severity.getSymbol();
388  if (sevSymbol[0] == '-')
389  sevSymbol = sevSymbol.substr(1);
390  s << sevSymbol << "_" << (*i).first.id;
391  int n = (*i).second.aggregateN;
392  std::string catstr = s.str();
393  if (sm.find(catstr) != sm.end()) {
394  sm[catstr] += n;
395  } else {
396  sm[catstr] = n;
397  }
398  // ----- Obtain information for Part III, below:
399  //
400  ELextendedID xid = (*i).first;
401  p3[xid.severity.getLevel()].n += (*i).second.n;
402  p3[xid.severity.getLevel()].t += (*i).second.aggregateN;
403  } // for i
404 
405  // ----- Part Ia: The grouped categories
406  for (std::set<std::string>::iterator g = groupedCategories.begin(); g != gcEnd; ++g) {
407  int groupTotal = 0;
408  int groupAggregateN = 0;
410  for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
411  if ((*i).first.id == *g) {
412  if (groupTotal == 0)
413  severityLevel = (*i).first.severity;
414  groupAggregateN += (*i).second.aggregateN;
415  ++groupTotal;
416  }
417  } // for i
418  if (groupTotal > 0) {
419  // ----- Emit detailed message information:
420  //
421  std::ostringstream s;
422  s << "Category_";
423  std::string sevSymbol = severityLevel.getSymbol();
424  if (sevSymbol[0] == '-')
425  sevSymbol = sevSymbol.substr(1);
426  s << sevSymbol << "_" << *g;
427  int n = groupAggregateN;
428  std::string catstr = s.str();
429  if (sm.find(catstr) != sm.end()) {
430  sm[catstr] += n;
431  } else {
432  sm[catstr] = n;
433  }
434 
435  // ----- Obtain information for Part III, below:
436  //
437  int lev = severityLevel.getLevel();
438  p3[lev].n += groupTotal;
439  p3[lev].t += groupAggregateN;
440  } // end if groupTotal>0
441  } // for g
442 
443  // part II (sample event numbers) does not exist for the job report.
444 
445  // ----- Summary part III:
446  //
447  for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
448  //if ( p3[k].t != 0 ) {
449  if (true) {
450  std::string sevName;
452  if (sevName == "Severe")
453  sevName = "System";
454  if (sevName == "Success")
455  sevName = "Debug";
456  sevName = std::string("Log") + sevName;
457  sevName = dualLogName(sevName);
458  if (sevName != "UnusedSeverity") {
459  sm[sevName] = p3[k].t;
460  }
461  }
462  } // for k
463 
464  } // summaryForJobReport()
465 
467  if (s == "LogDebug")
468  return "LogDebug_LogTrace";
469  if (s == "LogInfo")
470  return "LogInfo_LogVerbatim";
471  if (s == "LogWarning")
472  return "LogWarnng_LogPrint";
473  if (s == "LogError")
474  return "LogError_LogProblem";
475  if (s == "LogSystem")
476  return "LogSystem_LogAbsolute";
477  return "UnusedSeverity";
478  }
479 
480  std::set<std::string> ELstatistics::groupedCategories; // 8/16/07 mf
481 
483 
484  } // end of namespace service
485 } // end of namespace edm
edm::service::ELstatistics::dualLogName
std::string dualLogName(std::string const &s)
Definition: ELstatistics.cc:466
ELstatistics.h
service
Definition: service.py:1
dttmaxenums::L
Definition: DTTMax.h:29
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
edm::service::ELstatistics::noTerminationSummary
void noTerminationSummary()
Definition: ELstatistics.cc:359
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::service::ELstatistics::~ELstatistics
~ELstatistics() override
Definition: ELstatistics.cc:138
edm::service::ELdestination
Definition: ELdestination.h:52
edm::service::ELstatistics::tableLimit
int tableLimit
Definition: ELstatistics.h:89
edm::ELseverityLevel::ELsev_
ELsev_
Definition: ELseverityLevel.h:31
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::service::ELdestination::respondToThese
std::unordered_set< std::string > respondToThese
Definition: ELdestination.h:126
eostools.cat
def cat(path)
Definition: eostools.py:401
edm::ErrorObj
Definition: ErrorObj.h:43
edm::ELextendedID
Definition: ELextendedID.h:25
ErrorObj.h
edm::service::ELstatistics::statisticsMap
std::map< ELextendedID, StatsCount > statisticsMap() const
Definition: ELstatistics.cc:361
mps_check.msg
tuple msg
Definition: mps_check.py:285
edm::service::ELstatistics::stats
ELmap_stats stats
Definition: ELstatistics.h:90
edm::ELmap_stats
std::map< ELextendedID, StatsCount > ELmap_stats
Definition: ELmap.h:88
edm::service::ELstatistics
Definition: ELstatistics.h:49
edm::service::ELstatistics::clearSummary
void clearSummary()
Definition: ELstatistics.cc:197
edm::service::ELlimitsTable::wipe
void wipe()
Definition: ELlimitsTable.cc:165
edm::service::ELstatistics::summary
void summary(unsigned long overfullWaitCount)
Definition: ELstatistics.cc:349
edm::StatsCount
Definition: ELmap.h:68
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::service::ELstatistics::noteGroupedCategory
static void noteGroupedCategory(std::string const &cat)
Definition: ELstatistics.cc:482
edm::service::ELstatistics::termStream
std::ostream & termStream
Definition: ELstatistics.h:92
edm::service::ELstatistics::wipe
void wipe() override
Definition: ELstatistics.cc:207
edm::service::ELdestination::respondToMostModules
bool respondToMostModules
Definition: ELdestination.h:124
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::service::ELstatistics::printAtTermination
bool printAtTermination
Definition: ELstatistics.h:94
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::service::ELdestination::thisShouldBeIgnored
virtual bool thisShouldBeIgnored(std::string const &s) const
Definition: ELdestination.cc:211
funct::true
true
Definition: Factorize.h:173
edm::service::ELdestination::ignoreMostModules
bool ignoreMostModules
Definition: ELdestination.h:125
edm::service::ELstatistics::summaryForJobReport
void summaryForJobReport(std::map< std::string, double > &sm)
Definition: ELstatistics.cc:366
edmPickEvents.event
event
Definition: edmPickEvents.py:273
edm::ELseverityLevel::nLevels
Definition: ELseverityLevel.h:53
dqmMemoryStats.stats
stats
Definition: dqmMemoryStats.py:134
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::service::ELdestination::limits
ELlimitsTable limits
Definition: ELdestination.h:119
edm::service::ELdestination::threshold
ELseverityLevel threshold
Definition: ELdestination.h:117
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::ELseverityLevel
Definition: ELseverityLevel.h:26
interestingDetIdCollectionProducer_cfi.severityLevel
severityLevel
Definition: interestingDetIdCollectionProducer_cfi.py:10
edm::ELseverityLevel::getLevel
constexpr int getLevel() const noexcept
Definition: ELseverityLevel.h:70
edm::service::ELstatistics::ELstatistics
ELstatistics()
Definition: ELstatistics.cc:73
edm::service::ELlimitsTable::zero
void zero()
Definition: ELlimitsTable.cc:187
edm::service::ELstatistics::zero
void zero() override
Definition: ELstatistics.cc:213
edm::ELseverityLevel::getName
const std::string & getName() const
Definition: ELseverityLevel.cc:106
edm::service::ELstatistics::log
bool log(const edm::ErrorObj &msg) override
Definition: ELstatistics.cc:152
p3
double p3[4]
Definition: TauolaWrapper.h:91
edm::service::ELstatistics::formSummary
static std::string formSummary(ELmap_stats &stats)
Definition: ELstatistics.cc:215
edm::service::ELstatistics::groupedCategories
static std::set< std::string > groupedCategories
Definition: ELstatistics.h:96
edm::ELextendedID::severity
ELseverityLevel severity
Definition: ELextendedID.h:30
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
edm::service::ELstatistics::updatedStats
bool updatedStats
Definition: ELstatistics.h:91
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
edm::service::ELdestination::ignoreThese
std::unordered_set< std::string > ignoreThese
Definition: ELdestination.h:127