CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.

15 
16 def _cleanup():
17  pass
18 #Override the function in subprocess
19 subprocess._cleanup=_cleanup
def cmsPerfSuite.main (   argv = [__name__])

Definition at line 1699 of file cmsPerfSuite.py.

1700 def main(argv=[__name__]): #argv is a list of arguments.
1701  #Valid ways to call main with arguments:
1702  #main(["--cmsScimark",10])
1703  #main(["-t100"]) #With the caveat that the options.timeSize will be of type string... so should avoid using this!
1704  #main(["-timeSize,100])
1705  #Invalid ways:
1706  #main(["One string with all options"])
1707 
1708  #Let's instatiate the class:
1709  suite=PerfSuite()
1710 
1711  #print suite
1712  #Uncomment this for tests with main() in inteactive python:
1713  #print suite.optionParse(argv)
1714 
1715  PerfSuiteArgs={}
1716  (PerfSuiteArgs['castordir'],
1717  PerfSuiteArgs['TimeSizeEvents'],
1718  PerfSuiteArgs['IgProfEvents'],
1719  PerfSuiteArgs['CallgrindEvents'],
1720  PerfSuiteArgs['MemcheckEvents'],
1721  PerfSuiteArgs['cmsScimark'],
1722  PerfSuiteArgs['cmsScimarkLarge'],
1723  PerfSuiteArgs['cmsdriverOptions'],
1724  PerfSuiteArgs['cmsdriverPUOptions'],
1725  PerfSuiteArgs['stepOptions'],
1726  PerfSuiteArgs['quicktest'],
1727  PerfSuiteArgs['profilers'],
1728  PerfSuiteArgs['cpus'],
1729  PerfSuiteArgs['cores'],
1730  PerfSuiteArgs['prevrel'],
1731  PerfSuiteArgs['bypasshlt'],
1732  PerfSuiteArgs['runonspare'],
1733  PerfSuiteArgs['perfsuitedir'],
1734  PerfSuiteArgs['logfile'],
1735  PerfSuiteArgs['TimeSizeCandles'],
1736  PerfSuiteArgs['IgProfCandles'],
1737  PerfSuiteArgs['CallgrindCandles'],
1738  PerfSuiteArgs['MemcheckCandles'],
1739  PerfSuiteArgs['TimeSizePUCandles'],
1740  PerfSuiteArgs['IgProfPUCandles'],
1741  PerfSuiteArgs['CallgrindPUCandles'],
1742  PerfSuiteArgs['MemcheckPUCandles'],
1743  PerfSuiteArgs['PUInputFile'],
1744  PerfSuiteArgs['userInputFile'],
1745  PerfSuiteArgs['MailLogRecipients'],
1746  PerfSuiteArgs['tarball']
1747  ) = suite.optionParse(argv)
1748 
1749  if not PerfSuiteArgs['logfile'] == None:
1750  if os.path.exists(PerfSuiteArgs['logfile']):
1751  oldlogfile=PerfSuiteArgs['logfile']+"_"+time.strftime("%d-%m-%Y_%H:%M:%S")
1752  #Move old logfile to a file with the same filename plus a timestamp appended
1753  mvOldLogfile=subprocess.Popen("mv %s %s"%(PerfSuiteArgs['logfile'],oldlogfile), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
1754  mvOldLogfileExitCode=mvOldLogfile.wait()
1755  #Finally open the logfile and put the information above in it:
1756  try:
1757  ActualLogfile = open(PerfSuiteArgs['logfile'],"w")
1758  if mvOldLogfileExitCode:
1759  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))
1760  else:
1761  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))
1762  except (OSError, IOError), detail:
1763  ActualLogfile.write("Failed to open the intended logfile %s, detail error:\n%s"%(PerfSuiteArgs['logfile'],detail))
1764 
1765  else:
1766  try:
1767  ActualLogfile = open(PerfSuiteArgs['logfile'],"w")
1768  except (OSError, IOError), detail:
1769  ActualLogfile.write("Failed to open the intended logfile %s, detail error:\n%s"%(PerfSuiteArgs['logfile'],detail))
1770  ActualLogfile.flush()
1771 
1772  #Three lines to add the exact command line used to call the performance suite directly in the log.
1773  ActualLogfile.write("Performance suite invoked with command line:\n")
1774  cmdline=reduce(lambda x,y:x+" "+y,sys.argv)
1775  ActualLogfile.write(cmdline+"\n")
1776  ActualLogfile.flush()
1777 
1778  #Debug printout that we could silence...
1779  ActualLogfile.write("Initial PerfSuite Arguments:\n")
1780  for key in PerfSuiteArgs.keys():
1781  ActualLogfile.write("%s %s\n"%(key,PerfSuiteArgs[key]))
1782  ActualLogfile.flush()
1783  #print PerfSuiteArgs
1784 
1785  #Handle in here the case of multiple cores and the loading of cores with cmsScimark:
1786  if len(PerfSuiteArgs['cpus']) > 1:
1787  ActualLogfile.write("More than 1 cpu: threading the Performance Suite!\n")
1788  outputdir=PerfSuiteArgs['perfsuitedir']
1789  runonspare=PerfSuiteArgs['runonspare'] #Save the original value of runonspare for cmsScimark stuff
1790  cpus=PerfSuiteArgs['cpus']
1791  if runonspare:
1792  for core in range(PerfSuiteArgs['cores']):
1793  cmsScimarkLaunch_pslist={}
1794  if (core not in cpus):
1795  #self.logh.write("Submitting cmsScimarkLaunch.csh to run on core cpu "+str(core) + "\n")
1796  ActualLogfile.write("Submitting cmsScimarkLaunch.csh to run on core cpu "+str(core)+"\n")
1797  subcmd = "cd %s ; cmsScimarkLaunch.csh %s" % (outputdir, str(core))
1798  command="taskset -c %s sh -c \"%s\" &" % (str(core), subcmd)
1799  #self.logh.write(command + "\n")
1800  ActualLogfile.write(command+"\n")
1801  #cmsScimarkLaunch.csh is an infinite loop to spawn cmsScimark2 on the other
1802  #cpus so it makes no sense to try reading its stdout/err
1803  cmsScimarkLaunch_pslist[core]=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
1804  ActualLogfile.write("Spawned %s \n with PID %s"%(command,cmsScimarkLaunch_pslist[core].pid))
1805  ActualLogfile.flush()
1806  PerfSuiteArgs['runonspare']=False #Set it to false to avoid cmsScimark being spawned by each thread
1807  logfile=PerfSuiteArgs['logfile']
1808  suitethread={}
1809  for cpu in cpus:
1810  #Make arguments "threaded" by setting for each instance of the suite:
1811  #1-A different output (sub)directory
1812  #2-Only 1 core on which to run
1813  #3-Automatically have a logfile... otherwise stdout is lost?
1814  #To be done:[3-A flag for Valgrind not to "thread" itself onto the other cores..]
1815  cpudir = os.path.join(outputdir,"cpu_%s" % cpu)
1816  if not os.path.exists(cpudir):
1817  os.mkdir(cpudir)
1818  PerfSuiteArgs['perfsuitedir']=cpudir
1819  PerfSuiteArgs['cpus']=[cpu] #Keeping the name cpus for now FIXME: change it to cpu in the whole code
1820  if PerfSuiteArgs['logfile']:
1821  PerfSuiteArgs['logfile']=os.path.join(cpudir,os.path.basename(PerfSuiteArgs['logfile']))
1822  else:
1823  PerfSuiteArgs['logfile']=os.path.join(cpudir,"cmsPerfSuiteThread.log")
1824  #Now spawn the thread with:
1825  suitethread[cpu]=PerfThread(**PerfSuiteArgs)
1826  ActualLogfile.write(suitethread[cpu])
1827  ActualLogfile.write("Launching PerfSuite thread on cpu%s"%cpu)
1828  ActualLogfile.flush()
1829  #print "With arguments:"
1830  #print PerfSuiteArgs
1831  suitethread[cpu].start()
1832 
1833  while reduce(lambda x,y: x or y, map(lambda x: x.isAlive(),suitethread.values())):
1834  try:
1835  time.sleep(5.0)
1836  sys.stdout.flush()
1837  except (KeyboardInterrupt, SystemExit):
1838  raise
1839  ActualLogfile.write("All PerfSuite threads have completed!\n")
1840  ActualLogfile.flush()
1841 
1842  else: #No threading, just run the performance suite on the cpu core selected
1843  suite.runPerfSuite(**PerfSuiteArgs)
Definition: start.py:1