2 import socket, xml, xmlrpclib, os, sys, threading, Queue, time, random, pickle, exceptions
4 from functools
import reduce
7 PROG_NAME = os.path.basename(sys.argv[0])
9 validPerfSuitKeys= [
"castordir",
"perfsuitedir" ,
"TimeSizeEvents",
"TimeSizeCandles",
"IgProfEvents",
"IgProfCandles",
"CallgrindEvents",
"CallgrindCandles",
"MemcheckEvents",
"MemcheckCandles",
"cmsScimark",
"cmsScimarkLarge",
10 "cmsdriverOptions",
"stepOptions",
"quicktest",
"profilers",
"cpus",
"cores",
"prevrel",
"isAllCandles",
"candles",
11 "bypasshlt",
"runonspare",
"logfile"]
24 def _isValidPerfCmdsDef(alist):
27 isdict = type(item) == type({})
31 out = out
and key
in validPerfSuitKeys
33 out = out
and type(item[key]) == type(
"")
35 out = out
and type(item[key]) == type(
"")
36 elif key ==
"castordir":
37 out = out
and type(item[key]) == type(
"")
38 elif key ==
"perfsuitedir":
39 out = out
and type(item[key]) == type(
"")
40 elif key ==
"TimeSizeEvents":
41 out = out
and type(item[key]) == type(123)
42 elif key ==
"TimeSizeCandles":
43 out = out
and type(item[key]) == type(
"")
44 elif key ==
"CallgrindEvents":
45 out = out
and type(item[key]) == type(123)
46 elif key ==
"CallgrindCandles":
47 out = out
and type(item[key]) == type(
"")
48 elif key ==
"IgProfEvents":
49 out = out
and type(item[key]) == type(123)
50 elif key ==
"IgProfCandles":
51 out = out
and type(item[key]) == type(
"")
52 elif key ==
"MemcheckEvents":
53 out = out
and type(item[key]) == type(123)
54 elif key ==
"MemcheckCandles":
55 out = out
and type(item[key]) == type(
"")
56 elif key ==
"cmsScimark":
57 out = out
and type(item[key]) == type(123)
58 elif key ==
"cmsScimarkLarge":
59 out = out
and type(item[key]) == type(123)
60 elif key ==
"cmsdriverOptions":
61 out = out
and type(item[key]) == type(
"")
62 elif key ==
"stepOptions":
63 out = out
and type(item[key]) == type(
"")
64 elif key ==
"quicktest":
65 out = out
and type(item[key]) == type(
False)
66 elif key ==
"profilers":
67 out = out
and type(item[key]) == type(
"")
68 elif key ==
"prevrel":
69 out = out
and type(item[key]) == type(
"")
70 elif key ==
"isAllCandles":
71 out = out
and type(item[key]) == type(
False)
72 elif key ==
"candles":
73 out = out
and type(item[key]) == type(
"")
74 elif key ==
"bypasshlt":
75 out = out
and type(item[key]) == type(
False)
76 elif key ==
"runonspare":
77 out = out
and type(item[key]) == type(
False)
78 elif key ==
"logfile":
79 out = out
and type(item[key]) == type(
"")
82 parser = opt.OptionParser(usage=(
"""%s [Options]""" % PROG_NAME))
84 parser.add_option(
'-p',
89 help=
'Connect to server on a particular port',
93 parser.add_option(
'-o',
98 help=
'File to output data to',
102 parser.add_option(
'-m',
108 help=
'Machines to run the benchmarking on, for each machine add another one of these options',
109 metavar=
'<MACHINES>',
112 parser.add_option(
'-f',
118 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.',
122 (options, args) = parser.parse_args()
127 outfile = options.outfile
128 if not outfile ==
"":
129 outfile = os.path.abspath(options.outfile)
130 outdir = os.path.dirname(outfile)
131 if not os.path.isdir(outdir):
132 parser.error(
"ERROR: %s is not a valid directory to create %s" % (outdir,os.path.basename(outfile)))
135 outfile = os.path.join(os.getcwd(),
"cmsmultiperfdata.pypickle")
137 if os.path.exists(outfile):
138 parser.error(
"ERROR: outfile %s already exists" % outfile)
146 cmscmdfiles = options.cmscmdfile
147 if len(cmscmdfiles) <= 0:
148 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")
151 for cmscmdfile
in cmscmdfiles:
152 cmdfile = os.path.abspath(cmscmdfile)
154 if os.path.isfile(cmdfile):
157 cmsperf_cmds.append(listperfsuitekeywords)
158 except (SyntaxError)
as detail:
159 parser.error(
"ERROR: %s must be a valid python file" % cmdfile)
161 except (NameError)
as detail:
162 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)))
166 if not type(cmsperf_cmds[-1]) == type([]):
167 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)
169 if not _isValidPerfCmdsDef(cmsperf_cmds[-1]):
170 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)
174 parser.error(
"ERROR: %s is not a file" % cmdfile)
181 if options.port == -1:
186 machines = options.machines
191 if len(machines) <= 0:
192 parser.error(
"you must specify at least one machine to benchmark")
194 machines =
map(
lambda x: x.strip(),machines)
196 for machine
in machines:
198 output = socket.getaddrinfo(machine,port)
199 except socket.gaierror:
200 parser.error(
"ERROR: Can not resolve machine address %s (must be ip{4,6} or hostname)" % machine)
207 if len(cmsperf_cmds) == 1:
208 for machine
in machines:
211 cmdindex[machine] = 0
213 if not len(cmsperf_cmds) == len(machines):
214 parser.error(
"if more than one configuration file was specified you must specify a configuration file for each machine.")
217 for i
in range(len(machines)):
220 cmdindex[machine] = i
222 return (cmsperf_cmds, port, machines, outfile, cmdindex)
231 server = xmlrpclib.ServerProxy(
"http://%s:%s" % (shost,sport))
232 return server.request_benchmark(perfcmds)
233 except socket.error
as detail:
234 print "ERROR: Could not communicate with server %s:%s:" % (shost,sport), detail
235 except xml.parsers.expat.ExpatError
as detail:
236 print "ERROR: XML-RPC could not be parsed:", detail
237 except xmlrpclib.ProtocolError
as detail:
238 print "ERROR: XML-RPC protocol error", detail,
"try using -L xxx:localhost:xxx if using ssh to forward" 239 except exceptions
as detail:
240 print "ERROR: There was a runtime error thrown by server %s; detail follows." % shost
254 threading.Thread.__init__(self)
260 print "data is %s"%data
261 print "Puttin it in the queue as (%s,%s)"%(self.
__host,data)
262 self.__queue.put((self.
__host, data))
263 except (exceptions.Exception, xmlrpclib.Fault)
as detail:
264 print "Exception was thrown when receiving/submitting job information to host", self.
__host,
". Exception information:" 272 def runclient(perfcmds, hosts, port, outfile, cmdindex):
273 queue = Queue.Queue()
277 print "Submitting jobs to %s..." % host
278 w =
Worker(host, port, perfcmds[cmdindex[host]], queue)
281 print "All jobs submitted, waiting for results..." 284 while reduce(
lambda x,y: x
or y,
map(
lambda x: x.isAlive(),workers)):
288 except (KeyboardInterrupt, SystemExit):
296 print "All job results received" 297 print "The size with the queue containing all data is: %s "%queue.qsize()
320 print "Pickling data to file %s"%outfile
324 print "Queue size is still %s"%q.qsize()
325 (host, data) = q.get()
326 out.append((host,data))
327 print "Dumping at screen the output!\n%s"%out
328 oh = open(outfile,
"wb")
333 (cmsperf_cmds, port, hosts, outfile, cmdindex) =
optionparse()
334 runclient(cmsperf_cmds, hosts, port, outfile, cmdindex)
336 if __name__ ==
"__main__":
def optionparse()
Option parser returns : Command set to run on each (or all) machines, port to connect to server...
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...