CMS 3D CMS Logo

ExceptionGenerator.cc
Go to the documentation of this file.
1 #include "ExceptionGenerator.h"
2 
3 #include <iostream>
4 #include <typeinfo>
5 #include <map>
6 #include <sstream>
7 #include <sys/time.h>
8 
9 #include "TRandom3.h"
10 
13 
14 #include "boost/tokenizer.hpp"
15 
16 #include <cstdio>
17 #include <sys/types.h>
18 #include <csignal>
19 
20 using namespace std;
21 
22 namespace evf {
23 
25  : actionId_(pset.getUntrackedParameter<int>("defaultAction", -1)),
26  intqualifier_(pset.getUntrackedParameter<int>("defaultQualifier", 0)),
27  qualifier2_(pset.getUntrackedParameter<double>("secondQualifier", 1)),
28  actionRequired_(actionId_ != -1) {
29  // timing destribution from (https://twiki.cern.ch/twiki/bin/viewauth/CMS/HLTCpuTimingFAQ#2011_Most_Recent_Data)
30  // /castor/cern.ch/user/d/dsperka/HLT/triggerSkim_HLTPhysics_run178479_68_188.root
31  // Baseline result with CMSSW_4_2_9_HLT3_hltpatch3 and /online/collisions/2011/5e33/v2.1/HLT/V9 :
32  // vocms110:/store/timing_178479/outfile-178479-col1.root
33 
34  timingHisto_ = new TH1D("timingHisto_", "Total time for all modules per event", 100, 0, 1000);
35  timingHisto_->SetBinContent(1, 5016);
36  timingHisto_->SetBinContent(2, 4563);
37  timingHisto_->SetBinContent(3, 3298);
38  timingHisto_->SetBinContent(4, 1995);
39  timingHisto_->SetBinContent(5, 1708);
40  timingHisto_->SetBinContent(6, 1167);
41  timingHisto_->SetBinContent(7, 928);
42  timingHisto_->SetBinContent(8, 785);
43  timingHisto_->SetBinContent(9, 643);
44  timingHisto_->SetBinContent(10, 486);
45  timingHisto_->SetBinContent(11, 427);
46  timingHisto_->SetBinContent(12, 335);
47  timingHisto_->SetBinContent(13, 332);
48  timingHisto_->SetBinContent(14, 327);
49  timingHisto_->SetBinContent(15, 258);
50  timingHisto_->SetBinContent(16, 257);
51  timingHisto_->SetBinContent(17, 222);
52  timingHisto_->SetBinContent(18, 253);
53  timingHisto_->SetBinContent(19, 223);
54  timingHisto_->SetBinContent(20, 177);
55  timingHisto_->SetBinContent(21, 148);
56  timingHisto_->SetBinContent(22, 148);
57  timingHisto_->SetBinContent(23, 113);
58  timingHisto_->SetBinContent(24, 83);
59  timingHisto_->SetBinContent(25, 84);
60  timingHisto_->SetBinContent(26, 75);
61  timingHisto_->SetBinContent(27, 61);
62  timingHisto_->SetBinContent(28, 66);
63  timingHisto_->SetBinContent(29, 51);
64  timingHisto_->SetBinContent(30, 43);
65  timingHisto_->SetBinContent(31, 38);
66  timingHisto_->SetBinContent(32, 27);
67  timingHisto_->SetBinContent(33, 34);
68  timingHisto_->SetBinContent(34, 28);
69  timingHisto_->SetBinContent(35, 18);
70  timingHisto_->SetBinContent(36, 26);
71  timingHisto_->SetBinContent(37, 18);
72  timingHisto_->SetBinContent(38, 11);
73  timingHisto_->SetBinContent(39, 11);
74  timingHisto_->SetBinContent(40, 12);
75  timingHisto_->SetBinContent(41, 14);
76  timingHisto_->SetBinContent(42, 11);
77  timingHisto_->SetBinContent(43, 8);
78  timingHisto_->SetBinContent(44, 4);
79  timingHisto_->SetBinContent(45, 2);
80  timingHisto_->SetBinContent(46, 5);
81  timingHisto_->SetBinContent(47, 3);
82  timingHisto_->SetBinContent(48, 4);
83  timingHisto_->SetBinContent(49, 6);
84  timingHisto_->SetBinContent(50, 6);
85  timingHisto_->SetBinContent(51, 3);
86  timingHisto_->SetBinContent(52, 5);
87  timingHisto_->SetBinContent(53, 6);
88  timingHisto_->SetBinContent(54, 6);
89  timingHisto_->SetBinContent(55, 6);
90  timingHisto_->SetBinContent(56, 4);
91  timingHisto_->SetBinContent(57, 5);
92  timingHisto_->SetBinContent(58, 9);
93  timingHisto_->SetBinContent(59, 3);
94  timingHisto_->SetBinContent(60, 3);
95  timingHisto_->SetBinContent(61, 8);
96  timingHisto_->SetBinContent(62, 7);
97  timingHisto_->SetBinContent(63, 5);
98  timingHisto_->SetBinContent(64, 7);
99  timingHisto_->SetBinContent(65, 5);
100  timingHisto_->SetBinContent(66, 5);
101  timingHisto_->SetBinContent(67, 4);
102  timingHisto_->SetBinContent(68, 2);
103  timingHisto_->SetBinContent(69, 2);
104  timingHisto_->SetBinContent(70, 4);
105  timingHisto_->SetBinContent(71, 5);
106  timingHisto_->SetBinContent(72, 4);
107  timingHisto_->SetBinContent(73, 5);
108  timingHisto_->SetBinContent(74, 3);
109  timingHisto_->SetBinContent(75, 5);
110  timingHisto_->SetBinContent(76, 3);
111  timingHisto_->SetBinContent(77, 9);
112  timingHisto_->SetBinContent(78, 2);
113  timingHisto_->SetBinContent(79, 2);
114  timingHisto_->SetBinContent(80, 5);
115  timingHisto_->SetBinContent(81, 5);
116  timingHisto_->SetBinContent(82, 5);
117  timingHisto_->SetBinContent(83, 5);
118  timingHisto_->SetBinContent(84, 4);
119  timingHisto_->SetBinContent(85, 4);
120  timingHisto_->SetBinContent(86, 9);
121  timingHisto_->SetBinContent(87, 5);
122  timingHisto_->SetBinContent(88, 4);
123  timingHisto_->SetBinContent(89, 4);
124  timingHisto_->SetBinContent(90, 5);
125  timingHisto_->SetBinContent(91, 3);
126  timingHisto_->SetBinContent(92, 3);
127  timingHisto_->SetBinContent(93, 3);
128  timingHisto_->SetBinContent(94, 7);
129  timingHisto_->SetBinContent(95, 5);
130  timingHisto_->SetBinContent(96, 6);
131  timingHisto_->SetBinContent(97, 2);
132  timingHisto_->SetBinContent(98, 3);
133  timingHisto_->SetBinContent(99, 5);
134  timingHisto_->SetBinContent(101, 147);
135  timingHisto_->SetEntries(24934);
136  }
137 
138  void ExceptionGenerator::beginRun(const edm::Run &r, const edm::EventSetup &iSetup) {
139  gettimeofday(&tv_start_, nullptr);
140  }
141 
142  void __attribute__((optimize("O0"))) ExceptionGenerator::analyze(const edm::Event &e, const edm::EventSetup &c) {
143  float dummy = 0.;
144  unsigned int iterations = 0;
145  if (actionRequired_) {
146  int *pi = nullptr; //null-pointer used with actionId_ 8 and 12 to intentionally cause segfault
147  int ind = 0;
148  int step = 1;
149  switch (actionId_) {
150  case 0:
151  ::usleep(intqualifier_ * 1000);
152  break;
153  case 1:
154  ::sleep(0xFFFFFFF);
155  break;
156  case 2:
157  throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
158  break;
159  case 3:
160  exit(-1);
161  break;
162  case 4:
163  abort();
164  break;
165  case 5:
166  throw qualifier_;
167  break;
168  case 6:
169  while (true) {
170  ind += step;
171  if (ind > 1000000)
172  step = -1;
173  if (ind == 0)
174  step = 1;
175  }
176  break;
177  case 7:
178  edm::LogError("TestErrorMessage") << qualifier_;
179  break;
180  case 8:
181  *pi = 0; //intentionally caused segfault by assigning null pointer (this produces static-checker warning)
182  break;
183  case 9:
184  for (unsigned int j = 0; j < intqualifier_ * 1000 * 100; j++) {
185  dummy += sqrt(log(float(j + 1))) / float(j * j);
186  }
187  break;
188  case 10:
189  iterations = 100 * static_cast<unsigned int>(timingHisto_->GetRandom() * intqualifier_ * 17. + 0.5);
190  for (unsigned int j = 0; j < iterations; j++) {
191  dummy += sqrt(log(float(j + 1))) / float(j * j);
192  }
193  break;
194  case 11: {
195  iterations = static_cast<unsigned int>(timingHisto_->GetRandom() * intqualifier_ * 12. + 0.5);
196  TRandom3 random(iterations);
197  const size_t dataSize = 32 * 500; // 124kB
198  std::vector<double> data(dataSize);
199  random.RndmArray(dataSize, &data[0]);
200 
201  for (unsigned int j = 0; j < iterations; j++) {
202  const size_t index = static_cast<size_t>(random.Rndm() * dataSize + 0.5);
203  const double value = data[index];
204  dummy += sqrt(log(value + 1)) / (value * value);
205  if (random.Rndm() < 0.1)
206  data[index] = dummy;
207  }
208  } break;
209  case 12: {
210  timeval tv_now;
211  gettimeofday(&tv_now, nullptr);
212  if ((unsigned)(tv_now.tv_sec - tv_start_.tv_sec) > intqualifier_)
213  *pi = 0; //intentionally caused segfault by assigning null pointer (this produces static-checker warning)
214  } break;
215  case 13: {
216  void *vp = malloc(1024);
217 #pragma GCC diagnostic push
218 #pragma GCC diagnostic ignored "-Wstringop-overflow"
219  memset((char *)vp - 32 + intqualifier_, 0, 1024);
220 #pragma GCC diagnostic pop
221  free(vp);
222  } break;
223  case 14: {
224  float mean = 60.; // timingHisto_->GetMean();
225  float scale = intqualifier_ / mean;
226  float off = intqualifier_ * (1. - qualifier2_);
227  scale = scale * qualifier2_; // scale factor (1 default)
228  iterations = static_cast<unsigned int>(max(1., off + timingHisto_->GetRandom() * scale));
229  //std::cout << " off " << off << " scale " << scale << " " << iterations << std::endl;
230  ::usleep(iterations * 1000);
231  } break;
232  case 15: {
233  float mean = 60.; // timingHisto_->GetMean();
234  float scale = intqualifier_ / mean;
235  float off = intqualifier_ * (1. - qualifier2_);
236  scale = scale * qualifier2_; // scale factor (1 default)
237  iterations = static_cast<unsigned int>(max(1., off + timingHisto_->GetRandom() * scale));
238  iterations *= 100000;
239  for (unsigned int j = 0; j < iterations; j++) {
240  dummy += sqrt(log(float(j + 1))) / float(j * j);
241  }
242  } break;
243  case 16: {
244  throw cms::Exception("FastMonitoringService") << "Random exception!";
245  } break;
246 
247  default:
248  break;
249  }
250  }
251  }
252 
253 } // end namespace evf
Definition: fillJson.h:27
Log< level::Error, false > LogError
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
const Double_t pi
void beginRun(const edm::Run &r, const edm::EventSetup &iSetup) override
void free(void *ptr) noexcept
void __attribute__((optimize("O0"))) ExceptionGenerator
T sqrt(T t)
Definition: SSEVec.h:19
Definition: value.py:1
void * malloc(size_t size) noexcept
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
step
Definition: StallMonitor.cc:83
Definition: Run.h:45
def exit(msg="")