2 import socket, xml, xmlrpclib, os, sys, threading, Queue, time, random, pickle, exceptions
6 PROG_NAME = os.path.basename(sys.argv[0])
8 validPerfSuitKeys= [
"castordir",
"perfsuitedir" ,
"TimeSizeEvents",
"TimeSizeCandles",
"IgProfEvents",
"IgProfCandles",
"CallgrindEvents",
"CallgrindCandles",
"MemcheckEvents",
"MemcheckCandles",
"cmsScimark",
"cmsScimarkLarge",
9 "cmsdriverOptions",
"stepOptions",
"quicktest",
"profilers",
"cpus",
"cores",
"prevrel",
"isAllCandles",
"candles",
10 "bypasshlt",
"runonspare",
"logfile"]
23 def _isValidPerfCmdsDef(alist):
26 isdict = type(item) == type({})
30 out = out
and key
in validPerfSuitKeys
32 out = out
and type(item[key]) == type(
"")
34 out = out
and type(item[key]) == type(
"")
35 elif key ==
"castordir":
36 out = out
and type(item[key]) == type(
"")
37 elif key ==
"perfsuitedir":
38 out = out
and type(item[key]) == type(
"")
39 elif key ==
"TimeSizeEvents":
40 out = out
and type(item[key]) == type(123)
41 elif key ==
"TimeSizeCandles":
42 out = out
and type(item[key]) == type(
"")
43 elif key ==
"CallgrindEvents":
44 out = out
and type(item[key]) == type(123)
45 elif key ==
"CallgrindCandles":
46 out = out
and type(item[key]) == type(
"")
47 elif key ==
"IgProfEvents":
48 out = out
and type(item[key]) == type(123)
49 elif key ==
"IgProfCandles":
50 out = out
and type(item[key]) == type(
"")
51 elif key ==
"MemcheckEvents":
52 out = out
and type(item[key]) == type(123)
53 elif key ==
"MemcheckCandles":
54 out = out
and type(item[key]) == type(
"")
55 elif key ==
"cmsScimark":
56 out = out
and type(item[key]) == type(123)
57 elif key ==
"cmsScimarkLarge":
58 out = out
and type(item[key]) == type(123)
59 elif key ==
"cmsdriverOptions":
60 out = out
and type(item[key]) == type(
"")
61 elif key ==
"stepOptions":
62 out = out
and type(item[key]) == type(
"")
63 elif key ==
"quicktest":
64 out = out
and type(item[key]) == type(
False)
65 elif key ==
"profilers":
66 out = out
and type(item[key]) == type(
"")
67 elif key ==
"prevrel":
68 out = out
and type(item[key]) == type(
"")
69 elif key ==
"isAllCandles":
70 out = out
and type(item[key]) == type(
False)
71 elif key ==
"candles":
72 out = out
and type(item[key]) == type(
"")
73 elif key ==
"bypasshlt":
74 out = out
and type(item[key]) == type(
False)
75 elif key ==
"runonspare":
76 out = out
and type(item[key]) == type(
False)
77 elif key ==
"logfile":
78 out = out
and type(item[key]) == type(
"")
81 parser = opt.OptionParser(usage=(
"""%s [Options]""" % PROG_NAME))
83 parser.add_option(
'-p',
88 help=
'Connect to server on a particular port',
92 parser.add_option(
'-o',
97 help=
'File to output data to',
101 parser.add_option(
'-m',
107 help=
'Machines to run the benchmarking on, for each machine add another one of these options',
108 metavar=
'<MACHINES>',
111 parser.add_option(
'-f',
117 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.',
121 (options, args) = parser.parse_args()
126 outfile = options.outfile
127 if not outfile ==
"":
128 outfile = os.path.abspath(options.outfile)
129 outdir = os.path.dirname(outfile)
130 if not os.path.isdir(outdir):
131 parser.error(
"ERROR: %s is not a valid directory to create %s" % (outdir,os.path.basename(outfile)))
134 outfile = os.path.join(os.getcwd(),
"cmsmultiperfdata.pypickle")
136 if os.path.exists(outfile):
137 parser.error(
"ERROR: outfile %s already exists" % outfile)
145 cmscmdfiles = options.cmscmdfile
146 if len(cmscmdfiles) <= 0:
147 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")
150 for cmscmdfile
in cmscmdfiles:
151 cmdfile = os.path.abspath(cmscmdfile)
153 if os.path.isfile(cmdfile):
156 cmsperf_cmds.append(listperfsuitekeywords)
157 except (SyntaxError), detail:
158 parser.error(
"ERROR: %s must be a valid python file" % cmdfile)
160 except (NameError), detail:
161 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)))
165 if not type(cmsperf_cmds[-1]) == type([]):
166 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)
168 if not _isValidPerfCmdsDef(cmsperf_cmds[-1]):
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 3" % cmdfile)
173 parser.error(
"ERROR: %s is not a file" % cmdfile)
180 if options.port == -1:
185 machines = options.machines
190 if len(machines) <= 0:
191 parser.error(
"you must specify at least one machine to benchmark")
193 machines =
map(
lambda x: x.strip(),machines)
195 for machine
in machines:
197 output = socket.getaddrinfo(machine,port)
198 except socket.gaierror:
199 parser.error(
"ERROR: Can not resolve machine address %s (must be ip{4,6} or hostname)" % machine)
206 if len(cmsperf_cmds) == 1:
207 for machine
in machines:
210 cmdindex[machine] = 0
212 if not len(cmsperf_cmds) == len(machines):
213 parser.error(
"if more than one configuration file was specified you must specify a configuration file for each machine.")
216 for i
in range(len(machines)):
219 cmdindex[machine] = i
221 return (cmsperf_cmds, port, machines, outfile, cmdindex)
230 server = xmlrpclib.ServerProxy(
"http://%s:%s" % (shost,sport))
231 return server.request_benchmark(perfcmds)
232 except socket.error, detail:
233 print "ERROR: Could not communicate with server %s:%s:" % (shost,sport), detail
234 except xml.parsers.expat.ExpatError, detail:
235 print "ERROR: XML-RPC could not be parsed:", detail
236 except xmlrpclib.ProtocolError, detail:
237 print "ERROR: XML-RPC protocol error", detail,
"try using -L xxx:localhost:xxx if using ssh to forward"
238 except exceptions, detail:
239 print "ERROR: There was a runtime error thrown by server %s; detail follows." % shost
253 threading.Thread.__init__(self)
259 print "data is %s"%data
260 print "Puttin it in the queue as (%s,%s)"%(self.
__host,data)
261 self.__queue.put((self.
__host, data))
262 except (exceptions.Exception, xmlrpclib.Fault), detail:
263 print "Exception was thrown when receiving/submitting job information to host", self.
__host,
". Exception information:"
271 def runclient(perfcmds, hosts, port, outfile, cmdindex):
272 queue = Queue.Queue()
276 print "Submitting jobs to %s..." % host
277 w =
Worker(host, port, perfcmds[cmdindex[host]], queue)
280 print "All jobs submitted, waiting for results..."
283 while reduce(
lambda x,y: x
or y,
map(
lambda x: x.isAlive(),workers)):
287 except (KeyboardInterrupt, SystemExit):
295 print "All job results received"
296 print "The size with the queue containing all data is: %s "%queue.qsize()
319 print "Pickling data to file %s"%outfile
323 print "Queue size is still %s"%q.qsize()
324 (host, data) = q.get()
325 out.append((host,data))
326 print "Dumping at screen the output!\n%s"%out
327 oh = open(outfile,
"wb")
332 (cmsperf_cmds, port, hosts, outfile, cmdindex) =
optionparse()
333 runclient(cmsperf_cmds, hosts, port, outfile, cmdindex)
335 if __name__ ==
"__main__":
Worker This is a subclass of thread that submits commands to the server and stores the result in a th...
def optionparse
Option parser returns : Command set to run on each (or all) machines, port to connect to server...
def presentBenchmarkData
Format of the returned data from remote host should be of the form (this could be cleaned up a little...
def request_benchmark
Request benchmark Connects to server and returns data returns: profiling data from server...