Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:26

0001 #include "ExceptionGenerator.h"
0002 
0003 #include <iostream>
0004 #include <typeinfo>
0005 #include <map>
0006 #include <sstream>
0007 #include <sys/time.h>
0008 
0009 #include "TRandom3.h"
0010 
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include "boost/tokenizer.hpp"
0015 
0016 #include <cstdio>
0017 #include <sys/types.h>
0018 #include <csignal>
0019 
0020 using namespace std;
0021 
0022 namespace evf {
0023 
0024   ExceptionGenerator::ExceptionGenerator(const edm::ParameterSet &pset)
0025       : actionId_(pset.getUntrackedParameter<int>("defaultAction", -1)),
0026         intqualifier_(pset.getUntrackedParameter<int>("defaultQualifier", 0)),
0027         qualifier2_(pset.getUntrackedParameter<double>("secondQualifier", 1)),
0028         actionRequired_(actionId_ != -1) {
0029     // timing destribution from (https://twiki.cern.ch/twiki/bin/viewauth/CMS/HLTCpuTimingFAQ#2011_Most_Recent_Data)
0030     // /castor/cern.ch/user/d/dsperka/HLT/triggerSkim_HLTPhysics_run178479_68_188.root
0031     // Baseline result with CMSSW_4_2_9_HLT3_hltpatch3 and /online/collisions/2011/5e33/v2.1/HLT/V9 :
0032     // vocms110:/store/timing_178479/outfile-178479-col1.root
0033 
0034     timingHisto_ = new TH1D("timingHisto_", "Total time for all modules per event", 100, 0, 1000);
0035     timingHisto_->SetBinContent(1, 5016);
0036     timingHisto_->SetBinContent(2, 4563);
0037     timingHisto_->SetBinContent(3, 3298);
0038     timingHisto_->SetBinContent(4, 1995);
0039     timingHisto_->SetBinContent(5, 1708);
0040     timingHisto_->SetBinContent(6, 1167);
0041     timingHisto_->SetBinContent(7, 928);
0042     timingHisto_->SetBinContent(8, 785);
0043     timingHisto_->SetBinContent(9, 643);
0044     timingHisto_->SetBinContent(10, 486);
0045     timingHisto_->SetBinContent(11, 427);
0046     timingHisto_->SetBinContent(12, 335);
0047     timingHisto_->SetBinContent(13, 332);
0048     timingHisto_->SetBinContent(14, 327);
0049     timingHisto_->SetBinContent(15, 258);
0050     timingHisto_->SetBinContent(16, 257);
0051     timingHisto_->SetBinContent(17, 222);
0052     timingHisto_->SetBinContent(18, 253);
0053     timingHisto_->SetBinContent(19, 223);
0054     timingHisto_->SetBinContent(20, 177);
0055     timingHisto_->SetBinContent(21, 148);
0056     timingHisto_->SetBinContent(22, 148);
0057     timingHisto_->SetBinContent(23, 113);
0058     timingHisto_->SetBinContent(24, 83);
0059     timingHisto_->SetBinContent(25, 84);
0060     timingHisto_->SetBinContent(26, 75);
0061     timingHisto_->SetBinContent(27, 61);
0062     timingHisto_->SetBinContent(28, 66);
0063     timingHisto_->SetBinContent(29, 51);
0064     timingHisto_->SetBinContent(30, 43);
0065     timingHisto_->SetBinContent(31, 38);
0066     timingHisto_->SetBinContent(32, 27);
0067     timingHisto_->SetBinContent(33, 34);
0068     timingHisto_->SetBinContent(34, 28);
0069     timingHisto_->SetBinContent(35, 18);
0070     timingHisto_->SetBinContent(36, 26);
0071     timingHisto_->SetBinContent(37, 18);
0072     timingHisto_->SetBinContent(38, 11);
0073     timingHisto_->SetBinContent(39, 11);
0074     timingHisto_->SetBinContent(40, 12);
0075     timingHisto_->SetBinContent(41, 14);
0076     timingHisto_->SetBinContent(42, 11);
0077     timingHisto_->SetBinContent(43, 8);
0078     timingHisto_->SetBinContent(44, 4);
0079     timingHisto_->SetBinContent(45, 2);
0080     timingHisto_->SetBinContent(46, 5);
0081     timingHisto_->SetBinContent(47, 3);
0082     timingHisto_->SetBinContent(48, 4);
0083     timingHisto_->SetBinContent(49, 6);
0084     timingHisto_->SetBinContent(50, 6);
0085     timingHisto_->SetBinContent(51, 3);
0086     timingHisto_->SetBinContent(52, 5);
0087     timingHisto_->SetBinContent(53, 6);
0088     timingHisto_->SetBinContent(54, 6);
0089     timingHisto_->SetBinContent(55, 6);
0090     timingHisto_->SetBinContent(56, 4);
0091     timingHisto_->SetBinContent(57, 5);
0092     timingHisto_->SetBinContent(58, 9);
0093     timingHisto_->SetBinContent(59, 3);
0094     timingHisto_->SetBinContent(60, 3);
0095     timingHisto_->SetBinContent(61, 8);
0096     timingHisto_->SetBinContent(62, 7);
0097     timingHisto_->SetBinContent(63, 5);
0098     timingHisto_->SetBinContent(64, 7);
0099     timingHisto_->SetBinContent(65, 5);
0100     timingHisto_->SetBinContent(66, 5);
0101     timingHisto_->SetBinContent(67, 4);
0102     timingHisto_->SetBinContent(68, 2);
0103     timingHisto_->SetBinContent(69, 2);
0104     timingHisto_->SetBinContent(70, 4);
0105     timingHisto_->SetBinContent(71, 5);
0106     timingHisto_->SetBinContent(72, 4);
0107     timingHisto_->SetBinContent(73, 5);
0108     timingHisto_->SetBinContent(74, 3);
0109     timingHisto_->SetBinContent(75, 5);
0110     timingHisto_->SetBinContent(76, 3);
0111     timingHisto_->SetBinContent(77, 9);
0112     timingHisto_->SetBinContent(78, 2);
0113     timingHisto_->SetBinContent(79, 2);
0114     timingHisto_->SetBinContent(80, 5);
0115     timingHisto_->SetBinContent(81, 5);
0116     timingHisto_->SetBinContent(82, 5);
0117     timingHisto_->SetBinContent(83, 5);
0118     timingHisto_->SetBinContent(84, 4);
0119     timingHisto_->SetBinContent(85, 4);
0120     timingHisto_->SetBinContent(86, 9);
0121     timingHisto_->SetBinContent(87, 5);
0122     timingHisto_->SetBinContent(88, 4);
0123     timingHisto_->SetBinContent(89, 4);
0124     timingHisto_->SetBinContent(90, 5);
0125     timingHisto_->SetBinContent(91, 3);
0126     timingHisto_->SetBinContent(92, 3);
0127     timingHisto_->SetBinContent(93, 3);
0128     timingHisto_->SetBinContent(94, 7);
0129     timingHisto_->SetBinContent(95, 5);
0130     timingHisto_->SetBinContent(96, 6);
0131     timingHisto_->SetBinContent(97, 2);
0132     timingHisto_->SetBinContent(98, 3);
0133     timingHisto_->SetBinContent(99, 5);
0134     timingHisto_->SetBinContent(101, 147);
0135     timingHisto_->SetEntries(24934);
0136   }
0137 
0138   void ExceptionGenerator::beginRun(const edm::Run &r, const edm::EventSetup &iSetup) {
0139     gettimeofday(&tv_start_, nullptr);
0140   }
0141 
0142   void __attribute__((optimize("O0"))) ExceptionGenerator::analyze(const edm::Event &e, const edm::EventSetup &c) {
0143     float dummy = 0.;
0144     unsigned int iterations = 0;
0145     if (actionRequired_) {
0146       int *pi = nullptr;  //null-pointer used with actionId_ 8 and 12 to intentionally cause segfault
0147       int ind = 0;
0148       int step = 1;
0149       switch (actionId_) {
0150         case 0:
0151           ::usleep(intqualifier_ * 1000);
0152           break;
0153         case 1:
0154           ::sleep(0xFFFFFFF);
0155           break;
0156         case 2:
0157           throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
0158           break;
0159         case 3:
0160           exit(-1);
0161           break;
0162         case 4:
0163           abort();
0164           break;
0165         case 5:
0166           throw qualifier_;
0167           break;
0168         case 6:
0169           while (true) {
0170             ind += step;
0171             if (ind > 1000000)
0172               step = -1;
0173             if (ind == 0)
0174               step = 1;
0175           }
0176           break;
0177         case 7:
0178           edm::LogError("TestErrorMessage") << qualifier_;
0179           break;
0180         case 8:
0181           *pi = 0;  //intentionally caused segfault by assigning null pointer (this produces static-checker warning)
0182           break;
0183         case 9:
0184           for (unsigned int j = 0; j < intqualifier_ * 1000 * 100; j++) {
0185             dummy += sqrt(log(float(j + 1))) / float(j * j);
0186           }
0187           break;
0188         case 10:
0189           iterations = 100 * static_cast<unsigned int>(timingHisto_->GetRandom() * intqualifier_ * 17. + 0.5);
0190           for (unsigned int j = 0; j < iterations; j++) {
0191             dummy += sqrt(log(float(j + 1))) / float(j * j);
0192           }
0193           break;
0194         case 11: {
0195           iterations = static_cast<unsigned int>(timingHisto_->GetRandom() * intqualifier_ * 12. + 0.5);
0196           TRandom3 random(iterations);
0197           const size_t dataSize = 32 * 500;  // 124kB
0198           std::vector<double> data(dataSize);
0199           random.RndmArray(dataSize, &data[0]);
0200 
0201           for (unsigned int j = 0; j < iterations; j++) {
0202             const size_t index = static_cast<size_t>(random.Rndm() * dataSize + 0.5);
0203             const double value = data[index];
0204             dummy += sqrt(log(value + 1)) / (value * value);
0205             if (random.Rndm() < 0.1)
0206               data[index] = dummy;
0207           }
0208         } break;
0209         case 12: {
0210           timeval tv_now;
0211           gettimeofday(&tv_now, nullptr);
0212           if ((unsigned)(tv_now.tv_sec - tv_start_.tv_sec) > intqualifier_)
0213             *pi = 0;  //intentionally caused segfault by assigning null pointer (this produces static-checker warning)
0214         } break;
0215         case 13: {
0216           void *vp = malloc(1024);
0217           memset((char *)vp - 32, 0, 1024);
0218           free(vp);
0219         } break;
0220         case 14: {
0221           float mean = 60.;  // timingHisto_->GetMean();
0222           float scale = intqualifier_ / mean;
0223           float off = intqualifier_ * (1. - qualifier2_);
0224           scale = scale * qualifier2_;  // scale factor (1 default)
0225           iterations = static_cast<unsigned int>(max(1., off + timingHisto_->GetRandom() * scale));
0226           //std::cout << " off " << off << " scale " << scale << " " << iterations << std::endl;
0227           ::usleep(iterations * 1000);
0228         } break;
0229         case 15: {
0230           float mean = 60.;  // timingHisto_->GetMean();
0231           float scale = intqualifier_ / mean;
0232           float off = intqualifier_ * (1. - qualifier2_);
0233           scale = scale * qualifier2_;  // scale factor (1 default)
0234           iterations = static_cast<unsigned int>(max(1., off + timingHisto_->GetRandom() * scale));
0235           iterations *= 100000;
0236           for (unsigned int j = 0; j < iterations; j++) {
0237             dummy += sqrt(log(float(j + 1))) / float(j * j);
0238           }
0239         } break;
0240         default:
0241           break;
0242       }
0243     }
0244   }
0245 
0246   void ExceptionGenerator::endLuminosityBlock(edm::LuminosityBlock const &lb, edm::EventSetup const &es) {}
0247 
0248 }  // end namespace evf