CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Validation/Performance/scripts/cmsPerfHarvest.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 from cmsPerfCommons import Candles, CandFname
00003 import optparse as opt
00004 import cmsPerfRegress as cpr
00005 import sys, os, glob, re
00006 
00007 _PROG_NAME = os.path.basename(sys.argv[0])
00008 
00009 ###################
00010 # Parse options 
00011 #
00012 def optionParse():
00013     parser = opt.OptionParser(usage="""./%s [perf dir] [options]""" % _PROG_NAME)
00014 
00015     (options, args) = parser.parse_args()
00016 
00017     if not len(args) == 1:
00018         parser.error("You have not supplied a perfsuite directory.")
00019         sys.exit()
00020 
00021     args[0] = os.path.abspath(args[0])
00022 
00023     ###########
00024     # Check existance of the directory supplied
00025     #
00026     if not os.path.isdir(args[0]):
00027         parser.error("You have not provided a valid perfsuite output directory")
00028         sys.exit()
00029 
00030     perfdir = args[0]
00031 
00032     return (perfdir)
00033 
00034 #################
00035 # Harvest information from a timesize directory, currently only retrieves TimingReport information
00036 #
00037 def visit_timesize_steps(candle,profsetdir):
00038     out = {}
00039     # Just do timing report for now
00040     globpath = os.path.join(profsetdir,"%s_*_TimingReport.log" % CandFname[candle])
00041     globs = glob.glob(globpath)
00042     if len(globs) > 0:
00043         stepreg = re.compile("%s_([^_]*)_TimingReport.log" % CandFname[candle])
00044         for globule in globs:
00045             base = os.path.basename(globule)
00046             found = stepreg.search(base)
00047             if found:
00048                 step = found.groups()[0]
00049                 try:
00050                     if step == None:
00051                         print "Error: could not resolve step something is wrong"
00052                         step = "None"
00053                     if not out.has_key("TimingReport"):
00054                         out["TimingReport"] = {}
00055                     stepdict = out["TimingReport"]
00056                     stepdict[step] = cpr.getTimingLogData(globule)
00057                     out["TimingReport"] = stepdict
00058                 except (OSError, IOError), detail:
00059                     print detail
00060             else:
00061                 print "Error: Could not determine step from %s" % base
00062     return out
00063 
00064 ###############
00065 # Retrieve data from a perf suite output (sub) directory, only examines TimeSize at the moment
00066 #
00067 def visit(visitdir):
00068     out = {}
00069     for candle in Candles:
00070         globpath = os.path.join(visitdir,"%s_*" % (candle))
00071         globs = glob.glob(globpath)
00072         if len(globs) > 0:
00073             profsetreg = re.compile("%s_(.*)" % candle)
00074             for globule in globs:
00075                 base = os.path.basename(globule)
00076                 found = profsetreg.search(base)
00077                 if found:
00078                     profset = found.groups()[0]
00079                     if profset == "TimeSize": # Just do timesize for now!
00080                         if candle == None:
00081                             print "Error: could not resolve candle something is wrong"
00082                             candle = "None"
00083                         if profset == None:
00084                             print "Error: could not resolve profset something is wrong"
00085                             profset = "None"
00086                         if not out.has_key(candle):
00087                             out[candle] = {}
00088                         candledict = out[candle]
00089                         if candledict.has_key(profset):
00090                             print "Error: we already have a profset that matches %s" % str(profset)
00091                         else:
00092                             candledict[profset] = visit_timesize_steps(candle,globule)
00093                             out[candle] = candledict
00094     return out
00095         
00096 ###############
00097 # Harvest all data from a perfsuite directory (if cpu subdirectories exist, it will examine them)
00098 #
00099 def harvest(perfdir):
00100     cpureg = re.compile("cpu_([0-9][0-9]*)")
00101     out = {}
00102     globpath = os.path.join(perfdir, "cpu_*")
00103     globs = glob.glob(globpath)
00104     if len(globs) > 0:
00105         for globule in globs:
00106             base  = os.path.basename(globule)
00107             found = cpureg.search(base)
00108             if found:
00109                 cpuid = found.groups()[0]
00110                 if out.has_key(cpuid):
00111                     print "Error: we already have a cpu run with this id %s ! Skipping..." % cpuid
00112                 else:
00113                     if cpuid == None:
00114                         print "Error: could not resolve cpuid something is wrong"
00115                         cpuid = "None"
00116                     out[cpuid] = visit(globule)                
00117             else:
00118                 print "Error: could not determine valid cpu id from %s ! Skipping..." % base
00119 
00120     else:
00121         out["None"] = visit(perfdir)
00122         
00123     return out  
00124 
00125 if __name__ == "__main__":
00126     (perfdir) = optionParse()
00127     print harvest(perfdir)