CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
8 #include "TRandom3.h"
9 
10 #include "xgi/Method.h"
11 #include "xgi/Utils.h"
12 
13 #include "cgicc/Cgicc.h"
14 #include "cgicc/FormEntry.h"
15 #include "cgicc/HTMLClasses.h"
16 
19 
20 #include "boost/tokenizer.hpp"
21 
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <signal.h>
25 
26 using namespace std;
27 
28 namespace evf{
29 
30  const std::string ExceptionGenerator::menu[menu_items] =
31  {"Sleep x ms", "SleepForever", "Cms Exception", "Exit with error", "Abort", "Unknown Exception", "Endless loop", "Generate Error Message", "Segfault",
32  "Burn CPU","HLT timing distribution","HLT timing with memory access","Timed segfault","Invalid free()"};
33 
35  ModuleWeb("ExceptionGenerator"),
36  actionId_(pset.getUntrackedParameter<int>("defaultAction",-1)),
37  intqualifier_(pset.getUntrackedParameter<unsigned int>("defaultQualifier",0)),
38  actionRequired_(actionId_!=-1)
39  {
40 
41  }
43  {
44  // timing destribution from (https://twiki.cern.ch/twiki/bin/viewauth/CMS/HLTCpuTimingFAQ#2011_Most_Recent_Data)
45  // /castor/cern.ch/user/d/dsperka/HLT/triggerSkim_HLTPhysics_run178479_68_188.root
46  // Baseline result with CMSSW_4_2_9_HLT3_hltpatch3 and /online/collisions/2011/5e33/v2.1/HLT/V9 :
47  // vocms110:/store/timing_178479/outfile-178479-col1.root
48 
49  timingHisto_ = new TH1D("timingHisto_","Total time for all modules per event",100,0,1000);
50  timingHisto_->SetBinContent(1,5016);
51  timingHisto_->SetBinContent(2,4563);
52  timingHisto_->SetBinContent(3,3298);
53  timingHisto_->SetBinContent(4,1995);
54  timingHisto_->SetBinContent(5,1708);
55  timingHisto_->SetBinContent(6,1167);
56  timingHisto_->SetBinContent(7,928);
57  timingHisto_->SetBinContent(8,785);
58  timingHisto_->SetBinContent(9,643);
59  timingHisto_->SetBinContent(10,486);
60  timingHisto_->SetBinContent(11,427);
61  timingHisto_->SetBinContent(12,335);
62  timingHisto_->SetBinContent(13,332);
63  timingHisto_->SetBinContent(14,327);
64  timingHisto_->SetBinContent(15,258);
65  timingHisto_->SetBinContent(16,257);
66  timingHisto_->SetBinContent(17,222);
67  timingHisto_->SetBinContent(18,253);
68  timingHisto_->SetBinContent(19,223);
69  timingHisto_->SetBinContent(20,177);
70  timingHisto_->SetBinContent(21,148);
71  timingHisto_->SetBinContent(22,148);
72  timingHisto_->SetBinContent(23,113);
73  timingHisto_->SetBinContent(24,83);
74  timingHisto_->SetBinContent(25,84);
75  timingHisto_->SetBinContent(26,75);
76  timingHisto_->SetBinContent(27,61);
77  timingHisto_->SetBinContent(28,66);
78  timingHisto_->SetBinContent(29,51);
79  timingHisto_->SetBinContent(30,43);
80  timingHisto_->SetBinContent(31,38);
81  timingHisto_->SetBinContent(32,27);
82  timingHisto_->SetBinContent(33,34);
83  timingHisto_->SetBinContent(34,28);
84  timingHisto_->SetBinContent(35,18);
85  timingHisto_->SetBinContent(36,26);
86  timingHisto_->SetBinContent(37,18);
87  timingHisto_->SetBinContent(38,11);
88  timingHisto_->SetBinContent(39,11);
89  timingHisto_->SetBinContent(40,12);
90  timingHisto_->SetBinContent(41,14);
91  timingHisto_->SetBinContent(42,11);
92  timingHisto_->SetBinContent(43,8);
93  timingHisto_->SetBinContent(44,4);
94  timingHisto_->SetBinContent(45,2);
95  timingHisto_->SetBinContent(46,5);
96  timingHisto_->SetBinContent(47,3);
97  timingHisto_->SetBinContent(48,4);
98  timingHisto_->SetBinContent(49,6);
99  timingHisto_->SetBinContent(50,6);
100  timingHisto_->SetBinContent(51,3);
101  timingHisto_->SetBinContent(52,5);
102  timingHisto_->SetBinContent(53,6);
103  timingHisto_->SetBinContent(54,6);
104  timingHisto_->SetBinContent(55,6);
105  timingHisto_->SetBinContent(56,4);
106  timingHisto_->SetBinContent(57,5);
107  timingHisto_->SetBinContent(58,9);
108  timingHisto_->SetBinContent(59,3);
109  timingHisto_->SetBinContent(60,3);
110  timingHisto_->SetBinContent(61,8);
111  timingHisto_->SetBinContent(62,7);
112  timingHisto_->SetBinContent(63,5);
113  timingHisto_->SetBinContent(64,7);
114  timingHisto_->SetBinContent(65,5);
115  timingHisto_->SetBinContent(66,5);
116  timingHisto_->SetBinContent(67,4);
117  timingHisto_->SetBinContent(68,2);
118  timingHisto_->SetBinContent(69,2);
119  timingHisto_->SetBinContent(70,4);
120  timingHisto_->SetBinContent(71,5);
121  timingHisto_->SetBinContent(72,4);
122  timingHisto_->SetBinContent(73,5);
123  timingHisto_->SetBinContent(74,3);
124  timingHisto_->SetBinContent(75,5);
125  timingHisto_->SetBinContent(76,3);
126  timingHisto_->SetBinContent(77,9);
127  timingHisto_->SetBinContent(78,2);
128  timingHisto_->SetBinContent(79,2);
129  timingHisto_->SetBinContent(80,5);
130  timingHisto_->SetBinContent(81,5);
131  timingHisto_->SetBinContent(82,5);
132  timingHisto_->SetBinContent(83,5);
133  timingHisto_->SetBinContent(84,4);
134  timingHisto_->SetBinContent(85,4);
135  timingHisto_->SetBinContent(86,9);
136  timingHisto_->SetBinContent(87,5);
137  timingHisto_->SetBinContent(88,4);
138  timingHisto_->SetBinContent(89,4);
139  timingHisto_->SetBinContent(90,5);
140  timingHisto_->SetBinContent(91,3);
141  timingHisto_->SetBinContent(92,3);
142  timingHisto_->SetBinContent(93,3);
143  timingHisto_->SetBinContent(94,7);
144  timingHisto_->SetBinContent(95,5);
145  timingHisto_->SetBinContent(96,6);
146  timingHisto_->SetBinContent(97,2);
147  timingHisto_->SetBinContent(98,3);
148  timingHisto_->SetBinContent(99,5);
149  timingHisto_->SetBinContent(101,147);
150  timingHisto_->SetEntries(24934);
151  }
153  {
154  gettimeofday(&tv_start_,0);
155  }
156 
158  {
159  float dummy = 0.;
160  unsigned int iterations = 0;
161  if(actionRequired_)
162  {
163  int *pi = 0;
164  int ind = 0;
165  int step = 1;
166  switch(actionId_)
167  {
168  case 0:
169  ::usleep(intqualifier_*1000);
170  break;
171  case 1:
172  ::sleep(0xFFFFFFF);
173  break;
174  case 2:
175  throw cms::Exception(qualifier_) << "This exception was generated by the ExceptionGenerator";
176  break;
177  case 3:
178  exit(-1);
179  break;
180  case 4:
181  abort();
182  break;
183  case 5:
184  throw qualifier_;
185  break;
186  case 6:
187  while(1){ind+=step; if(ind>1000000) step = -1; if(ind==0) step = 1;}
188  break;
189  case 7:
190  edm::LogError("TestErrorMessage") << qualifier_;
191  break;
192  case 8:
193  *pi=0;
194  break;
195  case 9:
196  for(unsigned int j=0; j<intqualifier_*1000;j++){
197  dummy += sqrt(log(float(j+1)))/float(j*j);
198  }
199  break;
200  case 10:
201  iterations = static_cast<unsigned int>(
202  timingHisto_->GetRandom() * intqualifier_*17. + 0.5
203  );
204  for(unsigned int j=0; j<iterations;j++){
205  dummy += sqrt(log(float(j+1)))/float(j*j);
206  }
207  break;
208  case 11:
209  {
210  iterations = static_cast<unsigned int>(
211  timingHisto_->GetRandom() * intqualifier_*12. + 0.5
212  );
213  TRandom3 random(iterations);
214  const size_t dataSize = 32*500; // 124kB
215  std::vector<double> data(dataSize);
216  random.RndmArray(dataSize, &data[0]);
217 
218  for(unsigned int j=0; j<iterations;j++){
219  const size_t index = static_cast<size_t>(random.Rndm() * dataSize + 0.5);
220  const double value = data[index];
221  dummy += sqrt(log(value+1))/(value*value);
222  if ( random.Rndm() < 0.1 )
223  data[index] = dummy;
224  }
225  }
226  break;
227  case 12:
228  {
229  timeval tv_now;
230  gettimeofday(&tv_now,0);
231  if (static_cast<unsigned long>(tv_now.tv_sec-tv_start_.tv_sec) > intqualifier_)
232  *pi=0;
233  }
234  break;
235  case 13:
236  void *vp = malloc(1024);
237  memset((char *)vp - 32, 0, 1024);
238  free(vp);
239  break;
240  }
241  }
242  }
243 
245  {
246 
247  }
248 
250  {
251  gettimeofday(&tv_start_,0);
253  std::string urn;
254  std::string mname;
256  try
257  {
258  cgicc::Cgicc cgi(in);
259  if ( xgi::Utils::hasFormElement(cgi,"exceptiontype") )
260  {
261  actionId_ = xgi::Utils::getFormElement(cgi, "exceptiontype")->getIntegerValue();
262  try {
263  qualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getValue();
264  intqualifier_ = xgi::Utils::getFormElement(cgi, "qualifier")->getIntegerValue();
265  }
266  catch (...) {
267  //didn't have some parameters
268  }
269  actionRequired_ = true;
270  }
271  if ( xgi::Utils::hasFormElement(cgi,"module") )
272  mname = xgi::Utils::getFormElement(cgi, "module")->getValue();
273  cgicc::CgiEnvironment cgie(in);
274  if(original_referrer_ == "")
275  original_referrer_ = cgie.getReferrer();
276  path = cgie.getPathInfo();
277  query = cgie.getQueryString();
278  if(actionId_>=0)
279  std::cout << " requested action " << actionId_ << " "
280  << menu[actionId_] << ". Number of cycles "
281  << intqualifier_ << std::endl;
282  }
283  catch (const std::exception & e)
284  {
285  // don't care if it did not work
286  }
287 
288  using std::endl;
289  *out << "<html>" << endl;
290  *out << "<head>" << endl;
291 
292 
293  *out << "<STYLE type=\"text/css\"> #T1 {border-width: 2px; border: solid blue; text-align: center} </STYLE> " << endl;
294  *out << "<link type=\"text/css\" rel=\"stylesheet\"";
295  *out << " href=\"/" << urn
296  << "/styles.css\"/>" << endl;
297 
298  *out << "<title>" << moduleName_
299  << " MAIN</title>" << endl;
300 
301  *out << "</head>" << endl;
302  *out << "<body onload=\"loadXMLDoc()\">" << endl;
303  *out << "<table border=\"0\" width=\"100%\">" << endl;
304  *out << "<tr>" << endl;
305  *out << " <td align=\"left\">" << endl;
306  *out << " <img" << endl;
307  *out << " align=\"middle\"" << endl;
308  *out << " src=\"/evf/images/systemerror.jpg\"" << endl;
309  *out << " alt=\"main\"" << endl;
310  *out << " width=\"90\"" << endl;
311  *out << " height=\"64\"" << endl;
312  *out << " border=\"\"/>" << endl;
313  *out << " <b>" << endl;
314  *out << moduleName_ << endl;
315  *out << " </b>" << endl;
316  *out << " </td>" << endl;
317  *out << " <td width=\"32\">" << endl;
318  *out << " <a href=\"/urn:xdaq-application:lid=3\">" << endl;
319  *out << " <img" << endl;
320  *out << " align=\"middle\"" << endl;
321  *out << " src=\"/hyperdaq/images/HyperDAQ.jpg\"" << endl;
322  *out << " alt=\"HyperDAQ\"" << endl;
323  *out << " width=\"32\"" << endl;
324  *out << " height=\"32\"" << endl;
325  *out << " border=\"\"/>" << endl;
326  *out << " </a>" << endl;
327  *out << " </td>" << endl;
328  *out << " <td width=\"32\">" << endl;
329  *out << " </td>" << endl;
330  *out << " <td width=\"32\">" << endl;
331  *out << " <a href=\"" << original_referrer_ << "\">" << endl;
332  *out << " <img" << endl;
333  *out << " align=\"middle\"" << endl;
334  *out << " src=\"/evf/images/spoticon.jpg\"" << endl;
335  *out << " alt=\"main\"" << endl;
336  *out << " width=\"32\"" << endl;
337  *out << " height=\"32\"" << endl;
338  *out << " border=\"\"/>" << endl;
339  *out << " </a>" << endl;
340  *out << " </td>" << endl;
341  *out << "</tr>" << endl;
342  *out << "</table>" << endl;
343 
344  *out << "<hr/>" << endl;
345 
346  *out << cgicc::form().set("method","GET").set("action", path )
347  << std::endl;
348  boost::char_separator<char> sep("&");
349  boost::tokenizer<boost::char_separator<char> > tokens(query, sep);
350  for (boost::tokenizer<boost::char_separator<char> >::iterator tok_iter = tokens.begin();
351  tok_iter != tokens.end(); ++tok_iter){
352  size_t pos = (*tok_iter).find_first_of("=");
353  if(pos != std::string::npos){
354  std::string first = (*tok_iter).substr(0 , pos);
355  std::string second = (*tok_iter).substr(pos+1, (*tok_iter).length()-pos-1);
356  *out << cgicc::input().set("type","hidden").set("name",first).set("value", second)
357  << std::endl;
358  }
359  }
360 
361  *out << "Select " << endl;
362  *out << cgicc::select().set("name","exceptiontype") << std::endl;
363  char istring[2];
364 
365  for(int i = 0; i < menu_items; i++)
366  {
367  sprintf(istring,"%d",i);
368  *out << cgicc::option().set("value",istring) << menu[i] << cgicc::option() << std::endl;
369  }
370  *out << cgicc::select() << std::endl;
371  *out << "<br>" << endl;
372  *out << "Qualifier" << endl;
373  *out << cgicc::input().set("type","text").set("name","qualifier") << std::endl;
374  *out << cgicc::input().set("type","submit").set("value","Do It !") << std::endl;
375  *out << cgicc::form() << std::endl;
376 
377  *out << "</body>" << endl;
378  *out << "</html>" << endl;
379  }
380  void ExceptionGenerator::publish(xdata::InfoSpace *is)
381  {
382  }
384  {
385  }
386 } // end namespace evf
int i
Definition: DBlmapReader.cc:9
virtual void publishForkInfo(moduleweb::ForkInfoObj *forkInfoObj)
#define Input(cl)
Definition: vmac.h:189
boost::tokenizer< boost::char_separator< char > > tokenizer
void defaultWebPage(xgi::Input *in, xgi::Output *out)
TRandom random
Definition: MVATrainer.cc:138
void publish(xdata::InfoSpace *)
void sleep(Duration_t)
Definition: Utils.h:163
U second(std::pair< T, U > const &p)
void analyze(const edm::Event &e, const edm::EventSetup &c)
T sqrt(T t)
Definition: SSEVec.h:48
int j
Definition: DBlmapReader.cc:9
bool first
Definition: L1TdeRCT.cc:94
std::string moduleName_
Definition: ModuleWeb.h:61
static const int menu_items
tuple out
Definition: dbtoconf.py:99
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
static const std::string menu[menu_items]
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
#define Output(cl)
Definition: vmac.h:193
tuple query
Definition: o2o.py:269
void beginRun(edm::Run &r, const edm::EventSetup &iSetup)
tuple cout
Definition: gather_cfg.py:121
double pi
Definition: Run.h:36