CMS 3D CMS Logo

mps_check.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # This script checks outputs from jobs that have FETCH status and updates if errors occured
4 # -> check STDOUT files
5 # -> check cmsRun.out
6 # -> check alignment.log
7 # -> check if millebinaries are on eos
8 # -> check pede.dump
9 # -> check millepede.log
10 # -> check millepede.end
11 #
12 # It also retirieves number of events from alignment.log and cputime from STDOUT
13 
14 from __future__ import print_function
15 from builtins import range
16 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass as mpslib
17 import subprocess
18 import re
19 import os
20 
21 lib = mpslib.jobdatabase()
22 lib.read_db()
23 
24 # create a list of eos ls entries containing files on eos binary store
25 command = ["ls", "-l", os.path.join(lib.mssDir, "binaries")]
26 try:
27  eoslsoutput = subprocess.check_output(command, stderr=subprocess.STDOUT).split('\n')
28 except subprocess.CalledProcessError:
29  eoslsoutput = ""
30 
31 # loop over FETCH jobs
32 for i in range(len(lib.JOBID)):
33  # FIXME use bools?
34  batchSuccess = 0
35  batchExited = 0
36  finished = 0
37  endofjob = 0
38  eofile = 1 # do not deal with timel yet
39  timel = 0
40  killed = 0
41  ioprob = 0
42  fw8001 = 0
43  tooManyTracks = 0
44  segviol = 0
45  rfioerr = 0
46  quota = 0
47  nEvent = 0
48  cputime = -1
49  pedeAbend = 0
50  pedeLogErr = 0
51  pedeLogWrn = 0
52  exceptionCaught = 0
53  timeout = 0
54  cfgerr = 0
55  emptyDatErr = 0
56  emptyDatOnFarm = 0
57  cmdNotFound = 0
58  insuffPriv = 0
59  quotaspace = 0
60 
61  kill_reason = None
62  pedeLogErrStr = ""
63  pedeLogWrnStr = ""
64  remark = ""
65 
66  disabled = "";
67  if 'DISABLED' in lib.JOBSTATUS[i]:
68  disabled = 'DISABLED'
69 
70  if 'FETCH' in lib.JOBSTATUS[i]:
71 
72  # open the STDOUT file
73  stdOut = 'jobData/'+lib.JOBDIR[i]+'/STDOUT'
74  # unzip the STDOUT file if necessary
75  if os.access(stdOut+'.gz', os.R_OK):
76  os.system('gunzip '+stdOut+'.gz')
77 
78  try:
79  with open(stdOut, "r") as STDFILE:
80  # scan records in input file.
81  # use regular expression to search. re.compile needed for options re.M and re.I
82  # re.M=re.MULTILINE enables matching of newline char
83  # re.I=re.IGNORECASE makes matching case-insensitive.
84  for line in STDFILE:
85  if re.search(re.compile('Unable to access quota space',re.M|re.I), line):
86  quotaspace = 1
87  if re.search(re.compile('Unable to get quota space',re.M|re.I), line):
88  quotaspace = 1
89  if re.search(re.compile('Disk quota exceeded',re.M|re.I), line):
90  quotaspace = 1
91  if re.search(re.compile('CERN report: Job Killed',re.M), line):
92  killed = 1
93  if re.search(re.compile('Job finished',re.M), line):
94  finished = 1
95  if re.search(re.compile('connection timed out',re.M), line):
96  timeout = 1
97  if re.search(re.compile('ConfigFileReadError',re.M), line):
98  cfgerr = 1
99  if re.search(re.compile('0 bytes transferred',re.M), line):
100  emptyDatOnFarm = 1
101  if re.search(re.compile('command not found',re.M), line):
102  cmdNotFound = 1
103  # AP 26.11.2009 Insufficient privileges to rfcp files
104  if re.search(re.compile('stage_put: Insufficient user privileges',re.M), line):
105  insuffPriv = 1
106  # AP 05.11.2015 Extract cpu-time.
107  # STDOUT doesn't contain NCU anymore. Now KSI2K and HS06 seconds are displayed.
108  # The ncuFactor is calculated from few samples by comparing KSI2K seconds with
109  # CPU time from email.
110  match = re.search(re.compile('This process used .+?(\d+) KSI2K seconds',re.M|re.I), line)
111  if match:
112  cpuFactor = 2.125
113  cputime = int(round(int(match.group(1))/cpuFactor)) # match.group(1) is the matched digit
114 
115  # gzip it afterwards:
116  print('gzip -f '+stdOut)
117  os.system('gzip -f '+stdOut)
118  except IOError as e:
119  if e.args == (2, "No such file or directory"):
120  print("mps_check.py cannot find", stdOut, "to test")
121  else:
122  raise
123 
124  # check HTCondor log file
125  try:
126  log_file = os.path.join("jobData", lib.JOBDIR[i], "HTCJOB")
127  condor_log = subprocess.check_output(["condor_q", lib.JOBID[i],
128  "-userlog", log_file,
129  "-af",
130  "RemoteSysCpu",
131  "JobStatus",
132  "RemoveReason"],
133  stderr = subprocess.STDOUT)
134  condor_log = condor_log.split()
135 
136  cputime = int(round(float(condor_log[0])))
137 
138  if condor_log[1] == "3": # JobStatus == Removed
139  killed = 1
140  kill_reason = " ".join(condor_log[2:])
141 
142  except subprocess.CalledProcessError as e:
143  pass
144 
145 
146  # GF: This file is not produced (anymore...) -> check for existence and read-access added
147  eazeLog = 'jobData/'+lib.JOBDIR[i]+'/cmsRun.out'
148  if os.access(eazeLog, os.R_OK):
149  # open the input file
150  with open(eazeLog, "r") as INFILE:
151  # scan records in input file
152  for line in INFILE:
153  # check if end of file has been reached
154  if re.search(re.compile('<StorageStatistics>',re.M), line):
155  eofile = 1
156  if re.search(re.compile('Time limit reached\.',re.M), line):
157  timel = 1
158  if re.search(re.compile('gives I\/O problem',re.M), line):
159  ioprob = 1
160  if re.search(re.compile('FrameworkError ExitStatus=[\'\"]8001[\'\"]',re.M), line):
161  fw8001 = 1
162  if re.search(re.compile('too many tracks',re.M), line):
163  tooManyTracks = 1
164  if re.search(re.compile('segmentation violation',re.M), line):
165  segviol = 1
166  if re.search(re.compile('failed RFIO error',re.M), line):
167  rfioerr = 1
168  if re.search(re.compile('Request exceeds quota',re.M), line):
169  quota = 1
170 
171  # if there is an alignment.log[.gz] file, check it as well
172  eazeLog = 'jobData/'+lib.JOBDIR[i]+'/alignment.log'
173  logZipped = 'no'
174  # unzip the logfile if necessary
175  if os.access(eazeLog+'.gz', os.R_OK):
176  os.system('gunzip '+eazeLog+'.gz')
177  logZipped = 'true'
178 
179  if os.access(eazeLog, os.R_OK): # access to alignment.log
180  # open the input file
181  with open(eazeLog,'r') as INFILE:
182  # scan records in input file
183  for line in INFILE:
184  # check if end of file has been reached
185  if re.search(re.compile('<StorageStatistics>',re.M), line):
186  eofile = 1
187  if re.search(re.compile('EAZE\. Time limit reached\.',re.M), line):
188  timel = 1
189  if re.search(re.compile('GAF gives I\/O problem',re.M), line):
190  ioprob = 1
191  if re.search(re.compile('FrameworkError ExitStatus=[\'\"]8001[\'\"]',re.M), line):
192  fw8001 = 1
193  if re.search(re.compile('too many tracks',re.M), line):
194  tooManyTracks = 1
195  if re.search(re.compile('segmentation violation',re.M), line):
196  segviol = 1
197  if re.search(re.compile('failed RFIO error',re.M), line):
198  rfioerr = 1
199  if re.search(re.compile('Request exceeds quota',re.M), line):
200  quota = 1
201  # check for newer (e.g. CMSSW_5_1_X) and older CMSSW:
202  if re.search(re.compile('Fatal Exception',re.M), line):
203  exceptionCaught = 1
204  if re.search(re.compile('Exception caught in cmsRun',re.M), line):
205  exceptionCaught = 1
206  # AP 07.09.2009 - Check that the job got to a normal end
207  if re.search(re.compile('AlignmentProducerAsAnalyzer::endJob\(\)',re.M), line):
208  endofjob = 1
209  if re.search(re.compile('FwkReport -i main_input:sourc',re.M), line):
210  array = line.split()
211  nEvent = int(array[5])
212  if nEvent==0 and re.search(re.compile('FwkReport -i PostSource',re.M), line):
213  array = line.split()
214  nEvent = int(array[5])
215  # AP 31.07.2009 - To read number of events in CMSSW_3_2_2_patch2
216  if nEvent==0 and re.search(re.compile('FwkReport -i AfterSource',re.M), line):
217  array = line.split()
218  nEvent = int(array[5])
219 
220  if logZipped == 'true':
221  os.system('gzip '+eazeLog)
222 
223  else: # no access to alignment.log
224  print('mps_check.py cannot find',eazeLog,'to test')
225  # AP 07.09.2009 - The following check cannot be done: set to 1 to avoid fake error type
226  endofjob = 1
227 
228  # for mille jobs checks that milleBinary file is not empty
229  if i<lib.nJobs: # mille job!
230  milleOut = 'milleBinary%03d.dat' % (i+1)
231  # from Perl, should be deprecated because of cmsls and nsls
232  #(not translated to python, yes I'm lazy... use subprocess.checkout if needed):
233  #$mOutSize = `nsls -l $mssDir | grep $milleOut | head -1 | awk '{print \$5}'`;
234  #$mOutSize = `cmsLs -l $mssDir | grep $milleOut | head -1 | awk '{print \$2}'`;
235  mOutSize = 0
236  for line in eoslsoutput:
237  if milleOut in line:
238  columns = line.split()
239  mOutSize = columns[4] # 5th column = size
240  if not (mOutSize>0):
241  emptyDatErr = 1
242 
243  # merge jobs: additional checks for merging job
244  else:
245  # if there is a pede.dump file check it as well
246  eazeLog = 'jobData/'+lib.JOBDIR[i]+'/pede.dump'
247  if os.access(eazeLog+'.gz', os.R_OK):
248  # unzip - but clean before and save to tmp
249  os.system('rm -f /tmp/pede.dump')
250  os.system('gunzip -c '+eazeLog+'.gz > /tmp/pede.dump')
251  eazeLog = '/tmp/pede.dump'
252  if os.access(eazeLog, os.R_OK):
253  with open(eazeLog, "r") as INFILE: # open pede.dump
254  # scan records in INFILE
255  pedeAbend = 1
256  usedPedeMem = 0.
257  for line in INFILE:
258  # check if pede has reached its normal end
259  if re.search(re.compile('Millepede II.* ending',re.M), line):
260  pedeAbend = 0
261  # extract memory usage
262  match = re.search(re.compile('Peak dynamic memory allocation: (.+) GB',re.I), line)
263  if match:
264  mem = match.group(1)
265  mem = re.sub('\s', '', mem)
266  # if mem is a float
267  if re.search(re.compile('^\d+\.\d+$',re.M), mem):
268  usedPedeMem = float(mem)
269  else:
270  print('mps_check.py: Found Pede peak memory allocation but extracted number is not a float:',mem)
271 
272  # check memory usage
273  # no point in asking if lib.pedeMem is defined. Initialized as lib.pedeMem=-1
274  if lib.pedeMem > 0 and usedPedeMem > 0.:
275  memoryratio = usedPedeMem /(lib.pedeMem/1024.)
276  # print a warning if more than approx. 4 GB have been
277  # requested of which less than 75% are used by Pede
278  if lib.pedeMem > 4000 and memoryratio < 0.75 :
279  msg = ("Warning: {0:.2f} GB of memory for Pede "
280  "requested, but only {1:.1f}% of it has been "
281  "used! Consider to request less memory in order "
282  "to save resources.")
283  print(msg.format(lib.pedeMem/1024.0, memoryratio*100))
284  elif memoryratio > 1 :
285  msg = ("Warning: {0:.2f} GB of memory for Pede "
286  "requested, but {1:.1f}% of this has been "
287  "used! Consider to request more memory to avoid "
288  "premature removal of the job by the admin.")
289  print(msg.format(lib.pedeMem/1024.0, memoryratio*100))
290  else:
291  msg = ("Info: Used {0:.1f}% of {1:.2f} GB of memory "
292  "which has been requested for Pede.")
293  print(msg.format(memoryratio*100, lib.pedeMem/1024.0))
294 
295 
296  # clean up /tmp/pede.dump if needed
297  if eazeLog == '/tmp/pede.dump':
298  os.system('rm /tmp/pede.dump')
299 
300  # pede.dump not found or no read-access
301  else:
302  print('mps_check.py cannot find',eazeLog,'to test')
303 
304  # if there is a millepede.log file, check it as well
305  eazeLog = 'jobData/'+lib.JOBDIR[i]+'/millepede.log'
306  logZipped = 'no'
307  if os.access(eazeLog+'.gz', os.R_OK):
308  os.system('gunzip '+eazeLog+'.gz')
309  logZipped = 'true'
310 
311  if os.access(eazeLog, os.R_OK):
312  # open log file
313  with open(eazeLog, "r") as INFILE:
314  # scan records in input file
315  for line in INFILE:
316  # Checks for Pede Errors
317  if re.search(re.compile('step no descending',re.M), line):
318  pedeLogErr = 1
319  pedeLogErrStr += line
320  if re.search(re.compile('Constraint equation discrepancies:',re.M), line):
321  pedeLogErr = 1
322  pedeLogErrStr += line
323  # AP 07.09.2009 - Checks for Pede Warnings:
324  if re.search(re.compile('insufficient constraint equations',re.M), line):
325  pedeLogWrn = 1
326  pedeLogWrnStr += line
327 
328  if logZipped == 'true':
329  os.system('gzip '+eazeLog)
330  else:
331  print('mps_check.py cannot find',eazeLog,'to test')
332 
333 
334  # check millepede.end -- added F. Meier 03.03.2015
335  eazeLog = 'jobData/'+lib.JOBDIR[i]+'/millepede.end'
336  logZipped = 'no'
337  if os.access(eazeLog+'.gz', os.R_OK):
338  os.system('gunzip'+eazeLog+'.gz')
339  logZipped = 'true'
340 
341  if os.access(eazeLog, os.R_OK):
342  # open log file
343  with open(eazeLog, "r") as INFILE:
344  # scan records in input file
345  for line in INFILE:
346  # Checks for the output code. 0 is OK, 1 is WARN, anything else is FAIL
347  # searches the line for a number with or without a sign
348  match = re.search(re.compile('([-+]?\d+)',re.M), line)
349  if match:
350  if int(match.group(1)) == 1:
351  pedeLogWrn = 1
352  pedeLogWrnStr += line
353  elif int(match.group(1)) != 0:
354  pedeLogErr = 1
355  pedeLogErrStr += line
356  if logZipped == 'true':
357  os.system('gzip '+eazeLog)
358  else:
359  print('mps_check.py cannot find',eazeLog,'to test')
360 
361  # end of merge job checks
362  # evaluate Errors:
363  farmhost = ' '
364 
365  okStatus = 'OK'
366  if not eofile == 1:
367  print(lib.JOBDIR[i],lib.JOBID[i],'did not reach end of file')
368  okStatus = 'ABEND'
369  if quotaspace == 1:
370  print(lib.JOBDIR[i],lib.JOBID[i],'had quota space problem')
371  okStatus = 'FAIL'
372  remark = 'eos quota space problem'
373  if ioprob == 1:
374  print(lib.JOBDIR[i],lib.JOBID[i],'had I/O problem')
375  okStatus = 'FAIL'
376  if fw8001 == 1:
377  print(lib.JOBDIR[i],lib.JOBID[i],'had Framework error 8001 problem')
378  remark = 'fwk error 8001'
379  okStatus = 'FAIL'
380  if timeout == 1:
381  print(lib.JOBDIR[i],lib.JOBID[i],'had connection timed out problem')
382  remark = 'connection timed out'
383  if cfgerr == 1:
384  print(lib.JOBDIR[i],lib.JOBID[i],'had config file error')
385  remark = 'cfg file error'
386  okStatus = 'FAIL'
387  if killed == 1:
388  guess = " (probably time exceeded)" if kill_reason is None else ":"
389  print(lib.JOBDIR[i], lib.JOBID[i], "Job killed" + guess)
390  if kill_reason is not None: print(kill_reason)
391  remark = "killed";
392  okStatus = "FAIL"
393  if timel == 1:
394  print(lib.JOBDIR[i],lib.JOBID[i],'ran into time limit')
395  okStatus = 'TIMEL'
396  if tooManyTracks == 1:
397  print(lib.JOBDIR[i],lib.JOBID[i],'too many tracks')
398  if segviol == 1:
399  print(lib.JOBDIR[i],lib.JOBID[i],'SEGVIOL encountered')
400  remark = 'seg viol'
401  okStatus = 'FAIL'
402  if rfioerr == 1:
403  print(lib.JOBDIR[i],lib.JOBID[i],'RFIO error encountered')
404  remark = 'rfio error'
405  okStatus = 'FAIL'
406  if quota == 1:
407  print(lib.JOBDIR[i],lib.JOBID[i],'Request exceeds quota')
408  if exceptionCaught == 1:
409  print(lib.JOBDIR[i],lib.JOBID[i],'Exception caught in cmsrun')
410  remark = 'Exception caught'
411  okStatus = 'FAIL'
412  if emptyDatErr == 1:
413  print('milleBinary???.dat file not found or empty')
414  remark = 'empty milleBinary'
415  if emptyDatOnFarm > 0:
416  print('...but already empty on farm so OK (or check job',i+1,'yourself...)')
417  else:
418  okStatus = 'FAIL'
419  if cmdNotFound == 1:
420  print(lib.JOBDIR[i],lib.JOBID[i],'Command not found')
421  remark = 'cmd not found'
422  okStatus = 'FAIL'
423  if insuffPriv == 1:
424  print(lib.JOBDIR[i],lib.JOBID[i],'Insufficient privileges to rfcp files')
425  remark = 'Could not rfcp files'
426  okStatus = 'FAIL'
427  if pedeAbend == 1:
428  print(lib.JOBDIR[i],lib.JOBID[i],'Pede did not end normally')
429  remark = 'pede failed'
430  okStatus = 'FAIL'
431  if pedeLogErr == 1:
432  print(lib.JOBDIR[i],lib.JOBID[i],'Problems in running Pede:')
433  print(pedeLogErrStr)
434  remark = 'pede error'
435  okStatus = 'FAIL'
436  if pedeLogWrn == 1:
437  # AP 07.09.2009 - Reports Pede Warnings (but do _not_ set job status to FAIL)
438  print(lib.JOBDIR[i],lib.JOBID[i],'Warnings in running Pede:')
439  print(pedeLogWrnStr)
440  remark = 'pede warnings'
441  okStatus = 'WARN'
442  if endofjob != 1:
443  print(lib.JOBDIR[i],lib.JOBID[i],'Job not ended')
444  remark = 'job not ended'
445  okStatus = 'FAIL'
446 
447  # print warning line to stdout
448  if okStatus != "OK":
449  print(lib.JOBDIR[i],lib.JOBID[i],' -------- ',okStatus)
450 
451  # update number of events
452  lib.JOBNEVT[i] = nEvent
453  # udate Jobstatus
454  lib.JOBSTATUS[i] = disabled+okStatus
455  # update cputime
456  lib.JOBRUNTIME[i] = cputime
457  # update remark
458  lib.JOBREMARK[i] = remark
459  # update host
460  ##lib.JOBHOST[i] = farmhost
461 
462 lib.write_db()
463 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139