part3

part3

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
//  ---------------------------------------------------------------------
//
// ELstatistics.cc
//
// History:
//   7/8/98     mf      Created
//   7/2/99     jv      Added noTerminationSummary() function
//   6/7/00     web     Reflect consolidation of ELdestination/X;
//                      consolidate ELstatistics/X
//   6/14/00    web     Remove GNU relic code
//   6/15/00    web     using -> USING
//   10/4/00    mf      filterModule() and excludeModule()
//   3/13/00    mf      statisticsMap()
//    4/4/01    mf      Simplify filter/exclude logic by useing base class
//                      method thisShouldBeIgnored().  Eliminate
//                      moduleOfinterest and moduleToexclude.
//  11/01/01    web     Remove last vestige of GNU relic code; reordered
//                      initializers to correspond to order of member
//                      declarations
//   1/17/06    mf	summary() for use in MessageLogger
//   8/16/07    mf	Changes to implement grouping of modules in specified
//			categories
//   6/19/08    mf	summaryForJobReport()
//
//  ---------------------------------------------------------------------

#include "FWCore/MessageService/src/ELstatistics.h"

#include "FWCore/MessageLogger/interface/ErrorObj.h"

#include <iostream>
#include <iomanip>
#include <sstream>
#include <ios>
#include <cassert>

// Possible Traces:
// #define ELstatisticsCONSTRUCTOR_TRACE
// #define ELstatsLOG_TRACE

namespace {
  std::string summarizeContext(const std::string& c) {
    if (c.substr(0, 4) != "Run:")
      return c;
    std::istringstream is(c);
    std::string runWord;
    int run;
    is >> runWord >> run;
    if (!is)
      return c;
    if (runWord != "Run:")
      return c;
    std::string eventWord;
    int event;
    is >> eventWord >> event;
    if (!is)
      return c;
    if (eventWord != "Event:")
      return c;
    std::ostringstream os;
    os << run << "/" << event;
    return os.str();
  }
}  // namespace

using namespace edm::messagelogger;

namespace edm {
  namespace service {

    // ----------------------------------------------------------------------
    // Constructors
    // ----------------------------------------------------------------------

    ELstatistics::ELstatistics()
        : ELdestination(),
          tableLimit(-1),
          stats(),
          updatedStats(false),
          termStream(std::cerr),
          printAtTermination(true) {
#ifdef ELstatisticsCONSTRUCTOR_TRACE
      std::cerr << "Constructor for ELstatistics()\n";
#endif

    }  // ELstatistics()

    ELstatistics::ELstatistics(std::ostream& osp)
        : ELdestination(), tableLimit(-1), stats(), updatedStats(false), termStream(osp), printAtTermination(true) {
#ifdef ELstatisticsCONSTRUCTOR_TRACE
      std::cerr << "Constructor for ELstatistics(osp)\n";
#endif

    }  // ELstatistics()

    ELstatistics::ELstatistics(int spaceLimit)
        : ELdestination(),
          tableLimit(spaceLimit),
          stats(),
          updatedStats(false),
          termStream(std::cerr),
          printAtTermination(true) {
#ifdef ELstatisticsCONSTRUCTOR_TRACE
      std::cerr << "Constructor for ELstatistics(spaceLimit)\n";
#endif

    }  // ELstatistics()

    ELstatistics::ELstatistics(int spaceLimit, std::ostream& osp)
        : ELdestination(),
          tableLimit(spaceLimit),
          stats(),
          updatedStats(false),
          termStream(osp),
          printAtTermination(true) {
#ifdef ELstatisticsCONSTRUCTOR_TRACE
      std::cerr << "Constructor for ELstatistics(spaceLimit,osp)\n";
#endif

    }  // ELstatistics()

    ELstatistics::ELstatistics(const ELstatistics& orig)
        : ELdestination(),
          tableLimit(orig.tableLimit),
          stats(orig.stats),
          updatedStats(orig.updatedStats),
          termStream(orig.termStream),
          printAtTermination(orig.printAtTermination) {
#ifdef ELstatisticsCONSTRUCTOR_TRACE
      std::cerr << "Copy constructor for ELstatistics()\n";
#endif

      ignoreMostModules = orig.ignoreMostModules;
      respondToThese = orig.respondToThese;
      respondToMostModules = orig.respondToMostModules;
      ignoreThese = orig.ignoreThese;

    }  // ELstatistics()

    ELstatistics::~ELstatistics() {
#ifdef ELstatisticsCONSTRUCTOR_TRACE
      std::cerr << "Destructor for ELstatistics\n";
#endif

      if (updatedStats && printAtTermination)
        summary(termStream, "Termination Summary");

    }  // ~ELstatistics()

    // ----------------------------------------------------------------------
    // Methods invoked by the ELadministrator
    // ----------------------------------------------------------------------

    bool ELstatistics::log(const edm::ErrorObj& msg) {
#ifdef ELstatsLOG_TRACE
      std::cerr << "  =:=:=: Log to an ELstatistics\n";
#endif

      // See if this message is to be counted.

      if (msg.xid().severity < threshold)
        return false;
      if (thisShouldBeIgnored(msg.xid().module))
        return false;

      // Account for this message, making a new table entry if needed:
      //
      ELmap_stats::iterator s = stats.find(msg.xid());
      if (s == stats.end()) {
        if (tableLimit < 0 || static_cast<int>(stats.size()) < tableLimit) {
          stats[msg.xid()] = StatsCount();
          s = stats.find(msg.xid());
        }
      }
#ifdef ELstatsLOG_TRACE
      std::cerr << "    =:=:=: Message accounted for in stats \n";
#endif
      if (s != stats.end()) {
        (*s).second.add(summarizeContext(msg.context()), msg.reactedTo());

        updatedStats = true;
#ifdef ELstatsLOG_TRACE
        std::cerr << "    =:=:=: Updated stats \n";
#endif
      }

      // For the purposes of telling whether any log destination has reacted
      // to the message, the statistics destination does not count:
      //

#ifdef ELstatsLOG_TRACE
      std::cerr << "  =:=:=: log(msg) done (stats) \n";
#endif

      return false;

    }  // log()

    void ELstatistics::clearSummary() {
      limits.zero();
      ELmap_stats::iterator s;
      for (s = stats.begin(); s != stats.end(); ++s) {
        (*s).second.n = 0;
        (*s).second.context1 = (*s).second.context2 = (*s).second.contextLast = "";
      }

    }  // clearSummary()

    void ELstatistics::wipe() {
      limits.wipe();
      stats.erase(stats.begin(), stats.end());  //stats.clear();

    }  // wipe()

    void ELstatistics::zero() { limits.zero(); }  // zero()

    std::string ELstatistics::formSummary(ELmap_stats& stats) {
      // Major changes 8/16/07 mf, including making this
      // a static member function instead of a free function

      using std::ios; /* _base ? */
      using std::left;
      using std::right;
      using std::setw;

      std::ostringstream s;
      int n = 0;

      // -----  Summary part I:
      //
      bool ftnote(false);

      struct part3 {
        long n, t;
        part3() : n(0L), t(0L) { ; }
      } p3[ELseverityLevel::nLevels];

      std::set<std::string>::iterator gcEnd = groupedCategories.end();
      std::set<std::string> gCats = groupedCategories;  // TEMP FOR DEBUGGING SANITY
      for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
        // If this is a grouped category, wait till later to output its stats
        std::string cat = (*i).first.id;
        if (groupedCategories.find(cat) != gcEnd) {  // 8/16/07 mf
          continue;                                  // We will process these categories later
        }

        // -----  Emit new process and part I header, if needed:
        //
        if (n == 0) {
          s << "\n";
          s << " type     category        sev          module           "
               "     subroutine         count   total\n"
            << " ---- -------------------- -- ------------------------- "
               "---------------------   -----   -----\n";
        }
        // -----  Emit detailed message information:
        //
        s << right << std::setw(5) << ++n << ' ' << left << std::setw(20) << (*i).first.id.substr(0, 20) << ' ' << left
          << std::setw(2) << (*i).first.severity.getSymbol() << ' ' << left << std::setw(25)
          << (*i).first.module.substr(0, 25) << ' ' << left << std::setw(21) << (*i).first.subroutine.substr(0, 21)
          << right << std::setw(7) << (*i).second.n << left << std::setw(1) << ((*i).second.ignoredFlag ? '*' : ' ')
          << right << std::setw(8) << (*i).second.aggregateN << '\n';
        ftnote = ftnote || (*i).second.ignoredFlag;

        // -----  Obtain information for Part III, below:
        //
        ELextendedID xid = (*i).first;
        p3[xid.severity.getLevel()].n += (*i).second.n;
        p3[xid.severity.getLevel()].t += (*i).second.aggregateN;
      }  // for i

      // ----- Part Ia:  The grouped categories
      for (std::set<std::string>::iterator g = groupedCategories.begin(); g != gcEnd; ++g) {
        int groupTotal = 0;
        int groupAggregateN = 0;
        ELseverityLevel severityLevel;
        bool groupIgnored = true;
        for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
          if ((*i).first.id == *g) {
            if (groupTotal == 0)
              severityLevel = (*i).first.severity;
            groupIgnored &= (*i).second.ignoredFlag;
            groupAggregateN += (*i).second.aggregateN;
            ++groupTotal;
          }
        }  // for i
        if (groupTotal > 0) {
          // -----  Emit detailed message information:
          //
          s << right << std::setw(5) << ++n << ' ' << left << std::setw(20) << (*g).substr(0, 20) << ' ' << left
            << std::setw(2) << severityLevel.getSymbol() << ' ' << left << std::setw(16) << "  <Any Module>  " << ' '
            << left << std::setw(16) << "<Any Function>" << right << std::setw(7) << groupTotal << left << std::setw(1)
            << (groupIgnored ? '*' : ' ') << right << std::setw(8) << groupAggregateN << '\n';
          ftnote = ftnote || groupIgnored;

          // -----  Obtain information for Part III, below:
          //
          int lev = severityLevel.getLevel();
          p3[lev].n += groupTotal;
          p3[lev].t += groupAggregateN;
        }  // end if groupTotal>0
      }  // for g

      // -----  Provide footnote to part I, if needed:
      //
      if (ftnote)
        s << "\n* Some occurrences of this message"
             " were suppressed in all logs, due to limits.\n";

      // -----  Summary part II:
      //
      n = 0;
      for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
        std::string cat = (*i).first.id;
        if (groupedCategories.find(cat) != gcEnd) {  // 8/16/07 mf
          continue;                                  // We will process these categories later
        }
        if (n == 0) {
          s << '\n'
            << " type    category    Examples: "
               "run/evt        run/evt          run/evt\n"
            << " ---- -------------------- ----"
               "------------ ---------------- ----------------\n";
        }
        s << right << std::setw(5) << ++n << ' ' << left << std::setw(20) << (*i).first.id.c_str() << ' ' << left
          << std::setw(16) << (*i).second.context1.c_str() << ' ' << left << std::setw(16)
          << (*i).second.context2.c_str() << ' ' << (*i).second.contextLast.c_str() << '\n';
      }  // for

      // -----  Summary part III:
      //
      s << "\nSeverity    # Occurrences   Total Occurrences\n"
        << "--------    -------------   -----------------\n";
      for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
        if (p3[k].n != 0 || p3[k].t != 0) {
          s << left << std::setw(8) << ELseverityLevel(ELseverityLevel::ELsev_(k)).getName().c_str() << right
            << std::setw(17) << p3[k].n << right << std::setw(20) << p3[k].t << '\n';
        }
      }  // for

      return s.str();

    }  // formSummary()

    void ELstatistics::summary(std::ostream& os, std::string_view title) {
      os << title << std::endl << formSummary(stats) << std::flush;
      updatedStats = false;

    }  // summary()

    void ELstatistics::summary(unsigned long overfullWaitCount) {
      termStream << "\n=============================================\n\n"
                 << "MessageLogger Summary" << std::endl
                 << formSummary(stats) << std::endl
                 << "dropped waiting message count " << overfullWaitCount << std::endl
                 << std::flush;
      updatedStats = false;

    }  // summary()

    void ELstatistics::noTerminationSummary() { printAtTermination = false; }

    std::map<ELextendedID, StatsCount> ELstatistics::statisticsMap() const {
      return std::map<ELextendedID, StatsCount>(stats);
    }

    // 6/19/08 mf
    void ELstatistics::summaryForJobReport(std::map<std::string, double>& sm) {
      struct part3 {
        long n, t;
        part3() : n(0L), t(0L) { ; }
      } p3[ELseverityLevel::nLevels];

      std::set<std::string>::iterator gcEnd = groupedCategories.end();
      std::set<std::string> gCats = groupedCategories;  // TEMP FOR DEBUGGING SANITY

      // ----- Part I:  The ungrouped categories
      for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
        // If this is a grouped category, wait till later to output its stats
        std::string cat = (*i).first.id;
        if (groupedCategories.find(cat) != gcEnd) {
          continue;  // We will process these categories later
        }

        // -----  Emit detailed message information:
        //
        std::ostringstream s;
        s << "Category_";
        std::string sevSymbol = (*i).first.severity.getSymbol();
        if (sevSymbol[0] == '-')
          sevSymbol = sevSymbol.substr(1);
        s << sevSymbol << "_" << (*i).first.id;
        int n = (*i).second.aggregateN;
        std::string catstr = s.str();
        if (sm.find(catstr) != sm.end()) {
          sm[catstr] += n;
        } else {
          sm[catstr] = n;
        }
        // -----  Obtain information for Part III, below:
        //
        ELextendedID xid = (*i).first;
        p3[xid.severity.getLevel()].n += (*i).second.n;
        p3[xid.severity.getLevel()].t += (*i).second.aggregateN;
      }  // for i

      // ----- Part Ia:  The grouped categories
      for (std::set<std::string>::iterator g = groupedCategories.begin(); g != gcEnd; ++g) {
        int groupTotal = 0;
        int groupAggregateN = 0;
        ELseverityLevel severityLevel;
        for (ELmap_stats::const_iterator i = stats.begin(); i != stats.end(); ++i) {
          if ((*i).first.id == *g) {
            if (groupTotal == 0)
              severityLevel = (*i).first.severity;
            groupAggregateN += (*i).second.aggregateN;
            ++groupTotal;
          }
        }  // for i
        if (groupTotal > 0) {
          // -----  Emit detailed message information:
          //
          std::ostringstream s;
          s << "Category_";
          std::string sevSymbol = severityLevel.getSymbol();
          if (sevSymbol[0] == '-')
            sevSymbol = sevSymbol.substr(1);
          s << sevSymbol << "_" << *g;
          int n = groupAggregateN;
          std::string catstr = s.str();
          if (sm.find(catstr) != sm.end()) {
            sm[catstr] += n;
          } else {
            sm[catstr] = n;
          }

          // -----  Obtain information for Part III, below:
          //
          int lev = severityLevel.getLevel();
          p3[lev].n += groupTotal;
          p3[lev].t += groupAggregateN;
        }  // end if groupTotal>0
      }  // for g

      // part II (sample event numbers) does not exist for the job report.

      // -----  Summary part III:
      //
      for (int k = 0; k < ELseverityLevel::nLevels; ++k) {
        //if ( p3[k].t != 0 )  {
        if (true) {
          std::string sevName;
          sevName = ELseverityLevel(ELseverityLevel::ELsev_(k)).getName();
          if (sevName == "Severe")
            sevName = "System";
          if (sevName == "Success")
            sevName = "Debug";
          sevName = std::string("Log") + sevName;
          sevName = dualLogName(sevName);
          if (sevName != "UnusedSeverity") {
            sm[sevName] = p3[k].t;
          }
        }
      }  // for k

    }  // summaryForJobReport()

    std::string ELstatistics::dualLogName(std::string const& s) {
      if (s == "LogDebug")
        return "LogDebug_LogTrace";
      if (s == "LogInfo")
        return "LogInfo_LogVerbatim";
      if (s == "LogWarning")
        return "LogWarnng_LogPrint";
      if (s == "LogError")
        return "LogError_LogProblem";
      if (s == "LogSystem")
        return "LogSystem_LogAbsolute";
      return "UnusedSeverity";
    }

    std::set<std::string> ELstatistics::groupedCategories;  // 8/16/07 mf

    void ELstatistics::noteGroupedCategory(std::string const& cat) { groupedCategories.insert(cat); }

  }  // end of namespace service
}  // end of namespace edm