2 from __future__
import print_function
3 from builtins
import range
4 import socket, xml, xmlrpclib, os, sys, threading, Queue, time, random, pickle, exceptions
6 from functools
import reduce
9 PROG_NAME = os.path.basename(sys.argv[0])
11 validPerfSuitKeys= [
"castordir",
"perfsuitedir" ,
"TimeSizeEvents",
"TimeSizeCandles",
"IgProfEvents",
"IgProfCandles",
"CallgrindEvents",
"CallgrindCandles",
"MemcheckEvents",
"MemcheckCandles",
"cmsScimark",
"cmsScimarkLarge",
12 "cmsdriverOptions",
"stepOptions",
"quicktest",
"profilers",
"cpus",
"cores",
"prevrel",
"isAllCandles",
"candles",
13 "bypasshlt",
"runonspare",
"logfile"]
26 def _isValidPerfCmdsDef(alist):
29 isdict = isinstance(item, type({}))
33 out = out
and key
in validPerfSuitKeys
35 out = out
and isinstance(item[key], type(
""))
37 out = out
and isinstance(item[key], type(
""))
38 elif key ==
"castordir":
39 out = out
and isinstance(item[key], type(
""))
40 elif key ==
"perfsuitedir":
41 out = out
and isinstance(item[key], type(
""))
42 elif key ==
"TimeSizeEvents":
43 out = out
and isinstance(item[key], type(123))
44 elif key ==
"TimeSizeCandles":
45 out = out
and isinstance(item[key], type(
""))
46 elif key ==
"CallgrindEvents":
47 out = out
and isinstance(item[key], type(123))
48 elif key ==
"CallgrindCandles":
49 out = out
and isinstance(item[key], type(
""))
50 elif key ==
"IgProfEvents":
51 out = out
and isinstance(item[key], type(123))
52 elif key ==
"IgProfCandles":
53 out = out
and isinstance(item[key], type(
""))
54 elif key ==
"MemcheckEvents":
55 out = out
and isinstance(item[key], type(123))
56 elif key ==
"MemcheckCandles":
57 out = out
and isinstance(item[key], type(
""))
58 elif key ==
"cmsScimark":
59 out = out
and isinstance(item[key], type(123))
60 elif key ==
"cmsScimarkLarge":
61 out = out
and isinstance(item[key], type(123))
62 elif key ==
"cmsdriverOptions":
63 out = out
and isinstance(item[key], type(
""))
64 elif key ==
"stepOptions":
65 out = out
and isinstance(item[key], type(
""))
66 elif key ==
"quicktest":
67 out = out
and isinstance(item[key], type(
False))
68 elif key ==
"profilers":
69 out = out
and isinstance(item[key], type(
""))
70 elif key ==
"prevrel":
71 out = out
and isinstance(item[key], type(
""))
72 elif key ==
"isAllCandles":
73 out = out
and isinstance(item[key], type(
False))
74 elif key ==
"candles":
75 out = out
and isinstance(item[key], type(
""))
76 elif key ==
"bypasshlt":
77 out = out
and isinstance(item[key], type(
False))
78 elif key ==
"runonspare":
79 out = out
and isinstance(item[key], type(
False))
80 elif key ==
"logfile":
81 out = out
and isinstance(item[key], type(
""))
84 parser = opt.OptionParser(usage=(
"""%s [Options]""" % PROG_NAME))
86 parser.add_option(
'-p',
91 help=
'Connect to server on a particular port',
95 parser.add_option(
'-o',
100 help=
'File to output data to',
104 parser.add_option(
'-m',
110 help=
'Machines to run the benchmarking on, for each machine add another one of these options',
111 metavar=
'<MACHINES>',
114 parser.add_option(
'-f',
120 help=
'A files of cmsPerfSuite.py commands to execute on the machines, if more than one of these options is passed and the number of these options is the same as the number of machines, the x-th machine will use the x-th config file.',
124 (options, args) = parser.parse_args()
129 outfile = options.outfile
130 if not outfile ==
"":
131 outfile = os.path.abspath(options.outfile)
132 outdir = os.path.dirname(outfile)
133 if not os.path.isdir(outdir):
134 parser.error(
"ERROR: %s is not a valid directory to create %s" % (outdir,os.path.basename(outfile)))
137 outfile = os.path.join(os.getcwd(),
"cmsmultiperfdata.pypickle")
139 if os.path.exists(outfile):
140 parser.error(
"ERROR: outfile %s already exists" % outfile)
148 cmscmdfiles = options.cmscmdfile
149 if len(cmscmdfiles) <= 0:
150 parser.error(
"A valid python file defining a list of dictionaries that represents a list of cmsPerfSuite keyword arguments must be passed to this program")
153 for cmscmdfile
in cmscmdfiles:
154 cmdfile = os.path.abspath(cmscmdfile)
156 if os.path.isfile(cmdfile):
159 cmsperf_cmds.append(listperfsuitekeywords)
160 except (SyntaxError)
as detail:
161 parser.error(
"ERROR: %s must be a valid python file" % cmdfile)
163 except (NameError)
as detail:
164 parser.error(
"ERROR: %s must contain a list (variable named listperfsuitekeywords) of dictionaries that represents a list of cmsPerfSuite keyword arguments must be passed to this program: %s" % (cmdfile,
str(detail)))
168 if not isinstance(cmsperf_cmds[-1], type([])):
169 parser.error(
"ERROR: %s must contain a list (variable named listperfsuitekeywords) of dictionaries that represents a list of cmsPerfSuite keyword arguments must be passed to this program 2" % cmdfile)
171 if not _isValidPerfCmdsDef(cmsperf_cmds[-1]):
172 parser.error(
"ERROR: %s must contain a list (variable named listperfsuitekeywords) of dictionaries that represents a list of cmsPerfSuite keyword arguments must be passed to this program 3" % cmdfile)
176 parser.error(
"ERROR: %s is not a file" % cmdfile)
183 if options.port == -1:
188 machines = options.machines
193 if len(machines) <= 0:
194 parser.error(
"you must specify at least one machine to benchmark")
196 machines =
map(
lambda x: x.strip(),machines)
198 for machine
in machines:
200 output = socket.getaddrinfo(machine,port)
201 except socket.gaierror:
202 parser.error(
"ERROR: Can not resolve machine address %s (must be ip{4,6} or hostname)" % machine)
209 if len(cmsperf_cmds) == 1:
210 for machine
in machines:
213 cmdindex[machine] = 0
215 if not len(cmsperf_cmds) == len(machines):
216 parser.error(
"if more than one configuration file was specified you must specify a configuration file for each machine.")
219 for i
in range(len(machines)):
222 cmdindex[machine] = i
224 return (cmsperf_cmds, port, machines, outfile, cmdindex)
233 server = xmlrpclib.ServerProxy(
"http://%s:%s" % (shost,sport))
234 return server.request_benchmark(perfcmds)
235 except socket.error
as detail:
236 print(
"ERROR: Could not communicate with server %s:%s:" % (shost,sport), detail)
237 except xml.parsers.expat.ExpatError
as detail:
238 print(
"ERROR: XML-RPC could not be parsed:", detail)
239 except xmlrpclib.ProtocolError
as detail:
240 print(
"ERROR: XML-RPC protocol error", detail,
"try using -L xxx:localhost:xxx if using ssh to forward")
241 except exceptions
as detail:
242 print(
"ERROR: There was a runtime error thrown by server %s; detail follows." % shost)
256 threading.Thread.__init__(self)
262 print(
"data is %s"%data)
263 print(
"Puttin it in the queue as (%s,%s)"%(self.
__host,data))
264 self.__queue.put((self.
__host, data))
265 except (exceptions.Exception, xmlrpclib.Fault)
as detail:
266 print(
"Exception was thrown when receiving/submitting job information to host", self.
__host,
". Exception information:")
274 def runclient(perfcmds, hosts, port, outfile, cmdindex):
275 queue = Queue.Queue()
279 print(
"Submitting jobs to %s..." % host)
280 w =
Worker(host, port, perfcmds[cmdindex[host]], queue)
283 print(
"All jobs submitted, waiting for results...")
286 while reduce(
lambda x,y: x
or y,
map(
lambda x: x.isAlive(),workers)):
290 except (KeyboardInterrupt, SystemExit):
298 print(
"All job results received")
299 print(
"The size with the queue containing all data is: %s "%queue.qsize())
322 print(
"Pickling data to file %s"%outfile)
326 print(
"Queue size is still %s"%q.qsize())
327 (host, data) = q.get()
328 out.append((host,data))
329 print(
"Dumping at screen the output!\n%s"%out)
330 oh = open(outfile,
"wb")
335 (cmsperf_cmds, port, hosts, outfile, cmdindex) =
optionparse()
336 runclient(cmsperf_cmds, hosts, port, outfile, cmdindex)
338 if __name__ ==
"__main__":
def optionparse()
Option parser returns : Command set to run on each (or all) machines, port to connect to server...
S & print(S &os, JobReport::InputFile const &f)
Worker This is a subclass of thread that submits commands to the server and stores the result in a th...
def presentBenchmarkData(q, outfile)
Format of the returned data from remote host should be of the form (this could be cleaned up a little...
def __init__(self, host, port, perfcmds, queue)
def runclient(perfcmds, hosts, port, outfile, cmdindex)
def request_benchmark(perfcmds, shost, sport)
Request benchmark Connects to server and returns data returns: profiling data from server...