CMS 3D CMS Logo

summarizeEdmComparisonLogfiles.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 
3 from __future__ import print_function
4 import optparse
5 import os
6 from glob import glob
7 import re
8 import pprint
9 import subprocess
10 countRE = re.compile (r'^count_(\w+)')
11 avoid = ['index', 'print']
12 
13 def summaryOK (summary):
14  """returns a tuple. First value is true if summary hasn't found
15  any problems, else false."""
16  retval = True
17  count = -1
18  compared = summary.get('eventsCompared', -1)
19  if len( summary) != 2:
20  retval = False
21  for key,value in summary.items():
22  if countRE.search(key):
23  count = value
24  return (retval, {'count':count, 'compared':compared})
25 
26 if __name__ == "__main__":
27 
28  # compile regexs
29  percentRE = re.compile (r'%')
30  startOutputRE = re.compile (r'^Summary$')
31  success1RE = re.compile (r"{'eventsCompared':\s+(\d+),\s+'count_(\S+)':\s+(\d+)\s*}")
32  success2RE = re.compile (r"{'count_(\S+)':\s+(\d+),\s+'eventsCompared':\s+(\d+)\s*}")
33  loadingSoRE = re.compile (r'loading (genobjectrootlibs/\w+)')
34  creatingSoRE = re.compile (r'creating shared library (\S+)')
35  compRootRE = re.compile (r' --compRoot=(\S+)')
36  descriptionRE = re.compile (r'^edmOneToOneComparison.py (\w+).txt')
37  edmCommandRE = re.compile (r'^(edmOneToOneComparison.py .+?)\s*$')
38  # problem regexs
39  labelErrorRE = re.compile (r"labelDict = GenObject._ntupleDict\[tupleName\]\['_label'\]")
40  missingLabelRE = re.compile (r'not able to get')
41  terminatedRE = re.compile (r'Terminated\s+\$EXE\s+\$@')
42  cppExceptionRE = re.compile (r'\(C\+\+ exception\)')
43  missingCfgRE = re.compile (r"raise.+Can't open configuration")
44  finishRE = re.compile (r'finish')
45  dummyRE = re.compile (r'edm::Wrapper<dummyType>')
46  noEdmWrapperRE = re.compile (r"'ROOT' has no attribute 'edm::Wrapper")
47  uint32RE = re.compile (r"Config file parser error 'operatoruint32_t")
48  nonSpacesRE = re.compile (r'\S')
49  problemDict = { 'labelDict' : labelErrorRE,
50  'missingLabel' : missingLabelRE,
51  'terminate' : terminatedRE,
52  'uint32' : uint32RE,
53  'cppException' : cppExceptionRE,
54  'missingCfg' : missingCfgRE,
55  'noEdmWrapper' : noEdmWrapperRE,
56  'dummy' : dummyRE,
57  'operator' : re.compile (r"onfig file parser error 'operator"),
58  'useless' : re.compile (r'no member functions that are useful'),
59  'lazy' : re.compile (r': Assertion'),
60  'detset' : re.compile (r"AttributeError: 'edm::DetSet"),
61  'doubleint' : re.compile (r'AttributeError: (int|double)'),
62  'finish' : finishRE}
63 
64  parser = optparse.OptionParser ("Usage: %prog logfilePrefix [directory]")
65  parser.add_option ("--counts", dest="counts",
66  action="store_true", default=False,
67  help="Display counts only.")
68  parser.add_option ('--mismatch', dest='mismatch',
69  action='store_true',
70  help='Displays only mismatch output')
71  parser.add_option ("--diffTree", dest="diffTree",
72  action="store_true", default=False,
73  help="Shows diffTree printout.")
74  parser.add_option ('--makeCompRoot', dest='makeCompRoot',
75  action='store_true',
76  help='Prints commands to make compRoot files for difftree')
77  parser.add_option ("--problem", dest="problem", type='string',
78  help="Displays problems matching PROBLEM")
79 
80  options, args = parser.parse_args()
81  if not 1 <= len (args) <= 2:
82  raise RuntimeError("Must give directory and log file prefix")
83  logfilePrefix = percentRE.sub ('*', args[0])
84  if logfilePrefix[-1] != '*':
85  logfilePrefix += '*'
86  cwd = os.getcwd()
87  logdir = ''
88  if len (args) == 2:
89  logdir = args[1]
90  os.chdir (logdir)
91  files = glob (logfilePrefix)
92  if logdir:
93  oldFiles = files
94  files = []
95  for filename in oldFiles:
96  files.append (logdir + '/' + filename)
97  os.chdir (cwd)
98  totalFiles = len (files)
99  problems = {}
100  succeeded = 0
101  weird = 0
102  problemTypes = {}
103  successes = {}
104  objectName = ''
105  compRoot = ''
106  soName = ''
107  command = ''
108  diffOutput = {}
109  goShlib = ''
110  for log in files:
111  problemSet = set()
112  source = open (log, 'r')
113  ran = False
114  success = False
115  reading = False
116  summaryLines = ''
117  for line in source:
118  line = line.rstrip('\n')
119  match = edmCommandRE.search (line)
120  if match:
121  command = match.group(1)
122  match = loadingSoRE.search (line)
123  if match:
124  goShlib = match.group(1)
125  match = creatingSoRE.search (line)
126  if match:
127  goShlib = match.group(1)
128  if options.diffTree:
129  match = descriptionRE.search (line)
130  if match:
131  objectName = match.group(1)
132  match = compRootRE.search (line)
133  if match:
134  compRoot = match.group(1)
135  match = loadingSoRE.search (line)
136  if match:
137  soName = match.group(1)
138  if reading:
139  if not nonSpacesRE.search(line):
140  reading = False
141  continue
142  summaryLines += line
143  if startOutputRE.search(line):
144  ran = True
145  reading = True
146  continue
147  if success1RE.search (line) or success2RE.search(line):
148  success = True
149  continue
150  for key, regex in problemDict.items():
151  #print "considering %s for %s" % (key, line)
152  if regex.search(line):
153  if key in problemSet:
154  continue
155  problemSet.add (key)
156  problems.setdefault(log,[]).append(key)
157  if key not in problemTypes:
158  problemTypes[key] = 1
159  else:
160  problemTypes[key] += 1
161  key = ''
162  source.close()
163 
164  if summaryLines:
165  summary = eval (summaryLines)
166  ok = summaryOK (summary)
167  else:
168  ok = (False,)
169  summary = None
170  if ran and success:
171  succeeded += 1
172  if not ok[0]:
173  weird += 1
174  else:
175  successes[log] = pprint.pformat (summary, indent=4)
176  else:
177  if ok[0]:
178  weird += 1
179  if log not in problems and not ok[0]:
180  if not ok[0] and summary:
181  key = 'mismatch'
182  problems[log] = pprint.pformat (summary, indent=4)
183  #pprint.pprint (summary, indent=4)
184  if objectName and compRoot and soName:
185  # do the diffTree magic
186  varNames = summary.get(objectName, {}).\
187  get('_var', {}).keys()
188  variables = ['eta', 'phi']
189  for var in sorted (varNames):
190  if var not in variables and var not in avoid:
191  variables.append (var)
192  diffCmd = 'diffTreeTool.py --skipUndefined %s %s %s' \
193  % (compRoot, soName, " ".join(variables))
194  # print diffCmd
195  diffOutput[log] = diffCmd
196  else:
197  problems[log] = ['other','ran:%s' % ran,
198  'success:%s' % success]
199  key = 'other'
200  if key not in problemTypes:
201  problemTypes[key] = 1
202  else:
203  problemTypes[key] += 1
204  mismatches = problemTypes.get('mismatch', 0)
205  if 'mismatch' in problemTypes:
206  del problemTypes['mismatch']
207  print("total: ", len (files))
208  print("success: ", succeeded)
209  print("mismatches: ", mismatches)
210  print("weird: ", weird)
211  print("Tool issue types:")
212  total = 0
213  for key, value in sorted (problemTypes.items()):
214  print(" %-15s: %4d" % (key, value))
215  total += value
216  print(" ", '-'*13, " : ----")
217  print(" %-15s: %4d + %d + %d + %d = %d" \
218  % ('total', total, succeeded, mismatches, weird,
219  total + succeeded + mismatches + weird))
220 
221  if not options.counts:
222  print("\nDetailed Problems list:")
223  for key, problemList in sorted (problems.items()):
224  if options.problem and problemList[0] != options.problem:
225  continue
226  if options.mismatch and not isinstance (problemList, str):
227  continue
228  #if options.mismatch and
229  print(" %s:\n %s\n" % (key, problemList))
230  if options.mismatch and goShlib and compRoot:
231  print("diffTree %s %s" % (goShlib, compRoot))
232  diffCmd = diffOutput.get(key)
233  if diffCmd:
234  print(subprocess.getoutput (diffCmd))
235  if not options.problem and not options.mismatch:
236  print("\n", '='*78, '\n')
237  print("Success list:")
238  for key, successesList in sorted (successes.items()):
239  print(" %s:\n %s\n" % (key, successesList))
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19