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