Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from subprocess import Popen, PIPE
- def flatten_list_of_strings(args):
- output = ''
- for s in args:
- output += s
- output += ' '
- return output
- def str_to_num(s):
- if '.' in s:
- return float(s)
- else:
- return int(s)
- class ExpRunner():
- def __init__(self, filter_name, input_image_path, implementation, output_image_dir, verbose=False):
- self.tp_exec = '../build/tp2'
- self.filter_name = filter_name
- self.exp_results = {'filter_name': filter_name, 'implementation': implementation}
- self.run_args = [self.tp_exec,
- filter_name,
- input_image_path,
- "-i", implementation,
- "-o", output_image_dir]
- self.verbose = verbose
- def exp_keys(self):
- '''
- ["Comienzo",
- "Fin",
- "# de ciclos insumidos totales",
- "# de ciclos insumidos por llamada"]
- '''
- return ["# de ciclos insumidos totales"] # por ahora solo nos interesa esta
- def run_executable(self,run_args):
- p = Popen(run_args, stdout=PIPE, bufsize=1)
- with p.stdout:
- for line in iter(p.stdout.readline, b''):
- line = line.decode("utf-8")
- print(line)
- try:
- key, val = line[:-1].split(':')
- key = key.strip(" ")
- if(key in self.exp_keys()):
- self.exp_results[key] = str_to_num(val)
- except:
- pass
- p.wait() # wait for the subprocess to exit
- def print_help(self):
- self.run_executable([self.tp_exec, "-h"])
- return
- def run(self):
- if self.verbose:
- print("Run command:")
- print(flatten_list_of_strings(self.run_args))
- print
- self.run_executable(self.run_args)
- return dict(self.exp_results)
- from shutil import copyfile
- from subprocess import check_call
- class MultipleAsmImplementationsExpRunner(ExpRunner):
- def setup_asm_implementation(self, asm_implementation):
- filters_path = "../filters/"
- dest_implementation = "asm"
- src_asm = filters_path + self.filter_name + '_' + asm_implementation + ".asm"
- print(src_asm)
- dst_asm = filters_path + self.filter_name + '_' + dest_implementation + ".asm"
- print(dst_asm)
- copyfile(src_asm, dst_asm)
- def make_executable(self):
- check_call(["make"], cwd="../")
- def run(self, asm_implementation):
- self.setup_asm_implementation(asm_implementation)
- self.make_executable()
- super().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement