CMS 3D CMS Logo

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