CMS 3D CMS Logo

Classes | Functions

cmsPerfSuite Namespace Reference

Classes

class  PerfSuite
class  PerfSuiteTimer
class  PerfThread

Functions

def _cleanup
def main

Function Documentation

def cmsPerfSuite::_cleanup ( ) [private]

Definition at line 15 of file cmsPerfSuite.py.

00016               :
00017    pass
00018 #Override the function in subprocess
00019 subprocess._cleanup=_cleanup

def cmsPerfSuite::main (   argv = [__name__])

Definition at line 1728 of file cmsPerfSuite.py.

01728                          : #argv is a list of arguments.
01729                      #Valid ways to call main with arguments:
01730                      #main(["--cmsScimark",10])
01731                      #main(["-t100"]) #With the caveat that the options.timeSize will be of type string... so should avoid using this!
01732                      #main(["-timeSize,100])
01733                      #Invalid ways:
01734                      #main(["One string with all options"])
01735     
01736     #Let's instatiate the class:
01737     suite=PerfSuite()
01738 
01739     #print suite
01740     #Uncomment this for tests with main() in inteactive python:
01741     #print suite.optionParse(argv)
01742     
01743     PerfSuiteArgs={}
01744     (PerfSuiteArgs['create'],
01745      PerfSuiteArgs['castordir'],
01746      PerfSuiteArgs['TimeSizeEvents'],
01747      PerfSuiteArgs['IgProfEvents'],    
01748      PerfSuiteArgs['CallgrindEvents'],
01749      PerfSuiteArgs['MemcheckEvents'],
01750      PerfSuiteArgs['cmsScimark'],      
01751      PerfSuiteArgs['cmsScimarkLarge'], 
01752      PerfSuiteArgs['cmsdriverOptions'],
01753      PerfSuiteArgs['cmsdriverPUOptions'],
01754      PerfSuiteArgs['stepOptions'],     
01755      PerfSuiteArgs['quicktest'],       
01756      PerfSuiteArgs['profilers'],       
01757      PerfSuiteArgs['cpus'],            
01758      PerfSuiteArgs['cores'],           
01759      PerfSuiteArgs['prevrel'],         
01760      PerfSuiteArgs['bypasshlt'],       
01761      PerfSuiteArgs['runonspare'],      
01762      PerfSuiteArgs['perfsuitedir'],    
01763      PerfSuiteArgs['logfile'],
01764      PerfSuiteArgs['TimeSizeCandles'],
01765      PerfSuiteArgs['IgProfCandles'],
01766      PerfSuiteArgs['CallgrindCandles'],
01767      PerfSuiteArgs['MemcheckCandles'],
01768      PerfSuiteArgs['TimeSizePUCandles'],
01769      PerfSuiteArgs['IgProfPUCandles'],
01770      PerfSuiteArgs['CallgrindPUCandles'],
01771      PerfSuiteArgs['MemcheckPUCandles'],
01772      PerfSuiteArgs['PUInputFile'],
01773      PerfSuiteArgs['userInputFile'],
01774      PerfSuiteArgs['MailLogRecipients'],
01775      PerfSuiteArgs['tarball']
01776      ) = suite.optionParse(argv)
01777 
01778     if PerfSuiteArgs['create']: # Before anything, request the AFS volume (it takes some time...)
01779        suite.createIgVolume()
01780 
01781     if not PerfSuiteArgs['logfile'] == None:
01782        if os.path.exists(PerfSuiteArgs['logfile']):
01783           oldlogfile=PerfSuiteArgs['logfile']+"_"+time.strftime("%d-%m-%Y_%H:%M:%S")
01784           #Move old logfile to a file with the same filename plus a timestamp appended
01785           mvOldLogfile=subprocess.Popen("mv %s %s"%(PerfSuiteArgs['logfile'],oldlogfile), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
01786           mvOldLogfileExitCode=mvOldLogfile.wait()
01787           #Finally open the logfile and put the information above in it:
01788           try:
01789              ActualLogfile = open(PerfSuiteArgs['logfile'],"w")
01790              if mvOldLogfileExitCode:
01791                 ActualLogfile.write("Please check what happened: A file named %s existed already and the attempt to move it to %s produced the following output: %s\n"%(PerfSuiteArgs['logfile'],oldlogfile,mvOldLogfile.stdout))
01792              else:
01793                 ActualLogfile.write("***WARNING! A file named %s existed already!\n***It has been moved to %s before starting the current logfile!\n"%(PerfSuiteArgs['logfile'],oldlogfile))
01794           except (OSError, IOError), detail:
01795              ActualLogfile.write("Failed to open the intended logfile %s, detail error:\n%s"%(PerfSuiteArgs['logfile'],detail))
01796               
01797        else:
01798           try:
01799              ActualLogfile = open(PerfSuiteArgs['logfile'],"w")
01800           except (OSError, IOError), detail:
01801              ActualLogfile.write("Failed to open the intended logfile %s, detail error:\n%s"%(PerfSuiteArgs['logfile'],detail))
01802        ActualLogfile.flush()
01803                  
01804     #Three lines to add the exact command line used to call the performance suite directly in the log.
01805     ActualLogfile.write("Performance suite invoked with command line:\n")
01806     cmdline=reduce(lambda x,y:x+" "+y,sys.argv)
01807     ActualLogfile.write(cmdline+"\n")
01808     ActualLogfile.flush()
01809     
01810     #Debug printout that we could silence...
01811     ActualLogfile.write("Initial PerfSuite Arguments:\n")
01812     for key in PerfSuiteArgs.keys():
01813         ActualLogfile.write("%s %s\n"%(key,PerfSuiteArgs[key]))
01814     ActualLogfile.flush()
01815     #print PerfSuiteArgs
01816 
01817     PerfSuiteArgs['cpu_list'] = PerfSuiteArgs['cpus'] #To access the actual number of cpus used inside the threads..
01818 
01819     #Handle in here the case of multiple cores and the loading of cores with cmsScimark:
01820     if len(PerfSuiteArgs['cpus']) > 1:
01821         ActualLogfile.write("More than 1 cpu: threading the Performance Suite!\n")
01822         outputdir=PerfSuiteArgs['perfsuitedir']
01823         runonspare=PerfSuiteArgs['runonspare'] #Save the original value of runonspare for cmsScimark stuff
01824         cpus=PerfSuiteArgs['cpus']
01825         cores=PerfSuiteArgs['cores']
01826         if runonspare:
01827             for core in range(PerfSuiteArgs['cores']):
01828                 cmsScimarkLaunch_pslist={}
01829                 if len(cpus) != cores: #In case of this (relval), don't load the others with cmsScimark
01830                    if (core not in cpus):
01831                       #self.logh.write("Submitting cmsScimarkLaunch.csh to run on core cpu "+str(core) + "\n")
01832                       ActualLogfile.write("Submitting cmsScimarkLaunch.csh to run on core cpu "+str(core)+"\n")
01833                       subcmd = "cd %s ; cmsScimarkLaunch.csh %s" % (outputdir, str(core))            
01834                       command="taskset -c %s sh -c \"%s\" &" % (str(core), subcmd)
01835                       #self.logh.write(command + "\n")
01836                       ActualLogfile.write(command+"\n")
01837                       #cmsScimarkLaunch.csh is an infinite loop to spawn cmsScimark2 on the other
01838                       #cpus so it makes no sense to try reading its stdout/err
01839                       cmsScimarkLaunch_pslist[core]=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
01840                       ActualLogfile.write("Spawned %s \n with PID %s"%(command,cmsScimarkLaunch_pslist[core].pid))
01841                       ActualLogfile.flush()
01842         PerfSuiteArgs['runonspare']=False #Set it to false to avoid cmsScimark being spawned by each thread
01843         logfile=PerfSuiteArgs['logfile']
01844         suitethread={}
01845         for cpu in cpus:
01846             #Make arguments "threaded" by setting for each instance of the suite:
01847             #1-A different output (sub)directory
01848             #2-Only 1 core on which to run
01849             #3-Automatically have a logfile... otherwise stdout is lost?
01850             #To be done:[3-A flag for Valgrind not to "thread" itself onto the other cores..]
01851             cpudir = os.path.join(outputdir,"cpu_%s" % cpu)
01852             if not os.path.exists(cpudir):
01853                 os.mkdir(cpudir)
01854             PerfSuiteArgs['perfsuitedir']=cpudir
01855             PerfSuiteArgs['cpus']=[cpu]  #Keeping the name cpus for now FIXME: change it to cpu in the whole code
01856             if PerfSuiteArgs['logfile']:
01857                 PerfSuiteArgs['logfile']=os.path.join(cpudir,os.path.basename(PerfSuiteArgs['logfile']))
01858             else:
01859                 PerfSuiteArgs['logfile']=os.path.join(cpudir,"cmsPerfSuiteThread.log")
01860             #Now spawn the thread with:
01861             suitethread[cpu]=PerfThread(**PerfSuiteArgs)
01862             #ActualLogfile.write(suitethread[cpu])
01863             ActualLogfile.write("Launching PerfSuite thread on cpu%s"%cpu)
01864             ActualLogfile.flush()
01865             #print "With arguments:"
01866             #print PerfSuiteArgs
01867             suitethread[cpu].start()
01868             
01869         while reduce(lambda x,y: x or y, map(lambda x: x.isAlive(),suitethread.values())):
01870            try:            
01871               time.sleep(5.0)
01872               sys.stdout.flush()
01873            except (KeyboardInterrupt, SystemExit):
01874               raise
01875         ActualLogfile.write("All PerfSuite threads have completed!\n")
01876         ActualLogfile.flush()
01877 
01878     else: #No threading, just run the performance suite on the cpu core selected
01879         suite.runPerfSuite(**PerfSuiteArgs)
01880