Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:46

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