2 from __future__
import print_function
3 import socket, xml, xmlrpclib, os, sys, threading, Queue, time, random, pickle, exceptions
5 from functools
import reduce
8 PROG_NAME = os.path.basename(sys.argv[0])
10 validPerfSuitKeys= [
"castordir",
"perfsuitedir" ,
"TimeSizeEvents",
"TimeSizeCandles",
"IgProfEvents",
"IgProfCandles",
"CallgrindEvents",
"CallgrindCandles",
"MemcheckEvents",
"MemcheckCandles",
"cmsScimark",
"cmsScimarkLarge",
11 "cmsdriverOptions",
"stepOptions",
"quicktest",
"profilers",
"cpus",
"cores",
"prevrel",
"isAllCandles",
"candles",
12 "bypasshlt",
"runonspare",
"logfile"]
25 def _isValidPerfCmdsDef(alist):
28 isdict = isinstance(item, type({}))
32 out = out
and key
in validPerfSuitKeys
34 out = out
and isinstance(item[key], type(
""))
36 out = out
and isinstance(item[key], type(
""))
37 elif key ==
"castordir":
38 out = out
and isinstance(item[key], type(
""))
39 elif key ==
"perfsuitedir":
40 out = out
and isinstance(item[key], type(
""))
41 elif key ==
"TimeSizeEvents":
42 out = out
and isinstance(item[key], type(123))
43 elif key ==
"TimeSizeCandles":
44 out = out
and isinstance(item[key], type(
""))
45 elif key ==
"CallgrindEvents":
46 out = out
and isinstance(item[key], type(123))
47 elif key ==
"CallgrindCandles":
48 out = out
and isinstance(item[key], type(
""))
49 elif key ==
"IgProfEvents":
50 out = out
and isinstance(item[key], type(123))
51 elif key ==
"IgProfCandles":
52 out = out
and isinstance(item[key], type(
""))
53 elif key ==
"MemcheckEvents":
54 out = out
and isinstance(item[key], type(123))
55 elif key ==
"MemcheckCandles":
56 out = out
and isinstance(item[key], type(
""))
57 elif key ==
"cmsScimark":
58 out = out
and isinstance(item[key], type(123))
59 elif key ==
"cmsScimarkLarge":
60 out = out
and isinstance(item[key], type(123))
61 elif key ==
"cmsdriverOptions":
62 out = out
and isinstance(item[key], type(
""))
63 elif key ==
"stepOptions":
64 out = out
and isinstance(item[key], type(
""))
65 elif key ==
"quicktest":
66 out = out
and isinstance(item[key], type(
False))
67 elif key ==
"profilers":
68 out = out
and isinstance(item[key], type(
""))
69 elif key ==
"prevrel":
70 out = out
and isinstance(item[key], type(
""))
71 elif key ==
"isAllCandles":
72 out = out
and isinstance(item[key], type(
False))
73 elif key ==
"candles":
74 out = out
and isinstance(item[key], type(
""))
75 elif key ==
"bypasshlt":
76 out = out
and isinstance(item[key], type(
False))
77 elif key ==
"runonspare":
78 out = out
and isinstance(item[key], type(
False))
79 elif key ==
"logfile":
80 out = out
and isinstance(item[key], type(
""))
83 parser = opt.OptionParser(usage=(
"""%s [Options]""" % PROG_NAME))
85 parser.add_option(
'-p',
90 help=
'Connect to server on a particular port',
94 parser.add_option(
'-o',
99 help=
'File to output data to',
103 parser.add_option(
'-m',
109 help=
'Machines to run the benchmarking on, for each machine add another one of these options',
110 metavar=
'<MACHINES>',
113 parser.add_option(
'-f',
119 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.',
123 (options, args) = parser.parse_args()
128 outfile = options.outfile
129 if not outfile ==
"":
130 outfile = os.path.abspath(options.outfile)
131 outdir = os.path.dirname(outfile)
132 if not os.path.isdir(outdir):
133 parser.error(
"ERROR: %s is not a valid directory to create %s" % (outdir,os.path.basename(outfile)))
136 outfile = os.path.join(os.getcwd(),
"cmsmultiperfdata.pypickle")
138 if os.path.exists(outfile):
139 parser.error(
"ERROR: outfile %s already exists" % outfile)
147 cmscmdfiles = options.cmscmdfile
148 if len(cmscmdfiles) <= 0:
149 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")
152 for cmscmdfile
in cmscmdfiles:
153 cmdfile = os.path.abspath(cmscmdfile)
155 if os.path.isfile(cmdfile):
158 cmsperf_cmds.append(listperfsuitekeywords)
159 except (SyntaxError)
as detail:
160 parser.error(
"ERROR: %s must be a valid python file" % cmdfile)
162 except (NameError)
as detail:
163 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)))
167 if not isinstance(cmsperf_cmds[-1], type([])):
168 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)
170 if not _isValidPerfCmdsDef(cmsperf_cmds[-1]):
171 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)
175 parser.error(
"ERROR: %s is not a file" % cmdfile)
182 if options.port == -1:
187 machines = options.machines
192 if len(machines) <= 0:
193 parser.error(
"you must specify at least one machine to benchmark")
195 machines =
map(
lambda x: x.strip(),machines)
197 for machine
in machines:
199 output = socket.getaddrinfo(machine,port)
200 except socket.gaierror:
201 parser.error(
"ERROR: Can not resolve machine address %s (must be ip{4,6} or hostname)" % machine)
208 if len(cmsperf_cmds) == 1:
209 for machine
in machines:
212 cmdindex[machine] = 0
214 if not len(cmsperf_cmds) == len(machines):
215 parser.error(
"if more than one configuration file was specified you must specify a configuration file for each machine.")
218 for i
in range(len(machines)):
221 cmdindex[machine] = i
223 return (cmsperf_cmds, port, machines, outfile, cmdindex)
232 server = xmlrpclib.ServerProxy(
"http://%s:%s" % (shost,sport))
233 return server.request_benchmark(perfcmds)
234 except socket.error
as detail:
235 print(
"ERROR: Could not communicate with server %s:%s:" % (shost,sport), detail)
236 except xml.parsers.expat.ExpatError
as detail:
237 print(
"ERROR: XML-RPC could not be parsed:", detail)
238 except xmlrpclib.ProtocolError
as detail:
239 print(
"ERROR: XML-RPC protocol error", detail,
"try using -L xxx:localhost:xxx if using ssh to forward")
240 except exceptions
as detail:
241 print(
"ERROR: There was a runtime error thrown by server %s; detail follows." % shost)
255 threading.Thread.__init__(self)
261 print(
"data is %s"%data)
262 print(
"Puttin it in the queue as (%s,%s)"%(self.
__host,data))
263 self.__queue.put((self.
__host, data))
264 except (exceptions.Exception, xmlrpclib.Fault)
as detail:
265 print(
"Exception was thrown when receiving/submitting job information to host", self.
__host,
". Exception information:")
273 def runclient(perfcmds, hosts, port, outfile, cmdindex):
274 queue = Queue.Queue()
278 print(
"Submitting jobs to %s..." % host)
279 w =
Worker(host, port, perfcmds[cmdindex[host]], queue)
282 print(
"All jobs submitted, waiting for results...")
285 while reduce(
lambda x,y: x
or y,
map(
lambda x: x.isAlive(),workers)):
289 except (KeyboardInterrupt, SystemExit):
297 print(
"All job results received")
298 print(
"The size with the queue containing all data is: %s "%queue.qsize())
321 print(
"Pickling data to file %s"%outfile)
325 print(
"Queue size is still %s"%q.qsize())
326 (host, data) = q.get()
327 out.append((host,data))
328 print(
"Dumping at screen the output!\n%s"%out)
329 oh = open(outfile,
"wb")
334 (cmsperf_cmds, port, hosts, outfile, cmdindex) =
optionparse()
335 runclient(cmsperf_cmds, hosts, port, outfile, cmdindex)
337 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...