CMS 3D CMS Logo

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