CMS 3D CMS Logo

Functions | Variables
cmsPerfServer Namespace Reference

Functions

def _main ()
 
def getCPSkeyword (key, dict)
 
def optionparse ()
 
def readlog (logfile)
 
def request_benchmark (cmds)
 
def runserv (port)
 

Variables

 _CASTOR_DIR
 
 _DEFAULTS
 
 _logreturn
 
 _outputdir
 
 _PROG_NAME
 
 _reqnumber
 
 CandlesString
 

Function Documentation

def cmsPerfServer._main ( )
private

Definition at line 283 of file cmsPerfServer.py.

References optionparse(), edm.print(), and runserv().

283 def _main():
284  print(_DEFAULTS)
285  (port, outputdir) = optionparse()
286  server_thread = threading.Thread(target = runserv(port))
287  server_thread.setDaemon(True) # Allow process to finish if this is the only remaining thread
288  server_thread.start()
289 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def runserv(port)
def cmsPerfServer.getCPSkeyword (   key,
  dict 
)

Definition at line 149 of file cmsPerfServer.py.

Referenced by request_benchmark().

149 def getCPSkeyword(key,dict):
150  if key in dict:
151  return dict[key]
152  else:
153  return _DEFAULTS[key]
154 
155 
def getCPSkeyword(key, dict)
def cmsPerfServer.optionparse ( )

Definition at line 51 of file cmsPerfServer.py.

Referenced by _main().

52  global _outputdir
53  parser = opt.OptionParser(usage=("""%s [Options]""" % _PROG_NAME))
54 
55  parser.add_option('-p',
56  '--port',
57  type="int",
58  dest='port',
59  default=8000, #Setting the default port to be 8000
60  help='Run server on a particular port',
61  metavar='<PORT>',
62  )
63 
64  parser.add_option('-o',
65  '--output',
66  type="string",
67  dest='outputdir',
68  default="",
69  help='The output directory for all the cmsPerfSuite runs',
70  metavar='<DIR>',
71  )
72 
73  (options, args) = parser.parse_args()
74 
75  if not options.outputdir == "":
76  options.outputdir = os.path.abspath(options.outputdir)
77  if not os.path.exists(options.outputdir):
78  parser.error("the specified output directory %s does not exist" % options.outputdir)
79  sys.exit()
80  #This seems misleading naming _DEFAULTS, while we are re-initializing its keys to different values as we go...
81  _DEFAULTS["perfsuitedir"] = options.outputdir
82 
83  #resetting global variable _outputdir too... do we really need this variable?
84  _outputdir = options.outputdir
85 
86  return (options.port,options.outputdir)
87 
88 #class ClientThread(threading.Thread):
89  # Overloading the constructor to accept cmsPerfSuite parameters
90 
91 
def cmsPerfServer.readlog (   logfile)

Definition at line 140 of file cmsPerfServer.py.

References edm.print().

Referenced by request_benchmark().

140 def readlog(logfile):
141  astr = ""
142  try:
143  for line in open(logfile,"r"):
144  astr += line
145  except (OSError, IOError) as detail:
146  print(detail)
147  return astr
148 
def readlog(logfile)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def cmsPerfServer.request_benchmark (   cmds)

Definition at line 156 of file cmsPerfServer.py.

References cmsCpuInfo.get_NumOfCores(), getCPSkeyword(), edm.print(), readlog(), and str.

157  #This is the function with which the server listens on the given port
158  #cmds is a list of dictionaries: each dictionary is a set of cmsPerfSuite commands to run.
159  #Most common use will be only 1 dictionary, but for testing with reproducibility and statistical errors
160  #one can easily think of sending the same command 10 times for example and then compare the outputs
161  global _outputdir, _reqnumber
162  print("Commands received running perfsuite for these jobs:")
163  print(cmds)
164  sys.stdout.flush()
165  try:
166  # input is a list of dictionaries each defining the
167  # keywords to cmsperfsuite
168  outs = []
169  cmd_num = 0
170  exists = True
171  #Funky way to make sure we create a directory request_n with n = serial request number (if the server is running for a while
172  #and the client submits more than one request
173  #This should never happen since _reqnumber is a global variable on the server side...
174  while exists:
175  topdir = os.path.join(_outputdir,"request_" + str(_reqnumber))
176  exists = os.path.exists(topdir)
177  _reqnumber += 1
178  os.mkdir(topdir)
179  #Going through each command dictionary in the cmds list (usually only 1 such dictionary):
180  for cmd in cmds:
181  curperfdir = os.path.abspath(os.path.join(topdir,str(cmd_num)))
182  if not os.path.exists(curperfdir):
183  os.mkdir(curperfdir)
184  logfile = os.path.join(curperfdir, "cmsPerfSuite.log")
185  if os.path.exists(logfile):
186  logfile = logfile + str(cmd_num)
187  print(cmd)
188  if 'cpus' in cmd:
189  if cmd['cpus'] == "All":
190  print("Running performance suite on all CPUS!\n")
191  cmd['cpus']=""
192  for cpu in range(cmsCpuInfo.get_NumOfCores()):
193  cmd["cpus"]=cmd["cpus"]+str(cpu)+","
194  cmd["cpus"]=cmd["cpus"][:-1] #eliminate the last comma for cleanliness
195  print("I.e. on cpus %s\n"%cmd["cpus"])
196 
197  #Not sure this is the most elegant solution... we keep cloning dictionaries...
198  cmdwdefs = {}
199  cmdwdefs["castordir" ] = getCPSkeyword("castordir" , cmd)
200  cmdwdefs["perfsuitedir" ] = curperfdir
201  cmdwdefs["TimeSizeEvents" ] = getCPSkeyword("TimeSizeEvents" , cmd)
202  cmdwdefs["TimeSizeCandles" ] = getCPSkeyword("TimeSizeCandles" , cmd)
203  cmdwdefs["TimeSizePUCandles" ] = getCPSkeyword("TimeSizePUCandles" , cmd)
204  cmdwdefs["IgProfEvents" ] = getCPSkeyword("IgProfEvents" , cmd)
205  cmdwdefs["IgProfCandles" ] = getCPSkeyword("IgProfCandles" , cmd)
206  cmdwdefs["IgProfPUCandles" ] = getCPSkeyword("IgProfPUCandles" , cmd)
207  cmdwdefs["CallgrindEvents" ] = getCPSkeyword("CallgrindEvents" , cmd)
208  cmdwdefs["CallgrindCandles"] = getCPSkeyword("CallgrindCandles" , cmd)
209  cmdwdefs["CallgrindPUCandles"] = getCPSkeyword("CallgrindPUCandles" , cmd)
210  cmdwdefs["MemcheckEvents" ] = getCPSkeyword("MemcheckEvents" , cmd)
211  cmdwdefs["MemcheckCandles" ] = getCPSkeyword("MemcheckCandles" , cmd)
212  cmdwdefs["MemcheckPUCandles" ] = getCPSkeyword("MemcheckPUCandles" , cmd)
213  cmdwdefs["cmsScimark" ] = getCPSkeyword("cmsScimark" , cmd)
214  cmdwdefs["cmsScimarkLarge" ] = getCPSkeyword("cmsScimarkLarge" , cmd)
215  cmdwdefs["cmsdriverOptions"] = getCPSkeyword("cmsdriverOptions", cmd)
216  cmdwdefs["stepOptions" ] = getCPSkeyword("stepOptions" , cmd)
217  cmdwdefs["quicktest" ] = getCPSkeyword("quicktest" , cmd)
218  cmdwdefs["profilers" ] = getCPSkeyword("profilers" , cmd)
219  cmdwdefs["cpus" ] = getCPSkeyword("cpus" , cmd)
220  cmdwdefs["cores" ] = getCPSkeyword("cores" , cmd)
221  cmdwdefs["prevrel" ] = getCPSkeyword("prevrel" , cmd)
222 # cmdwdefs["candles" ] = getCPSkeyword("candles" , cmd)
223 # cmdwdefs["isAllCandles" ] = len(Candles) == len(cmdwdefs["candles"]) #Dangerous: in the _DEFAULTS version this is a boolean!
224  cmdwdefs["bypasshlt" ] = getCPSkeyword("bypasshlt" , cmd)
225  cmdwdefs["runonspare" ] = getCPSkeyword("runonspare" , cmd)
226  cmdwdefs["logfile" ] = logfile
227  logh = open(logfile,"w")
228  logh.write("This perfsuite run was configured with the following options:\n")
229  #logh.write(str(cmdwdefs) + "\n")
230  for key in cmdwdefs.keys():
231  logh.write(key + "\t" +str(cmdwdefs[key])+"\n")
232  logh.close()
233  print("Calling cmsPerfSuite.main() function\n")
234  cpsInputArgs=[
235  #"-a",cmdwdefs["castordir"],
236  "-t",cmdwdefs["TimeSizeEvents" ],
237  "--RunTimeSize",cmdwdefs["TimeSizeCandles"],
238  "-o",cmdwdefs["perfsuitedir" ],
239  #"-i",cmdwdefs["IgProfEvents" ],
240  #"--RunIgProf",cmdwdefs["RunIgProf" ],
241  #"-c",cmdwdefs["CallgrindEvents" ],
242  #"--RunCallgrind",cmdwdefs["RunCallgrind" ],
243  #"-m",cmdwdefs["MemcheckEvents"],
244  #"--RunMemcheck",cmdwdefs["RunMemcheck"],
245  "--cmsScimark",cmdwdefs["cmsScimark" ],
246  "--cmsScimarkLarge",cmdwdefs["cmsScimarkLarge" ],
247  "--cmsdriver",cmdwdefs["cmsdriverOptions"],
248  "--step",cmdwdefs["stepOptions" ],
249  #"--quicktest",cmdwdefs["quicktest" ],
250  #"--profile",cmdwdefs["profilers" ],
251  "--cpu",cmdwdefs["cpus" ],
252  "--cores",cmdwdefs["cores" ],
253  #"--prevrel",cmdwdefs["prevrel" ],
254  # "--candle",cmdwdefs["candles" ],
255  #"--bypass-hlt",cmdwdefs["bypasshlt" ],
256  "--notrunspare"#,cmdwdefs["runonspare" ]#,
257  #"--logfile",cmdwdefs["logfile" ]
258  ]
259  print(cpsInputArgs)
260  cps.main(cpsInputArgs)
261  print("Running of the Performance Suite is done!")
262  #logreturn is false... so this does not get executed
263  #Maybe we can replace this so that we can have more verbose logging of the server activity
264  if _logreturn:
265  outs.append(readlog(logfile))
266  else:
267  outs.append((cmdwdefs,cph.harvest(curperfdir)))
268  #incrementing the variable for the command number:
269  cmd_num += 1
270 
271 
272  return outs #Not sure what James intended to return here... the contents of all logfiles in a list of logfiles?
273  except exceptions.Exception as detail:
274  # wrap the entire function in try except so we can log the error at client and server
275  logh = open(os.path.join(os.getcwd(),"error.log"),"a")
276  logh.write(str(detail) + "\n")
277  logh.flush()
278  logh.close()
279  print(detail)
280  sys.stdout.flush()
281  raise
282 
def readlog(logfile)
def get_NumOfCores()
Definition: cmsCpuInfo.py:7
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def request_benchmark(cmds)
def getCPSkeyword(key, dict)
#define str(s)
def cmsPerfServer.runserv (   port)

Definition at line 92 of file cmsPerfServer.py.

References edm.print().

Referenced by _main().

92 def runserv(port):
93  # Remember that localhost is the loopback network: it does not provide
94  # or require any connection to the outside world. As such it is useful
95  # for testing purposes. If you want your server to be seen on other
96  # machines, you must use your real network address in stead of
97  # 'localhost'.
98  server = None
99  try:
100  server = SimpleXMLRPCServer.SimpleXMLRPCServer((socket.gethostname(),port))
101  server.register_function(request_benchmark)
102  except socket.error as detail:
103  print("ERROR: Could not initialise server:", detail)
104  sys.stdout.flush()
105  sys.exit()
106 
107  print("Running server on port %s... " % port)
108  sys.stdout.flush()
109  while True:
110  try:
111  server.handle_request()
112  sys.stdout.flush()
113  except (KeyboardInterrupt, SystemExit):
114  #cleanup
115  server.server_close()
116  raise
117  except:
118  #cleanup
119  server.server_close()
120  raise
121  server.server_close()
122 
123 #Not sure about this unused function:
124 #Probably left over from first server implementation tests
125 #def runcmd(cmd):
126 # process = os.popen(cmd)
127 # cmdout = process.read()
128 # exitstat = process.close()
129 #
130 # if True:
131 # print cmd
132 # print cmdout
133 #
134 # if not exitstat == None:
135 # sig = exitstat >> 16 # Get the top 16 bits
136 # xstatus = exitstat & 0xffff # Mask out all bits except the bottom 16
137 # raise
138 # return cmdout
139 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def runserv(port)

Variable Documentation

cmsPerfServer._CASTOR_DIR
private

Definition at line 21 of file cmsPerfServer.py.

cmsPerfServer._DEFAULTS
private

Definition at line 22 of file cmsPerfServer.py.

cmsPerfServer._logreturn
private

Definition at line 19 of file cmsPerfServer.py.

cmsPerfServer._outputdir
private

Definition at line 17 of file cmsPerfServer.py.

cmsPerfServer._PROG_NAME
private

Definition at line 20 of file cmsPerfServer.py.

cmsPerfServer._reqnumber
private

Definition at line 18 of file cmsPerfServer.py.

cmsPerfServer.CandlesString

Definition at line 13 of file cmsPerfServer.py.