def benchmark(self, maker=pyps.Maker(), iterations=1, args=[], **opt): rep = self.tmpdirname outfile = self.compile(rep=rep, maker=maker, rule="mrproper", **opt) outfile = self.compile(rep=rep, maker=maker, **opt) self._module_rtimes = dict() for i in range(0, iterations): print >> sys.stderr, "Launch execution of %s %s..." % ( outfile, " ".join(map(str, args))) rc, out, err = self.run(outfile, args) if rc != 0: message = "Program %s failed with return code %d.\nOutput:\n%s\nstderr:\n%s\n" % ( outfile + " ".join(args), rc, out, err) raise RuntimeError(message) try: self._get_timefile_and_parse() except IOError: message = "command: " + outfile + " ".join(args) + "\n" message += "out: " + out + "\n" message += "err: " + err + "\n" message += "return code: " + str(rc) + "\n" raise RuntimeError(message) self._final_runtimes = dict() for module, execs in self._module_rtimes.iteritems(): self._final_runtimes[module] = list() for times in execs: times.sort() self._final_runtimes[module].append(times[len(times) / 2]) return self._final_runtimes
def compile(self, maker=pyps.Maker(), rep=None, outfile="a.out", rule="all", **opts): """ Uses makefiles on the remote host to compile the workspace""" if rep == None: rep = self.tmpdirname self.divert(rep, maker) rep = os.path.join(self.__remoteExec.working_dir(), rep) commandline = pypsutils.gen_compile_command(rep, maker.makefile, outfile, rule, **opts) if self.verbose: print >> sys.stderr, "Compiling the remote workspace with", commandline #We need to set shell to False or it messes up with the make command p = self.__remoteExec.doPopen(commandline) (out, err) = p.communicate() rc = p.returncode if rc != 0: print >> sys.stderr, err raise RuntimeError("%s failed with return code %d" % (commandline, rc)) return os.path.join(rep, outfile)
def divert(self, rep=None, maker=pyps.Maker()): if rep == None: rep = self.tmpdirname makefile, others = super(workspace, self).divert(rep, maker) self.__remoteExec.copy(os.path.join(rep, makefile), rep) for f in others: self.__remoteExec.copy(os.path.join(rep, f), rep) return makefile, others
def binary_size(module, maker=pyps.Maker()): """Workspace extension to provide a binary_size function to each module. A call to the binary_size function of a given module attempts to compile the program and then to extract the compiled size and the instruction count of the given module using objdump. The compiled size and the instruction count are returned by the function in a tuple. A ValueError exception is thrown if the function is not found in the binary (see below). A RuntimeError is thrown when the objdump call failed. Be careful. The symbol used by the compiler in the binary object for the given module must be guessed by the binary_size function. Given a function "foo", the symbol can be "foo", "foo.", "_foo" or many others forms, thus we cannot ensure that this function will work in every situations. A wrong guess can lead to a ValueError exception or in a few cases to wrongs results.""" outfile = module.workspace.compile( maker=maker, CFLAGS="-O2") # we should strip it instead ret = __funcsize(module.name, outfile) os.unlink(outfile) return ret
def __init__(self, *sources, **kwargs): super(workspace, self).__init__(*sources, **kwargs) self.__ref_maker = kwargs.get('ref_maker', pyps.Maker()) self.__ref_argv = kwargs.get('ref_argv', []) self.__ref_output = None self._enable_check = True