def do_region_based_calculation(self, data): self.region_based_calculations = {} self.region_based_calculations_super_block_CFG = {} for cfg in self.cfgs.values(): if config.Arguments.function is None or config.Arguments.function == cfg.name: function_data = data.function_data[cfg.name] if config.Arguments.region_based: self.region_based_calculations[cfg.name] = [] if config.Arguments.region_based_super_block_CFG: self.region_based_calculations_super_block_CFG[ cfg.name] = [] for i in range(1, config.Arguments.repeat_calculation + 1): print("===== Repetition %d =====" % i) if config.Arguments.region_based: region_based_calculation = calculations.RegionalCalculationEnhancedCFG( function_data, cfg.get_LNT(), cfg.get_super_block_cfg()) self.region_based_calculations[cfg.name].append( region_based_calculation) if config.Arguments.region_based_super_block_CFG: region_based_calculation = calculations.RegionalCalculationSuperBlockCFG( function_data, cfg.get_LNT(), cfg.get_super_block_cfg()) self.region_based_calculations_super_block_CFG[ cfg.name].append(region_based_calculation) print("Region:: WCET(%s) = %d" % (cfg.name, region_based_calculation.wcet)) if config.Arguments.ilp: cfg_calculation = self.ilps.cfg_calculations[ cfg.name].constraint_system if cfg_calculation.wcet != region_based_calculation.wcet: debug.warning_message( "Disparity in WCETs for %s: (%f, %f)" % (cfg.name, cfg_calculation.wcet, region_based_calculation.wcet))
def binary(self): time_regex = re.compile(r'^(\d*\.\d+|\d+)$') total_time = 0.0 status = enums.Status.passed for run in xrange(1,config.Arguments.runs+1): debug.verbose_message("Run #%d of '%s'" % (run, config.Arguments.run_cmd), __name__) start = timeit.default_timer() proc = subprocess.Popen(config.Arguments.run_cmd, shell=True, stdout=subprocess.PIPE) stdout, stderr = proc.communicate() end = timeit.default_timer() if proc.returncode: status = enums.Status.failed debug.warning_message("FAILED: '%s'" % config.Arguments.run_cmd) continue if config.Arguments.execution_time_from_binary: if not stdout: raise internal_exceptions.BinaryRunException("Expected the binary to dump its execution time. Found nothing") for line in stdout.split(os.linesep): line = line.strip() matches = time_regex.findall(line) if matches: try: total_time += float(matches[0]) except: raise internal_exceptions.BinaryRunException("Execution time '%s' is not in the required format" % matches[0]) else: total_time += end - start self.status = status config.time_binary += total_time self.execution_time = total_time/config.Arguments.runs
def solve(self): with open(self._filename, 'w') as clpFile: for line in self._lines: clpFile.write(line) debug.debug_message("Solving CLP in %s" % self._filename, 10) command = 'jeclipse -b %s -e "%s."' % (self._filename, self.__goal) debug.verbose_message("Running command '%s'" % command, __name__) start = timeit.default_timer() proc = subprocess.Popen(command, shell=True, executable="/bin/bash") returnCode = proc.wait() self._solvingTime = (timeit.default_timer() - start) if returnCode != 0: debug.warning_message("Running '%s' failed" % command) return self._wcet, self._solvingTime else: with open(self._filename + '.res') as f: for line in f: if re.match(r'%s' % CLP.WCET, line): values = re.findall(r'[0-9]+', line) assert len( values ) == 1, "Unable to find WCET value in CLP output file" self._wcet = int(values[0]) assert self._wcet assert self._solvingTime return self._wcet, self._solvingTime
def solve(self): assert self._filename, "ILP filename has not been set" debug.debug_message("Solving ILP for %s" % self._filename, 10) command = "lp_solve %s -S1 -time" % self._filename start = timeit.default_timer() proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable="/bin/bash") returnCode = proc.wait() self._solvingTime = (timeit.default_timer() - start) if returnCode != 0: debug.warning_message("Running '%s' failed" % command) return self._wcet, self._solvingTime for line in proc.stdout.readlines(): if line.startswith("Value of objective function"): lexemes = shlex.split(line) self._wcet = long(decimal.Decimal(lexemes[-1])) assert self._wcet assert self._solvingTime for line in proc.stderr.readlines(): if line.startswith("CPU Time for Parsing"): lexemes = shlex.split(line) time = lexemes[5][:-1] #self.solvingTime -= float(time) return self._wcet, self._solvingTime
def do_region_based_calculation(self, data): self.region_based_calculations = {} self.region_based_calculations_super_block_CFG = {} for cfg in self.cfgs.values(): if config.Arguments.function is None or config.Arguments.function == cfg.name: function_data = data.function_data[cfg.name] if config.Arguments.region_based: self.region_based_calculations[cfg.name] = [] if config.Arguments.region_based_super_block_CFG: self.region_based_calculations_super_block_CFG[cfg.name] = [] for i in range(1, config.Arguments.repeat_calculation + 1): print("===== Repetition %d =====" % i) if config.Arguments.region_based: region_based_calculation = calculations.RegionalCalculationEnhancedCFG(function_data, cfg.get_LNT(), cfg.get_super_block_cfg()) self.region_based_calculations[cfg.name].append(region_based_calculation) if config.Arguments.region_based_super_block_CFG: region_based_calculation = calculations.RegionalCalculationSuperBlockCFG(function_data, cfg.get_LNT(), cfg.get_super_block_cfg()) self.region_based_calculations_super_block_CFG[cfg.name].append(region_based_calculation) print("Region:: WCET(%s) = %d" % (cfg.name, region_based_calculation.wcet)) if config.Arguments.ilp: cfg_calculation = self.ilps.cfg_calculations[cfg.name].constraint_system if cfg_calculation.wcet != region_based_calculation.wcet: debug.warning_message("Disparity in WCETs for %s: (%f, %f)" % (cfg.name, cfg_calculation.wcet, region_based_calculation.wcet))
def instrument_cfgs(program): for cfg_name in select_cfgs(program): if cfg_name not in program.cfgs: debug.warning_message("Program does not have CFG %s" % cfg_name) else: cfg = program.cfgs[cfg_name] instrumentation.do_instrumentation(cfg, get_program_points(cfg))
def check_IPG_edges(self, ipg): edges_in_ipg = set() for v in ipg: for succID in v.successors.keys(): edges_in_ipg.add((v.vertexID, succID)) for ipg_loop_info in self.ipgs_per_loop.values(): for (predID, succID) in ipg_loop_info.edges_added: if (predID, succID) not in edges_in_ipg: debug.warning_message("IPG edge (%d, %d) should NOT be in the IPG" % (predID, succID)) else: edges_in_ipg.remove((predID, succID)) if edges_in_ipg: for (predID, succID) in edges_in_ipg: debug.warning_message("IPG edgee (%d, %d) should be in the IPG" % (predID, succID))
def check_IPG_edges(self, ipg): edges_in_ipg = set() for v in ipg: for succID in v.successors.keys(): edges_in_ipg.add((v.vertexID, succID)) for ipg_loop_info in self.ipgs_per_loop.values(): for (predID, succID) in ipg_loop_info.edges_added: if (predID, succID) not in edges_in_ipg: debug.warning_message( "IPG edge (%d, %d) should NOT be in the IPG" % (predID, succID)) else: edges_in_ipg.remove((predID, succID)) if edges_in_ipg: for (predID, succID) in edges_in_ipg: debug.warning_message( "IPG edgee (%d, %d) should be in the IPG" % (predID, succID))
def solve (self): assert self._filename, "ILP filename has not been set" debug.debug_message("Solving ILP for %s" % self._filename, 10) command = "lp_solve %s -S1 -time" % self._filename start = timeit.default_timer() proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable="/bin/bash") returnCode = proc.wait() self._solvingTime = (timeit.default_timer() - start) if returnCode != 0: debug.warning_message("Running '%s' failed" % command) return self._wcet, self._solvingTime for line in proc.stdout.readlines(): if line.startswith("Value of objective function"): lexemes = shlex.split(line) self._wcet = long(decimal.Decimal(lexemes[-1])) assert self._wcet assert self._solvingTime for line in proc.stderr.readlines(): if line.startswith("CPU Time for Parsing"): lexemes = shlex.split(line) time = lexemes[5][:-1] #self.solvingTime -= float(time) return self._wcet, self._solvingTime
def get_program_points(cfg): vertices = set() edges = set() for v in cfg: vertices.add(v.vertexID) for succID in v.successors.keys(): edges.add((v.vertexID, succID)) if config.Arguments.profile == "choose": print("%s Vertices = {%s}" % (prompt_prefix, ','.join(str(vertexID) for vertexID in sorted(vertices)))) the_input = raw_input("%s Enter vertices as a comma-separated list: " % prompt_prefix).lower() the_input = re.sub(r'\s+', '', the_input) selected = set() for a_value in re.findall(r'\d+', the_input): vertexID = ast.literal_eval(a_value) if vertexID in vertices: selected.add(vertexID) else: debug.warning_message("CFG %s does not have vertex %d. Ignoring." % (cfg.name, vertexID)) print("%s Edges = {%s}" % (prompt_prefix, ','.join(str(edge) for edge in sorted(edges)))) the_input = raw_input("%s Enter edges as a comma-separated list: " % prompt_prefix).lower() the_input = re.sub(r'\s+', '', the_input) for a_value in re.findall(r'\(\d+,\d+\)', the_input): an_edge = ast.literal_eval(a_value) if an_edge in edges: selected.add(an_edge) else: debug.warning_message("CFG %s does not have edge %s. Ignoring." % (cfg.name, an_edge)) return selected elif config.Arguments.profile == "vertices": return vertices elif config.Arguments.profile == "edges": return edges elif config.Arguments.profile == "all": return vertices.union(edges) else: assert False, "Unknown profile choice"
def solve (self): with open(self._filename, 'w') as clpFile: for line in self._lines: clpFile.write(line) debug.debug_message("Solving CLP in %s" % self._filename, 10) command = 'jeclipse -b %s -e "%s."' % (self._filename, self.__goal) debug.verbose_message("Running command '%s'" % command, __name__) start = timeit.default_timer() proc = subprocess.Popen(command, shell=True, executable="/bin/bash") returnCode = proc.wait() self._solvingTime = (timeit.default_timer() - start) if returnCode != 0: debug.warning_message("Running '%s' failed" % command) return self._wcet, self._solvingTime else: with open(self._filename + '.res') as f: for line in f: if re.match(r'%s' % CLP.WCET, line): values = re.findall(r'[0-9]+', line) assert len(values) == 1, "Unable to find WCET value in CLP output file" self._wcet = int(values[0]) assert self._wcet assert self._solvingTime return self._wcet, self._solvingTime
def create_path_expression_between_two_vertices(program): prompt_prefix = "->" def parse_input_from_user(message): the_input = raw_input("%s %s: " % (prompt_prefix, message)).lower() the_input = re.sub(r'\s+', '', the_input) if re.match(r'\d+', the_input): return ast.literal_eval(the_input) return the_input try: while True: cfg = None if len(program.cfgs) == 1: cfg = program.cfgs.itervalues().next() else: print("%s CFGs = {%s}" % (prompt_prefix, ','.join( cfg.name for cfg in program.cfgs.values()))) cfg_name = parse_input_from_user("Enter CFG name") if cfg_name not in program.cfgs: debug.warning_message("Program does not have CFG %s" % cfg_name) else: cfg = program.cfgs[cfg_name] if cfg is not None: vertex_choices = "" for v in cfg: vertex_choices += "%d " % v.vertexID if v.vertexID == cfg.get_entryID(): vertex_choices += "(entry) " if v.vertexID == cfg.get_exitID(): vertex_choices += "(exit) " print("%s Vertices = %s" % (prompt_prefix, vertex_choices)) startID = parse_input_from_user("Enter start vertex") if not cfg.has_vertex(startID): debug.warning_message("CFG does not have vertex: %d" % startID) else: endID = parse_input_from_user("Enter end vertex") if not cfg.has_vertex(endID): debug.warning_message("CFG does not have vertex: %d" % endID) else: the_query = ((startID, ), (endID, )) regular_expressions.create_path_expression( cfg, the_query) except KeyboardInterrupt: pass
def create_path_expression_between_two_vertices(program): prompt_prefix = "->" def parse_input_from_user(message): the_input = raw_input("%s %s: " % (prompt_prefix, message)).lower() the_input = re.sub(r'\s+', '', the_input) if re.match(r'\d+', the_input): return ast.literal_eval(the_input) return the_input try: while True: cfg = None if len(program.cfgs) == 1: cfg = program.cfgs.itervalues().next() else: print("%s CFGs = {%s}" % (prompt_prefix, ','.join(cfg.name for cfg in program.cfgs.values()))) cfg_name = parse_input_from_user("Enter CFG name") if cfg_name not in program.cfgs: debug.warning_message("Program does not have CFG %s" % cfg_name) else: cfg = program.cfgs[cfg_name] if cfg is not None: vertex_choices = "" for v in cfg: vertex_choices += "%d " % v.vertexID if v.vertexID == cfg.get_entryID(): vertex_choices += "(entry) " if v.vertexID == cfg.get_exitID(): vertex_choices += "(exit) " print("%s Vertices = %s" % (prompt_prefix, vertex_choices)) startID = parse_input_from_user("Enter start vertex") if not cfg.has_vertex(startID): debug.warning_message("CFG does not have vertex: %d" % startID) else: endID = parse_input_from_user("Enter end vertex") if not cfg.has_vertex(endID): debug.warning_message("CFG does not have vertex: %d" % endID) else: the_query = ((startID,), (endID,)) regular_expressions.create_path_expression(cfg, the_query) except KeyboardInterrupt: pass