CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmsBenchmark.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 """
3 Usage: ./cmsBenchmark.py [options]
4 
5 Options:
6  --cpu=... specify the core on which to run the performance suite
7  --cores=... specify the number of cores of the machine (can be used with 0 to stop cmsScimark from running on the other cores)
8  -n ..., --numevts specify the number of events for each tests/each candle/each step
9  --candle=... specify the candle to run instead of all the 7 candles of the suite
10  --step=... specify the step to run instead of all steps of the suite
11  --repeat=... specify the number of times to re-run the whole suite
12  -h, --help show this help
13  -d show debugging information
14 
15 Legal entries for individual candles (--candle option):
16 HiggsZZ4LM190
17 MinBias
18 SingleElectronE1000
19 SingleMuMinusPt10
20 SinglePiMinusE1000
21 TTbar
22 QCD_80_120
23 
24 Legal entries for specific tests (--step option):
25 GEN
26 SIM
27 DIGI
28 L1
29 DIGI2RAW
30 HLT
31 RAW2DIGI
32 RECO
33 and combinations of steps like:
34 GEN-SIM
35 L1-DIGI2RAW-HLT
36 DIGI2RAW-RAW2DIGI
37 and sequences of steps or combinations of steps like:
38 GEN-SIM,DIGI,L1-DIGI2RAW-RAW2DIGI,RECO
39 Note: when the necessary pre-steps are omitted, cmsPerfSuite.py will take care of it.
40 
41 Examples:
42 ./cmsBenchmark.py
43  This will run with the default options --cpu=1, --cores=4, --numevts=100, --step=GEN-SIM,DIGI,RECO --repeat=1 (Note: all results will be reported in a directory called Run1).
44 OR
45 ./cmsBenchmark.py --cpu=2
46  This will run the test on core cpu2.
47 OR
48 ./cmsBenchmark.py --cpu=0,1 --cores=8 -n 200
49  This will run the suite with 200 events for all tests/candles/step, on cores cpu0 and cpu1 simulataneously, while running the cmsScimark benchmarks on the other 6 cores.
50 OR
51 ./cmsBenchmark.py --cores=8 --repeat=10 --candle QCD_80_120
52  This will run the performance tests only on candle QCD_80_120, running 100 evts for all steps, and it will repeat these tests 10 times, saving the results in 10 separate directories (each called RunN, with N=1,..,10) to check for systematic/statistical uncertainties. Note that by default --repeat=1, so all results will be in a directory called Run1.
53 OR
54 ./cmsBenchmark.py --step=GEN-SIM,DIGI,RECO
55  This will run the performance tests only for the steps "GEN,SIM" (at once), "DIGI" and "RECO" taking care of running the necessary intermediate steps to make sure all steps can be run.
56 
57 """
58 import os
59 #Get some environment variables to use
60 cmssw_base=os.environ["CMSSW_BASE"]
61 cmssw_release_base=os.environ["CMSSW_RELEASE_BASE"]
62 cmssw_version=os.environ["CMSSW_VERSION"]
63 host=os.environ["HOST"]
64 user=os.environ["USER"]
65 
66 #Performance suites script used:
67 Script="cmsPerfSuite.py"
68 
69 #Options handling
70 import getopt
71 import sys
72 
73 def usage():
74  print __doc__
75 
76 def main(argv):
77  #Some default values:
78  #Number of cpu cores on the machine
79  coresOption="4"
80  cores=" --cores=4"
81  #Cpu core(s) on which the suite is run:
82  cpuOption=(1) #not necessary to use tuple for single cpu, but for type consistency use ().
83  cpu=" --cpu=1"
84  #Number of events per test (per candle/per step):
85  numevtsOption="100"
86  numevts=" --timesize=100"
87  #default benchmark does not run igprof nor valgrind
88  igprofevts=" --igprof=0"
89  valgrindevts=" --valgrind=0"
90  #Default option for candle is "" since, usually all 7 candles of the suite will be run!
91  candleOption=""
92  candle=""
93  #Default option for step is ["GEN,SIM","DIGI","RECO"] since we don't need to profile all steps of the suite
94  stepOption="GEN-SIM,DIGI,RECO"
95  step=" --step="+stepOption
96  #Default option for repeat
97  repeatOption=1 #Use integer here since it will be used directly in the script
98  #Let's check the command line arguments
99  try:
100  opts, args = getopt.getopt(argv, "n:hd", ["cpu=","cores=","numevts=","candle=","step=","repeat=","help"])
101  except getopt.GetoptError:
102  print "This argument option is not accepted"
103  usage()
104  sys.exit(2)
105  for opt, arg in opts:
106  if opt in ("-h", "--help"):
107  usage()
108  sys.exit()
109  elif opt == '-d':
110  global _debug
111  _debug = 1
112  elif opt == "--cpu":
113  cpuOption=arg
114  cpus=cpuOption.split(",")
115  cpu=" --cpu="+cpuOption
116  elif opt == "--cores":
117  coresOption = arg
118  elif opt in ("-n", "--numevts"):
119  numevtsOption = arg
120  numevts=" --timesize="+arg
121  elif opt == "--candle":
122  candleOption = arg
123  candle=" --candle="+arg
124  elif opt == "--step":
125  stepOption = arg
126  steps=stepOption.split(",")
127  elif opt == "--repeat":
128  repeatOption = int(arg)
129  #Case with no arguments (using defaults)
130  if opts == []:
131  print "No arguments given, so DEFAULT test will be run:"
132  #Print a time stamp at the beginning:
133  import time
134  date=time.ctime()
135  path=os.path.abspath(".")
136  print "CMS Benchmarking started running at %s on %s in directory %s, run by user %s" % (date,host,path,user)
137  #showtags=os.popen4("showtags -r")[1].read()
138  #print showtags
139  #For the log:
140  print "This machine (%s) is assumed to have %s cores, and the suite will be run on cpu(s) %s" %(host,coresOption,cpuOption)
141  print "%s events per test will be run" % numevtsOption
142  if candleOption !="":
143  print "Running only %s candle, instead of all the candles in the performance suite" % candleOption
144  if stepOption != "":
145  print "Profiling only the following steps: %s" % stepOption
146  step=" --step="+stepOption
147  #This "unpacking" of the steps is better done in cmsPerfSuite.py or the cmsSimPyRelVal.py (.pl for now)
148  #steps=stepOption.split(",")
149  #cmsPerfSuiteSteps=[]
150  #for step in steps:
151  # newstep=reduce(lambda a,b:a+","+b,step.split("-"))
152  # cmsPerfSuiteSteps.append(newstep)
153  if repeatOption !=1:
154  print "The benchmarking will be repeated %s times" % repeatOption
155  #Now let's play!
156  for repetition in range(repeatOption):
157  mkdircdcmd="mkdir Run"+str(repetition+1)+";cd Run"+str(repetition+1)
158  #mkdircdstdout=os.popen4(mkdircmd)[1].read()
159  #if mkdirstdout:
160  # print mkdirstdout,
161  #print "Here we'd launch cmsPerfSuite.py!"
162  PerfSuitecmd="cmsPerfSuite.py" + cpu + cores + numevts + igprofevts + valgrindevts + candle + step + ">& cmsPerfSuiteRun" + str(repetition + 1) + ".log"
163  launchcmd=mkdircdcmd+";"+PerfSuitecmd
164  print launchcmd
165  sys.stdout.flush()
166  #Obsolete popen4-> subprocess.Popen
167  #launchcmdstdout=os.popen4(launchcmd)[1].read()
168  launchcmdstdout=Popen(launchcmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read()
169  print launchcmdstdout
170 
171 if __name__ == "__main__":
172  main(sys.argv[1:])
Definition: main.py:1