brunelWrapper.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 This script acts as a wrapper in order to generate Gaudi configs for running
5 with different parameters in order to perform performance measurements.
6 It takes command line arguments.
7 """
8 
9 import optparse
10 """
11 NumberOfEvents = 10
12 NumberOfEventsInFlight = 5
13 NumberOfAlgosInFlight = 5
14 NumberOfThreads = 10
15 CloneAlgos = False
16 DumpQueues = False
17 """
18 
20  usage="%prog [options]"
21  parser = optparse.OptionParser(usage)
22  parser.add_option('-n', help='Number of events', dest='nevts', default=15)
23  parser.add_option('--eif', help='Events in flight', dest='eif', default=5)
24  parser.add_option('--aif', help='Algos in flight', dest='aif', default=10)
25  parser.add_option('--nthreads', help='Number of threads', dest='nthreads', default=10)
26  parser.add_option('--clone', help='Clone Algos',dest='clone', action='store_true', default=False)
27  parser.add_option('--dumpQueues', help='Dump Queues',dest='dumpqueues', action='store_true', default=False)
28  parser.add_option('-v', help='Verbosity level', dest='verbosity', default=5)
29  parser.add_option('--exec', help='ExecuteWorkflow',dest='execbrunel', action='store_true', default=False)
30  parser.add_option('--bg', help='Launch in background',dest='bg', action='store_true', default=False)
31  parser.add_option('--scale', help='Scale Algorithms time',dest='scale', default=1)
32  options,args = parser.parse_args()
33  return options
34 
35 
36 def replaceValues(cfg_name,n,eif,aif,nthreads,scale,clone,dumpQueues,verbosity):
37 
38  newcfglines=open(cfg_name,"r").readlines()
39  cfg_name=cfg_name.replace(".py","")
40  verb=""
41  if verbosity!=6:
42  verb="_v%s"%verbosity
43  scale_s=""
44  if scale != 1:
45  scale_s="_s%s"%scale
46  newcfgname="measurement_%s_n%s_eif%s_aif%s_nthreads%s_c%s_dq%s%s%s.py" %(cfg_name,n,eif,aif,nthreads,clone,dumpQueues,scale_s,verb)
47  newcfg=open(newcfgname,"w")
48  for line in newcfglines:
49  if ('NumberOfEvents' in line and 'NUMBEROFEVENTS' in line and not "FLIGHT" in line):
50  line=line.replace("NUMBEROFEVENTS",str(n))
51  if ('NumberOfEventsInFlight' in line and 'NUMBEROFEVENTSINFLIGHT' in line):
52  line=line.replace("NUMBEROFEVENTSINFLIGHT",str(eif))
53  if ('NumberOfAlgosInFlight' in line and 'NUMBEROFALGOSINFLIGHT' in line):
54  line=line.replace("NUMBEROFALGOSINFLIGHT",str(aif))
55  if ('NumberOfThreads' in line and 'NUMBEROFTHREADS' in line):
56  line=line.replace("NUMBEROFTHREADS",str(nthreads))
57  if ('DumpQueues'in line and 'DUMPQUEUES' in line):
58  line=line.replace("DUMPQUEUES",str(dumpQueues))
59  if ('CloneAlgos'in line and 'CLONEALGOS' in line):
60  line=line.replace("CLONEALGOS",str(clone))
61  if ('Verbosity'in line and 'VERBOSITY' in line):
62  line=line.replace("VERBOSITY",str(verbosity))
63  if ('Scale'in line and 'SCALE' in line):
64  line=line.replace("SCALE",str(scale))
65  newcfg.write(line)
66  newcfg.close()
67  return newcfgname
68 
69 
70 if __name__ == "__main__":
71  options = createParser()
72  newcfg = replaceValues("BrunelScenario.py",
73  options.nevts,
74  options.eif,
75  options.aif,
76  options.nthreads,
77  float(options.scale),
78  options.clone,
79  options.dumpqueues,
80  options.verbosity)
81 
82  logfile = newcfg.replace(".py",".log")
83  gaudirun="`alias gaudirun`"
84  gaudirun = "/afs/cern.ch/user/d/dpiparo/Gaudi/build.x86_64-slc5-gcc46-opt/run gaudirun.py"
85  command = "/usr/bin/time -f %%S -o timing_%s %s %s >& %s " %(logfile, gaudirun, newcfg,logfile)
86  if options.bg:
87  command+=" &"
88 
89  print command
90  if options.execbrunel :
91  import os
92  os.system(command)
93 
94 
95 
def replaceValues(cfg_name, n, eif, aif, nthreads, scale, clone, dumpQueues, verbosity)
def createParser()