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