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