Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:33:41

0001 #! /usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 import optparse
0005 import os
0006 from glob import glob
0007 import re
0008 import pprint
0009 import subprocess
0010 countRE = re.compile (r'^count_(\w+)')
0011 avoid = ['index', 'print']
0012 
0013 def summaryOK (summary):
0014     """returns a tuple.  First value is true if summary hasn't found
0015     any problems, else false."""
0016     retval = True
0017     count    = -1
0018     compared = summary.get('eventsCompared', -1)
0019     if len( summary) != 2:
0020         retval = False
0021     for key,value in summary.items():
0022         if countRE.search(key):
0023             count = value
0024     return (retval, {'count':count, 'compared':compared})
0025 
0026 if __name__ == "__main__":
0027 
0028     # compile regexs
0029     percentRE      = re.compile (r'%')
0030     startOutputRE  = re.compile (r'^Summary$')
0031     success1RE     = re.compile (r"{'eventsCompared':\s+(\d+),\s+'count_(\S+)':\s+(\d+)\s*}")
0032     success2RE     = re.compile (r"{'count_(\S+)':\s+(\d+),\s+'eventsCompared':\s+(\d+)\s*}")
0033     loadingSoRE    = re.compile (r'loading (genobjectrootlibs/\w+)')
0034     creatingSoRE   = re.compile (r'creating shared library (\S+)')
0035     compRootRE     = re.compile (r' --compRoot=(\S+)')
0036     descriptionRE  = re.compile (r'^edmOneToOneComparison.py (\w+).txt')
0037     edmCommandRE  = re.compile (r'^(edmOneToOneComparison.py .+?)\s*$')
0038     # problem regexs
0039     labelErrorRE   = re.compile (r"labelDict = GenObject._ntupleDict\[tupleName\]\['_label'\]")
0040     missingLabelRE = re.compile (r'not able to get')
0041     terminatedRE   = re.compile (r'Terminated\s+\$EXE\s+\$@')
0042     cppExceptionRE = re.compile (r'\(C\+\+ exception\)')
0043     missingCfgRE   = re.compile (r"raise.+Can't open configuration")
0044     finishRE       = re.compile (r'finish')
0045     dummyRE        = re.compile (r'edm::Wrapper<dummyType>')
0046     noEdmWrapperRE = re.compile (r"'ROOT' has no attribute 'edm::Wrapper")
0047     uint32RE       = re.compile (r"Config file parser error 'operatoruint32_t")
0048     nonSpacesRE    = re.compile (r'\S')
0049     problemDict = { 'labelDict'    : labelErrorRE,
0050                     'missingLabel' : missingLabelRE,
0051                     'terminate'    : terminatedRE,
0052                     'uint32'       : uint32RE,
0053                     'cppException' : cppExceptionRE,
0054                     'missingCfg'   : missingCfgRE,
0055                     'noEdmWrapper' : noEdmWrapperRE,
0056                     'dummy'        : dummyRE,
0057                     'operator'     : re.compile (r"onfig file parser error 'operator"),
0058                     'useless'      : re.compile (r'no member functions that are useful'),
0059                     'lazy'         : re.compile (r': Assertion'),
0060                     'detset'       : re.compile (r"AttributeError: 'edm::DetSet"),
0061                     'doubleint'    : re.compile (r'AttributeError: (int|double)'),
0062                     'finish'       : finishRE}
0063 
0064     parser = optparse.OptionParser ("Usage: %prog logfilePrefix [directory]")
0065     parser.add_option ("--counts", dest="counts",
0066                        action="store_true", default=False,
0067                        help="Display counts only.")
0068     parser.add_option ('--mismatch', dest='mismatch',
0069                        action='store_true',
0070                        help='Displays only mismatch output')
0071     parser.add_option ("--diffTree", dest="diffTree",
0072                        action="store_true", default=False,
0073                        help="Shows diffTree printout.")
0074     parser.add_option ('--makeCompRoot', dest='makeCompRoot',
0075                        action='store_true',
0076                        help='Prints commands to make compRoot files for difftree')
0077     parser.add_option ("--problem", dest="problem", type='string',
0078                        help="Displays problems matching PROBLEM")
0079 
0080     options, args = parser.parse_args()
0081     if not 1 <= len (args) <= 2:
0082         raise RuntimeError("Must give directory and log file prefix")
0083     logfilePrefix = percentRE.sub ('*', args[0])
0084     if logfilePrefix[-1] != '*':
0085         logfilePrefix += '*'
0086     cwd = os.getcwd()
0087     logdir = ''
0088     if len (args) == 2:
0089         logdir = args[1]
0090         os.chdir (logdir)
0091     files        = glob (logfilePrefix)
0092     if logdir:
0093         oldFiles = files
0094         files = []
0095         for filename in oldFiles:
0096             files.append (logdir + '/' + filename)
0097         os.chdir (cwd)
0098     totalFiles   = len (files)
0099     problems     = {}
0100     succeeded    = 0
0101     weird        = 0
0102     problemTypes = {}
0103     successes    = {}
0104     objectName   = ''
0105     compRoot     = ''
0106     soName       = ''
0107     command      = ''
0108     diffOutput   = {}
0109     goShlib      = ''
0110     for log in files:
0111         problemSet = set()
0112         source = open (log, 'r')
0113         ran = False
0114         success = False
0115         reading = False
0116         summaryLines = ''
0117         for line in source:
0118             line = line.rstrip('\n')
0119             match = edmCommandRE.search (line)
0120             if match:
0121                 command = match.group(1)
0122             match = loadingSoRE.search (line)
0123             if match:
0124                 goShlib = match.group(1)                
0125             match = creatingSoRE.search (line)
0126             if match:
0127                 goShlib = match.group(1)                
0128             if options.diffTree:
0129                 match = descriptionRE.search (line)
0130                 if match:
0131                     objectName = match.group(1)
0132                 match = compRootRE.search (line)
0133                 if match:
0134                     compRoot = match.group(1)
0135                 match = loadingSoRE.search (line)
0136                 if match:
0137                     soName = match.group(1)
0138             if reading:
0139                 if not nonSpacesRE.search(line):
0140                     reading = False
0141                     continue
0142                 summaryLines += line
0143             if startOutputRE.search(line):
0144                 ran     = True
0145                 reading = True
0146                 continue
0147             if success1RE.search (line) or success2RE.search(line):
0148                 success = True
0149                 continue
0150             for key, regex in problemDict.items():
0151                 #print "considering %s for %s" % (key, line)
0152                 if regex.search(line):
0153                     if key in problemSet:
0154                         continue
0155                     problemSet.add (key)
0156                     problems.setdefault(log,[]).append(key)
0157                     if key not in problemTypes:
0158                         problemTypes[key] = 1
0159                     else:
0160                         problemTypes[key] += 1
0161             key = ''
0162         source.close()
0163         
0164         if summaryLines:
0165             summary = eval (summaryLines)
0166             ok = summaryOK (summary)
0167         else:
0168             ok = (False,)
0169             summary = None
0170         if ran and success:
0171             succeeded += 1
0172             if not ok[0]:
0173                 weird += 1
0174             else:
0175                 successes[log] = pprint.pformat (summary, indent=4)
0176         else:
0177             if ok[0]:
0178                 weird += 1
0179         if log not in problems and not ok[0]:
0180             if not ok[0] and summary:
0181                 key = 'mismatch'                
0182                 problems[log] = pprint.pformat (summary, indent=4)
0183                 #pprint.pprint (summary, indent=4)
0184                 if objectName and compRoot and soName:
0185                     # do the diffTree magic
0186                     varNames = summary.get(objectName, {}).\
0187                                get('_var', {}).keys()
0188                     variables = ['eta', 'phi']
0189                     for var in sorted (varNames):
0190                         if var not in variables and var not in avoid:
0191                             variables.append (var)
0192                     diffCmd = 'diffTreeTool.py --skipUndefined %s %s %s' \
0193                               % (compRoot, soName, " ".join(variables))
0194                     # print diffCmd
0195                     diffOutput[log] = diffCmd
0196             else:
0197                 problems[log] = ['other','ran:%s' % ran,
0198                                   'success:%s' % success]
0199                 key = 'other'
0200             if key not in problemTypes:
0201                 problemTypes[key] = 1
0202             else:
0203                 problemTypes[key] += 1
0204     mismatches = problemTypes.get('mismatch', 0)
0205     if 'mismatch' in problemTypes:
0206         del problemTypes['mismatch']
0207     print("total:      ", len (files))
0208     print("success:    ", succeeded)
0209     print("mismatches: ", mismatches)
0210     print("weird:      ", weird)
0211     print("Tool issue types:")
0212     total = 0
0213     for key, value in sorted (problemTypes.items()):
0214         print("  %-15s: %4d" % (key, value))
0215         total += value
0216     print(" ", '-'*13, " : ----")
0217     print("  %-15s: %4d + %d + %d + %d = %d" \
0218           % ('total', total, succeeded, mismatches, weird,
0219              total + succeeded + mismatches + weird))
0220     
0221     if not options.counts:
0222         print("\nDetailed Problems list:")
0223         for key, problemList in sorted (problems.items()):
0224             if options.problem and problemList[0] != options.problem:
0225                 continue
0226             if options.mismatch and not isinstance (problemList, str):
0227                 continue
0228             #if options.mismatch and 
0229             print("   %s:\n   %s\n" % (key, problemList))
0230             if options.mismatch and goShlib and compRoot:
0231                 print("diffTree %s %s" % (goShlib, compRoot))
0232             diffCmd = diffOutput.get(key)
0233             if diffCmd:                
0234                 print(subprocess.getoutput (diffCmd))
0235         if not options.problem and not options.mismatch:
0236             print("\n", '='*78, '\n')
0237             print("Success list:")
0238             for key, successesList in sorted (successes.items()):
0239                 print("   %s:\n   %s\n" % (key, successesList))