def replay_invocations(self, force): if not os.path.isfile("{0}/{1}.invocations".format( var.CERE_TRACES_PATH, self.region)): logger.error("No invocation file for region {0}".format( self.region)) return False err = False clust = 0 with open("{0}/{1}.invocations".format( var.CERE_TRACES_PATH, self.region)) as invocation_file: for line in invocation_file: self.force = False res = True clust = clust + 1 infos = line.strip().split() self.invocation = infos[0] self.invitro_callcount = 10 #Dump the required invocation cere_capture.run(self) #Replay it and compute error between invivo and invitro cycles for this invocation self.force = force if not cere_replay.run(self): err = True invitro_cycles = 0. else: try: if not os.path.isfile("{0}/{1}_{2}.csv".format( var.CERE_REPLAY_PATH, self.region, self.invocation)): shutil.move( "{0}.csv".format(self.region), "{0}/{1}_{2}.csv".format( var.CERE_REPLAY_PATH, self.region, self.invocation)) except IOError as err: logger.error(str(err)) logger.error( "No results file. Maybe replay failed for {0} invocation {1}" .format(self.region, self.invocation)) err = True invitro_cycles = 0. else: with open("{0}/{1}_{2}.csv".format( var.CERE_REPLAY_PATH, self.region, self.invocation)) as invitro: reader = csv.DictReader(invitro) for row in reader: invitro_cycles = float( row["CPU_CLK_UNHALTED_CORE"]) / float( row["Call Count"]) matching_err = compute_error(invitro_cycles, float(infos[2])) #Aggregate invocations cycles, needed to compute invitro measure for the codelet self.invitro_cycles = self.invitro_cycles + invitro_cycles * float( infos[1]) self.invocations_data.append([ infos[0], clust, infos[1], invitro_cycles, infos[2], matching_err ]) return not err
def replay_invocations(self, force): if not os.path.isfile("{0}/{1}.invocations".format(var.CERE_TRACES_PATH, self.region)): logger.error("No invocation file for region {0}".format(self.region)) return False err=False clust=0 with open("{0}/{1}.invocations".format(var.CERE_TRACES_PATH, self.region)) as invocation_file: for line in invocation_file: self.force = False res=True clust = clust + 1 infos = line.strip().split() self.invocation = infos[0] self.invitro_callcount = 10 #Dump the required invocation cere_capture.run(self) #Replay it and compute error between invivo and invitro cycles for this invocation self.force = force if not cere_replay.run(self): err=True invitro_cycles = 0. else: try: if not os.path.isfile("{0}/{1}_{2}.csv".format(var.CERE_REPLAY_PATH, self.region, self.invocation)) or self.force: shutil.move("{0}.csv".format(self.region), "{0}/{1}_{2}.csv".format(var.CERE_REPLAY_PATH, self.region, self.invocation)) except IOError as err: logger.error(str(err)) logger.error("No results file. Maybe replay failed for {0} invocation {1}".format(self.region, self.invocation)) err=True invitro_cycles = 0. else: with open("{0}/{1}_{2}.csv".format(var.CERE_REPLAY_PATH, self.region, self.invocation)) as invitro: reader = csv.DictReader(invitro) for row in reader: invitro_cycles = float(row["CPU_CLK_UNHALTED_CORE"]) / float(row["Call Count"]) matching_err = compute_error(invitro_cycles, float(infos[2])) #Aggregate invocations cycles, needed to compute invitro measure for the codelet self.invitro_cycles = self.invitro_cycles + invitro_cycles * float(infos[1]) self.invocations_data.append([infos[0], clust, infos[1], invitro_cycles, infos[2], matching_err]) return not err
def run(args): if not cere_configure.init(): return False profile_file = "{0}/app.prof".format(var.CERE_PROFILE_PATH) regions_file = cere_configure.cere_config["regions_infos"] new_regions_file = "tmp.csv" logger.info("Removing previous regions list") if os.path.isfile(regions_file): os.remove(regions_file) if args.dynamic: args.static = True if not args.static and not args.dynamic: args.static = True args.dynamic = True if(args.static): mydump = Dump() res = cere_capture.run(mydump) logger.info("Regions list dumped in {0} file".format(regions_file)) if not res: logger.warning("Regions listing encountered and error: list may be incomplete or empty") if(args.dynamic): if not os.path.isfile(profile_file): logger.critical('No profiling file. Please run cere profile') return False if not os.path.isfile(regions_file): logger.critical('Regions file does not exists. Please re-run cere regions with static enabled.') return False build_cmd = cere_configure.cere_config["build_cmd"] run_cmd = cere_configure.cere_config["run_cmd"] #Build again the application to be sure we give the right binary to pprof try: logger.debug(subprocess.check_output("{0} MODE=\"original --instrument --instrument-app\" -B".format(build_cmd), stderr=subprocess.STDOUT, shell=True)) except subprocess.CalledProcessError as err: logger.error(str(err)) logger.error(err.output) return False binary = which(run_cmd) if not binary: logger.critical("Cannot find the binary. Please provide binary name through cere configure --binary") return False add_header(regions_file, new_regions_file) #regular expression to parse the gperf tool output regex_list = [r'(N.*)\s\[label\=\"(.*?)\\n([0-9]*)\s\((.*)\%\)\\rof\s(.*)\s\((.*)\%\)\\r', r'(N.*)\s\[label\=\"(.*)\\n([0-9]*)\s\((.*)\%\)\\r', r'(N.*)\s\-\>\s(N.*)\s\[label\=([0-9]*)\,'] cmd = subprocess.Popen("pprof -dot {0} {1}".format(binary, profile_file), shell=True, stdout=subprocess.PIPE) for line in cmd.stdout: matchObj, step = parse_line(regex_list, line) if step < 2 : add_coverage(regions_file, new_regions_file, matchObj) else: continue try: shutil.move(new_regions_file, regions_file) except IOError as err: logger.critical(str(err)) logger.error(err.output) return False return True
def run(args): if not cere_configure.init(): return False profile_file = "{0}/app.prof".format(var.CERE_PROFILE_PATH) regions_file = cere_configure.cere_config["regions_infos"] new_regions_file = "tmp.csv" logger.info("Removing previous regions list") if os.path.isfile(regions_file): os.remove(regions_file) if args.dynamic: args.static = True if not args.static and not args.dynamic: args.static = True args.dynamic = True if (args.static): mydump = Dump() res = cere_capture.run(mydump) logger.info("Regions list dumped in {0} file".format(regions_file)) if not res: logger.warning( "Regions listing encountered and error: list may be incomplete or empty" ) if (args.dynamic): if not os.path.isfile(profile_file): logger.critical('No profiling file. Please run cere profile') return False if not os.path.isfile(regions_file): logger.critical( 'Regions file does not exists. Please re-run cere regions with static enabled.' ) return False build_cmd = cere_configure.cere_config["build_cmd"] run_cmd = cere_configure.cere_config["run_cmd"] #Build again the application to be sure we give the right binary to pprof try: logger.debug( subprocess.check_output( "{0} MODE=\"original --instrument --instrument-app\" -B". format(build_cmd), stderr=subprocess.STDOUT, shell=True)) except subprocess.CalledProcessError as err: logger.error(str(err)) logger.error(err.output) return False binary = which(run_cmd) if not binary: logger.critical( "Cannot find the binary. Please provide binary name through cere configure --binary" ) return False add_header(regions_file, new_regions_file) #regular expression to parse the gperf tool output regex_list = [ r'(N.*)\s\[label\=\"(.*?)\\n([0-9]*)\s\((.*)\%\)\\rof\s(.*)\s\((.*)\%\)\\r', r'(N.*)\s\[label\=\"(.*)\\n([0-9]*)\s\((.*)\%\)\\r', r'(N.*)\s\-\>\s(N.*)\s\[label\=([0-9]*)\,' ] cmd = subprocess.Popen("pprof -dot {0} {1}".format( binary, profile_file), shell=True, stdout=subprocess.PIPE) for line in cmd.stdout: matchObj, step = parse_line(regex_list, line) if step < 2: add_coverage(regions_file, new_regions_file, matchObj) else: continue try: shutil.move(new_regions_file, regions_file) except IOError as err: logger.critical(str(err)) logger.error(err.output) return False return True