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