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 1699 of file cmsPerfSuite.py.

01699                          : #argv is a list of arguments.
01700                      #Valid ways to call main with arguments:
01701                      #main(["--cmsScimark",10])
01702                      #main(["-t100"]) #With the caveat that the options.timeSize will be of type string... so should avoid using this!
01703                      #main(["-timeSize,100])
01704                      #Invalid ways:
01705                      #main(["One string with all options"])
01706     
01707     #Let's instatiate the class:
01708     suite=PerfSuite()
01709 
01710     #print suite
01711     #Uncomment this for tests with main() in inteactive python:
01712     #print suite.optionParse(argv)
01713     
01714     PerfSuiteArgs={}
01715     (PerfSuiteArgs['castordir'],
01716      PerfSuiteArgs['TimeSizeEvents'],
01717      PerfSuiteArgs['IgProfEvents'],    
01718      PerfSuiteArgs['CallgrindEvents'],
01719      PerfSuiteArgs['MemcheckEvents'],
01720      PerfSuiteArgs['cmsScimark'],      
01721      PerfSuiteArgs['cmsScimarkLarge'], 
01722      PerfSuiteArgs['cmsdriverOptions'],
01723      PerfSuiteArgs['cmsdriverPUOptions'],
01724      PerfSuiteArgs['stepOptions'],     
01725      PerfSuiteArgs['quicktest'],       
01726      PerfSuiteArgs['profilers'],       
01727      PerfSuiteArgs['cpus'],            
01728      PerfSuiteArgs['cores'],           
01729      PerfSuiteArgs['prevrel'],         
01730      PerfSuiteArgs['bypasshlt'],       
01731      PerfSuiteArgs['runonspare'],      
01732      PerfSuiteArgs['perfsuitedir'],    
01733      PerfSuiteArgs['logfile'],
01734      PerfSuiteArgs['TimeSizeCandles'],
01735      PerfSuiteArgs['IgProfCandles'],
01736      PerfSuiteArgs['CallgrindCandles'],
01737      PerfSuiteArgs['MemcheckCandles'],
01738      PerfSuiteArgs['TimeSizePUCandles'],
01739      PerfSuiteArgs['IgProfPUCandles'],
01740      PerfSuiteArgs['CallgrindPUCandles'],
01741      PerfSuiteArgs['MemcheckPUCandles'],
01742      PerfSuiteArgs['PUInputFile'],
01743      PerfSuiteArgs['userInputFile'],
01744      PerfSuiteArgs['MailLogRecipients'],
01745      PerfSuiteArgs['tarball']
01746      ) = suite.optionParse(argv)
01747 
01748     if not PerfSuiteArgs['logfile'] == None:
01749        if os.path.exists(PerfSuiteArgs['logfile']):
01750           oldlogfile=PerfSuiteArgs['logfile']+"_"+time.strftime("%d-%m-%Y_%H:%M:%S")
01751           #Move old logfile to a file with the same filename plus a timestamp appended
01752           mvOldLogfile=subprocess.Popen("mv %s %s"%(PerfSuiteArgs['logfile'],oldlogfile), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
01753           mvOldLogfileExitCode=mvOldLogfile.wait()
01754           #Finally open the logfile and put the information above in it:
01755           try:
01756              ActualLogfile = open(PerfSuiteArgs['logfile'],"w")
01757              if mvOldLogfileExitCode:
01758                 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))
01759              else:
01760                 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))
01761           except (OSError, IOError), detail:
01762              ActualLogfile.write("Failed to open the intended logfile %s, detail error:\n%s"%(PerfSuiteArgs['logfile'],detail))
01763               
01764        else:
01765           try:
01766              ActualLogfile = open(PerfSuiteArgs['logfile'],"w")
01767           except (OSError, IOError), detail:
01768              ActualLogfile.write("Failed to open the intended logfile %s, detail error:\n%s"%(PerfSuiteArgs['logfile'],detail))
01769        ActualLogfile.flush()
01770                  
01771     #Three lines to add the exact command line used to call the performance suite directly in the log.
01772     ActualLogfile.write("Performance suite invoked with command line:\n")
01773     cmdline=reduce(lambda x,y:x+" "+y,sys.argv)
01774     ActualLogfile.write(cmdline+"\n")
01775     ActualLogfile.flush()
01776     
01777     #Debug printout that we could silence...
01778     ActualLogfile.write("Initial PerfSuite Arguments:\n")
01779     for key in PerfSuiteArgs.keys():
01780         ActualLogfile.write("%s %s\n"%(key,PerfSuiteArgs[key]))
01781     ActualLogfile.flush()
01782     #print PerfSuiteArgs
01783 
01784     #Handle in here the case of multiple cores and the loading of cores with cmsScimark:
01785     if len(PerfSuiteArgs['cpus']) > 1:
01786         ActualLogfile.write("More than 1 cpu: threading the Performance Suite!\n")
01787         outputdir=PerfSuiteArgs['perfsuitedir']
01788         runonspare=PerfSuiteArgs['runonspare'] #Save the original value of runonspare for cmsScimark stuff
01789         cpus=PerfSuiteArgs['cpus']
01790         if runonspare:
01791             for core in range(PerfSuiteArgs['cores']):
01792                 cmsScimarkLaunch_pslist={}
01793                 if (core not in cpus):
01794                     #self.logh.write("Submitting cmsScimarkLaunch.csh to run on core cpu "+str(core) + "\n")
01795                     ActualLogfile.write("Submitting cmsScimarkLaunch.csh to run on core cpu "+str(core)+"\n")
01796                     subcmd = "cd %s ; cmsScimarkLaunch.csh %s" % (outputdir, str(core))            
01797                     command="taskset -c %s sh -c \"%s\" &" % (str(core), subcmd)
01798                     #self.logh.write(command + "\n")
01799                     ActualLogfile.write(command+"\n")
01800                     #cmsScimarkLaunch.csh is an infinite loop to spawn cmsScimark2 on the other
01801                     #cpus so it makes no sense to try reading its stdout/err
01802                     cmsScimarkLaunch_pslist[core]=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
01803                     ActualLogfile.write("Spawned %s \n with PID %s"%(command,cmsScimarkLaunch_pslist[core].pid))
01804                     ActualLogfile.flush()
01805         PerfSuiteArgs['runonspare']=False #Set it to false to avoid cmsScimark being spawned by each thread
01806         logfile=PerfSuiteArgs['logfile']
01807         suitethread={}
01808         for cpu in cpus:
01809             #Make arguments "threaded" by setting for each instance of the suite:
01810             #1-A different output (sub)directory
01811             #2-Only 1 core on which to run
01812             #3-Automatically have a logfile... otherwise stdout is lost?
01813             #To be done:[3-A flag for Valgrind not to "thread" itself onto the other cores..]
01814             cpudir = os.path.join(outputdir,"cpu_%s" % cpu)
01815             if not os.path.exists(cpudir):
01816                 os.mkdir(cpudir)
01817             PerfSuiteArgs['perfsuitedir']=cpudir
01818             PerfSuiteArgs['cpus']=[cpu]  #Keeping the name cpus for now FIXME: change it to cpu in the whole code
01819             if PerfSuiteArgs['logfile']:
01820                 PerfSuiteArgs['logfile']=os.path.join(cpudir,os.path.basename(PerfSuiteArgs['logfile']))
01821             else:
01822                 PerfSuiteArgs['logfile']=os.path.join(cpudir,"cmsPerfSuiteThread.log")
01823             #Now spawn the thread with:
01824             suitethread[cpu]=PerfThread(**PerfSuiteArgs)
01825             ActualLogfile.write(suitethread[cpu])
01826             ActualLogfile.write("Launching PerfSuite thread on cpu%s"%cpu)
01827             ActualLogfile.flush()
01828             #print "With arguments:"
01829             #print PerfSuiteArgs
01830             suitethread[cpu].start()
01831             
01832         while reduce(lambda x,y: x or y, map(lambda x: x.isAlive(),suitethread.values())):
01833            try:            
01834               time.sleep(5.0)
01835               sys.stdout.flush()
01836            except (KeyboardInterrupt, SystemExit):
01837               raise
01838         ActualLogfile.write("All PerfSuite threads have completed!\n")
01839         ActualLogfile.flush()
01840 
01841     else: #No threading, just run the performance suite on the cpu core selected
01842         suite.runPerfSuite(**PerfSuiteArgs)
01843