def _filter_with_black_list(self): self._copy_black_list() white_file = '%s/%s/%s' % (self.folder, config.time_dir(), config.time_output_file()) black_file = '%s/%s' % (self.folder, config.black_list_file()) white_methods = self._read_file(white_file) black_methods = self._read_file(black_file) white_method_package = [line for line in white_methods if line not in black_methods and line.startswith(self.program.options.package)] white_method_filtered = [line for line in white_method_package if not '<init>' in line] white_list_file = '%s/%s' % (self.folder, config.white_list_file()) self._write_file(white_list_file, white_method_filtered)
def _filter_tuples(self, depth): white_list = '%s/%s' % (self.folder, config.white_list_file()) tuples_output = '%s/%s/%s' % (self.folder, config.tuples_dir(), config.tuples_output_file()) depths_csv = '%s/%s/%s' % (self.folder, config.tuples_dir(), config.tuples_depths_file()) tuples_final = '%s/%s' % (self.folder, config.tuples_final_file()) hit_rates = '%s/hit_rates_%d.txt' % (self.folder, depth) min_hit_rate = 0.5 running = 'java -cp %s cpb.RefineCandidateMethods %d %f %s %s %s %s %s' % (commons.scala_libs(), depth, min_hit_rate, tuples_output, depths_csv, tuples_final, hit_rates, white_list) self._create_filter_depths_trace() subprocess.call(shlex.split(str(running)))
def refine_candidates(self): # self._filter_with_black_list() # depth = 1 # use_max_depth = not commons.profile_exaustive() # get_next_depth = None if commons.increment_function() == 'inc1': get_next_depth = lambda x: x + 1 elif commons.increment_function() == 'pow2': get_next_depth = lambda x: 2 * x else: if commons.profile_exaustive() == False: raise Exeception( 'Increment function parameter has wrong value -- ' + commons.increment_function()) get_next_depth = None while (True): commons.log('Exploring depth ' + str(depth) + ' -- ' + '"' + self.program.prefix + '"') self._save_white_list(depth) tuple_options = options.TuplesOptions(use_max_depth, depth, True, False) self.program.tuples(tuple_options) self._write_options_to_file( '%s/%s' % (self.folder, config.tuples_dir()), tuple_options) stop = False if self._max_depth_reached(): stop = True # if commons.profile_exaustive() == False: self._filter_tuples(depth) self._save_current_depth_directory(depth) # candidates_list_new = '%s/%s' % (self.folder, config.white_list_file()) number_of_candidates = self._count_lines(candidates_list_new) # if number_of_candidates == 0: commons.log('No caching candidates left to explore' + ' -- ' + str(depth) + ' -- ' + '"' + self.program.prefix + '"') break # if stop: self._create_tuples_file() commons.log('Max depth ' + str(depth) + 'reached' + ' -- ' + '"' + self.program.prefix + '"') break depth = get_next_depth(depth)
def _filter_tuples(self, depth): white_list = '%s/%s' % (self.folder, config.white_list_file()) tuples_output = '%s/%s/%s' % (self.folder, config.tuples_dir(), config.tuples_output_file()) depths_csv = '%s/%s/%s' % (self.folder, config.tuples_dir(), config.tuples_depths_file()) tuples_final = '%s/%s' % (self.folder, config.tuples_final_file()) hit_rates = '%s/hit_rates_%d.txt' % (self.folder, depth) min_hit_rate = 0.5 running = 'java -cp %s cpb.RefineCandidateMethods %d %f %s %s %s %s %s' % ( commons.scala_libs(), depth, min_hit_rate, tuples_output, depths_csv, tuples_final, hit_rates, white_list) self._create_filter_depths_trace() subprocess.call(shlex.split(str(running)))
def _filter_with_black_list(self): self._copy_black_list() white_file = '%s/%s/%s' % (self.folder, config.time_dir(), config.time_output_file()) black_file = '%s/%s' % (self.folder, config.black_list_file()) white_methods = self._read_file(white_file) black_methods = self._read_file(black_file) white_method_package = [ line for line in white_methods if line not in black_methods and line.startswith(self.program.options.package) ] white_method_filtered = [ line for line in white_method_package if not '<init>' in line ] white_list_file = '%s/%s' % (self.folder, config.white_list_file()) self._write_file(white_list_file, white_method_filtered)
def refine_candidates(self): # self._filter_with_black_list() # depth = 1 # use_max_depth = not commons.profile_exaustive() # get_next_depth = None if commons.increment_function() == 'inc1': get_next_depth = lambda x: x + 1 elif commons.increment_function() == 'pow2': get_next_depth = lambda x: 2 * x else: if commons.profile_exaustive() == False: raise Exeception('Increment function parameter has wrong value -- ' + commons.increment_function()) get_next_depth = None while (True): commons.log('Exploring depth ' + str(depth) + ' -- ' + '"' + self.program.prefix + '"') self._save_white_list(depth) tuple_options = options.TuplesOptions(use_max_depth, depth, True, False) self.program.tuples(tuple_options) self._write_options_to_file('%s/%s' % (self.folder, config.tuples_dir()), tuple_options) stop = False if self._max_depth_reached(): stop = True # if commons.profile_exaustive() == False: self._filter_tuples(depth) self._save_current_depth_directory(depth) # candidates_list_new = '%s/%s' % (self.folder, config.white_list_file()) number_of_candidates = self._count_lines(candidates_list_new) # if number_of_candidates == 0: commons.log('No caching candidates left to explore' + ' -- ' + str(depth) + ' -- ' + '"' + self.program.prefix + '"') break # if stop: self._create_tuples_file() commons.log('Max depth ' + str(depth) + 'reached' + ' -- ' + '"' + self.program.prefix + '"') break depth = get_next_depth(depth)
def _copy_time_output_to_white_list(self): from_file = '%s/%s/%s' % (self.folder, config.time_dir(), config.time_output_file()) to_file = '%s/%s' % (self.folder, config.white_list_file()) self._copy_file(from_file, to_file)
def _save_current_depth_directory(self, depth): self._move_file('%s/%s' % (self.folder, config.tuples_dir()), '%s/%d' % (self.folder, depth)) self._move_file( '%s/%d.txt' % (self.folder, depth), '%s/%d/%s' % (self.folder, depth, config.white_list_file()))
def _save_white_list(self, next_depth): self._copy_file('%s/%s' % (self.folder, config.white_list_file()), '%s/%d.txt' % (self.folder, next_depth))
def _save_current_depth_directory(self, depth): self._move_file('%s/%s' % (self.folder, config.tuples_dir()), '%s/%d' % (self.folder, depth)) self._move_file('%s/%d.txt' % (self.folder, depth) , '%s/%d/%s' % (self.folder, depth, config.white_list_file()))