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'^problems$')
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  'finish' : finishRE}
57 
58  parser = optparse.OptionParser ("Usage: %prog logfilePrefix [directory]")
59  parser.add_option ("--counts", dest="counts",
60  action="store_true", default=False,
61  help="Display counts only.")
62  parser.add_option ('--mismatch', dest='mismatch',
63  action='store_true',
64  help='Displays only mismatch output')
65  parser.add_option ("--diffTree", dest="diffTree",
66  action="store_true", default=False,
67  help="Shows diffTree printout.")
68  parser.add_option ('--makeCompRoot', dest='makeCompRoot',
69  action='store_true',
70  help='Prints commands to make compRoot files for difftree')
71  parser.add_option ("--problem", dest="problem", type='string',
72  help="Displays problems matching PROBLEM")
73 
74  options, args = parser.parse_args()
75  if not 1 <= len (args) <= 2:
76  raise RuntimeError, "Must give directory and log file prefix"
77  logfilePrefix = percentRE.sub ('*', args[0])
78  if logfilePrefix[-1] != '*':
79  logfilePrefix += '*'
80  cwd = os.getcwd()
81  logdir = ''
82  if len (args) == 2:
83  logdir = args[1]
84  os.chdir (logdir)
85  files = glob (logfilePrefix)
86  if logdir:
87  oldFiles = files
88  files = []
89  for filename in oldFiles:
90  files.append (logdir + '/' + filename)
91  os.chdir (cwd)
92  totalFiles = len (files)
93  problems = {}
94  succeeded = 0
95  weird = 0
96  problemTypes = {}
97  successes = {}
98  objectName = ''
99  compRoot = ''
100  soName = ''
101  command = ''
102  diffOutput = {}
103  goShlib = ''
104  for log in files:
105  problemSet = set()
106  source = open (log, 'r')
107  ran = False
108  success = False
109  reading = False
110  summaryLines = ''
111  for line in source:
112  line = line.rstrip('\n')
113  match = edmCommandRE.search (line)
114  if match:
115  command = match.group(1)
116  match = loadingSoRE.search (line)
117  if match:
118  goShlib = match.group(1)
119  match = creatingSoRE.search (line)
120  if match:
121  goShlib = match.group(1)
122  if options.diffTree:
123  match = descriptionRE.search (line)
124  if match:
125  objectName = match.group(1)
126  match = compRootRE.search (line)
127  if match:
128  compRoot = match.group(1)
129  match = loadingSoRE.search (line)
130  if match:
131  soName = match.group(1)
132  if reading:
133  if not nonSpacesRE.search(line):
134  reading = False
135  continue
136  summaryLines += line
137  if startOutputRE.search(line):
138  ran = True
139  reading = True
140  continue
141  if success1RE.search (line) or success2RE.search(line):
142  success = True
143  continue
144  for key, regex in problemDict.iteritems():
145  #print "considering %s for %s" % (key, line)
146  if regex.search(line):
147  if key in problemSet:
148  continue
149  problemSet.add (key)
150  problems.setdefault(log,[]).append(key)
151  if not problemTypes.has_key(key):
152  problemTypes[key] = 1
153  else:
154  problemTypes[key] += 1
155  key = ''
156  source.close()
157 
158  if summaryLines:
159  summary = eval (summaryLines)
160  ok = summaryOK (summary)
161  else:
162  ok = (False,)
163  summary = None
164  if ran and success:
165  succeeded += 1
166  if not ok[0]:
167  weird += 1
168  else:
169  successes[log] = pprint.pformat (summary, indent=4)
170  else:
171  if ok[0]:
172  weird += 1
173  if not problems.has_key (log) and not ok[0]:
174  if not ok[0] and summary:
175  key = 'mismatch'
176  problems[log] = pprint.pformat (summary, indent=4)
177  #pprint.pprint (summary, indent=4)
178  if objectName and compRoot and soName:
179  # do the diffTree magic
180  varNames = summary.get(objectName, {}).\
181  get('_var', {}).keys()
182  variables = ['eta', 'phi']
183  for var in sorted (varNames):
184  if var not in variables and var not in avoid:
185  variables.append (var)
186  diffCmd = 'diffTreeTool.py --skipUndefined %s %s %s' \
187  % (compRoot, soName, " ".join(variables))
188  # print diffCmd
189  diffOutput[log] = diffCmd
190  else:
191  problems[log] = ['other','ran:%s' % ran,
192  'success:%s' % success]
193  key = 'other'
194  if not problemTypes.has_key(key):
195  problemTypes[key] = 1
196  else:
197  problemTypes[key] += 1
198  mismatches = problemTypes.get('mismatch', 0)
199  if problemTypes.has_key ('mismatch'):
200  del problemTypes['mismatch']
201  print "total: ", len (files)
202  print "success: ", succeeded
203  print "mismatches: ", mismatches
204  print "weird: ", weird
205  print "Tool issue types:"
206  total = 0
207  for key, value in sorted (problemTypes.iteritems()):
208  print " %-15s: %4d" % (key, value)
209  total += value
210  print " ", '-'*13, " : ----"
211  print " %-15s: %4d + %d + %d + %d = %d" \
212  % ('total', total, succeeded, mismatches, weird,
213  total + succeeded + mismatches + weird)
214 
215  if not options.counts:
216  print "\nDetailed Problems list:"
217  for key, problemList in sorted (problems.iteritems()):
218  if options.problem and problemList[0] != options.problem:
219  continue
220  if options.mismatch and not isinstance (problemList, str):
221  continue
222  #if options.mismatch and
223  print " %s:\n %s\n" % (key, problemList)
224  if options.mismatch and goShlib and compRoot:
225  print "diffTree %s %s" % (goShlib, compRoot)
226  diffCmd = diffOutput.get(key)
227  if diffCmd:
228  print commands.getoutput (diffCmd)
229  if not options.problem and not options.mismatch:
230  print "\n", '='*78, '\n'
231  print "Success list:"
232  for key, successesList in sorted (successes.iteritems()):
233  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