def wc(fd, name): l = 0 w = 0 c = 0 inword = False # while((n = read(fd, buf, sizeof(buf))) > 0) while True: n, buf = read(fd, 512) if n <= 0: break for i in range(n): c += 1 if buf[i] == "\n": l += 1 if strchr(" \r\t\n\v", buf[i]): inword = False elif not inword: w += 1 inword = True if n < 0: printf(1, "wc: read error\n") exit_(1) printf(1, "%d %d %d %s\n", l, w, c, name)
def run_trace_measure_fp_fn(self): """ Run a trace on a single cache, only to measure the FN, or FP ratio. """ self.hit_cnt = 0 for self.req_cnt in range( self.req_df.shape[0]): # for each request in the trace... self.cur_req = self.req_df.iloc[self.req_cnt] if (self.cur_req.key in self.DS_list[0]): #hit self.hit_cnt += 1 if (self.cur_req.key in self.DS_list[0].stale_indicator): # True positive self.DS_list[0].access(self.cur_req.key) else: # FN self.FN_miss_cnt += 1 self.DS_list[0].insert(key=self.cur_req.key, req_cnt=self.req_cnt, consider_fpr_fnr_update=True) else: # miss self.DS_list[0].insert(key=self.cur_req.key, req_cnt=self.req_cnt, consider_fpr_fnr_update=True) printf( self.output_file, '({}, {})'.format(self.uInterval, self.FN_miss_cnt / self.hit_cnt))
def onButtonClick(x, y): button = buttons[y][x] if button.isOpen == True: return # Print statement that displays col and row no # when a button is clicked printf('Col (x)= %d Row (y)= %d\n', x, y) button.isOpen = True num = str(countMinesAround(x,y)) if button.isMine == True: button['text'] = 'X' elif num == '0': button['text'] = ' ' # Clicking all buttons recursively until # a number is reached for i in range(-1, 2): a = i + x for j in range(-1, 2): b = j + y # Checking for edge cases if(a >= 0 and a < COLS and \ b >= 0 and b < ROWS): onButtonClick(a, b) else: button['text'] = num
def main(argv, argc): #static char buf[100]; #int fd; # Assumes three file descriptors open. # while((fd = open("console", O_RDWR)) >= 0){ while True: fd = open_("console", O_RDWR) if fd < 0: break if fd >= 3: close(fd) break # Read and run input commands. # while(getcmd(buf, sizeof(buf)) >= 0){ while True: n, buf = getcmd(100) if n < 0: break if buf[0] == "c" and buf[1] == "d" and buf[2] == " ": # Clumsy but will have to do for now. # Chdir has no effect on the parent if run in the child. buf = buf[:strlen(buf) - 1] # chop \n if chdir(buf[3:]) < 0: printf(2, "cannot cd %s\n", buf[3:]) continue fork1(runcmd, parsecmd(buf)) # wait() exit_()
def forktest(): printf(1, "fork test\n") for n in range(1000): pid = fork() if pid < 0: break if pid == 0: exit_() if n == 1000: printf(1, "fork claimed to work 1000 times!\n") exit_() while n > 0: if wait() < 0: printf(1, "wait stopped early\n") exit_(1) n -= 1 if wait() != -1: printf(1, "wait got too many\n") exit_(1) printf(1, "fork test OK\n")
def print_bar_k_loc (self): """ Print table of service costs, normalized w.r.t. Opt, in the following format # uInterval FNO_kloc1 FNA_kloc1 FNO_kloc2 FNA_kloc2 FNO_kloc3 FNA_kloc3 # 256 2.0280 1.7800 2.4294 1.1564 2.4859 1.1039 # 1024 2.0280 1.7800 2.4294 1.1564 2.4859 1.1039 """ self.bar_k_loc_output_file = open ("../res/k_loc.dat", "w") printf (self.bar_k_loc_output_file, 'uInterval\t FNO_kloc1\t FNA_kloc1\t FNO_kloc2\t FNA_kloc2\t FNO_kloc3\t FNA_kloc3\n') self.gen_filtered_list(self.list_of_dicts, num_of_req = 4300, missp = 1000) for uInterval in [256, 1024]: if (uInterval==256): printf (self.bar_k_loc_output_file, '{} \t\t' .format (uInterval)) else: printf (self.bar_k_loc_output_file, '{}\t\t' .format (uInterval)) for Kloc in [1, 2, 3]: for alg_mode in ['FNOA', 'FNAA']: opt_cost = self.gen_filtered_list(self.list_of_dicts, uInterval = 256, num_of_DSs = 8, Kloc = Kloc, alg_mode = 'Opt') if (opt_cost == []): opt_cost = self.gen_filtered_list(self.list_of_dicts, uInterval = 1024, num_of_DSs = 8, Kloc = Kloc, alg_mode = 'Opt') opt_cost = opt_cost[0]['cost'] alg_cost = self.gen_filtered_list(self.list_of_dicts, uInterval = uInterval, bpe = 14, num_of_DSs = 8, Kloc = Kloc, alg_mode = alg_mode)[0]['cost'] printf (self.bar_k_loc_output_file, ' {:.4f}\t\t' .format(alg_cost / opt_cost)) printf (self.bar_k_loc_output_file, ' \n')
def print_floor(): print '\n------------------------------------\n' global floor for i in floor: for j in i: printf(str(j)) print ''
def get_mr_given_mr1(self, indications, mr0, mr1, verbose): """ Calculate and return the expected miss prob' of each DS, based on its indication. Input: indications - a vector, where indications[i] is true iff indicator i gave a positive indication. mr0 - a vector. mr0[i] is the estimation (based on historic data) of the miss probab' in cache i, given a neg' ind' by indicator i mr1 - a vector. mr1[i] is the estimation (based on historic data) of the miss probab' in cache i, given a pos' ind' by indicator i Details: The func' does the following: - Update the estimations of Pone ("q") and the hit ratio. - For each DS: - - If indication[i] == True, then assign mr[i] = mr1[i], according to the given history vector. - - Else, assign mr[i] = mr0[i], as estimated by our analysis. - - Handle corner cases (e.g., probabilities calculated are below 0 or above 1) - Returns the vector mr, where mr[i] is the estimated miss ratio of DS i, given its indication """ self.estimate_pr_of_post_ind_and_hit_ratio(indications) for i in range(self.num_of_DSs): if (indications[i]): #positive ind' self.mr[i] = mr1[i] # else: self.mr[i] = 1 if (self.fnr[i] == 0 or self.pr_of_pos_ind_estimation[i] == 1 or self.hit_ratio[i]==1) \ else (1 - self.fpr[i]) * (1 - self.hit_ratio[i]) / (1 - self.pr_of_pos_ind_estimation[i]) # if DS i gave neg' ind', then the estimated prob' that a datum is not in DS i, given a neg' indication for x if (verbose == 4): printf( self.verbose_file, 'mr_0[{}]: by analysis = {}, by hist = {}\n'.format( i, self.mr[i], mr0[i])) self.mr = np.maximum( self.zeros_ar, np.minimum(self.mr, self.ones_ar) ) # Verify that all mr values are feasible - that is, within [0,1]. return self.mr
def factor(self): token = self.current_token if token.type == TYPE_LPAR: self.advance() result = self.expr() if self.current_token.type != TYPE_RPAR: printf("ERROR: missing close parenthesis") return self.advance() return result elif token.type == TYPE_NUMBER: self.advance() return NumberNode(token.value) elif token.type == TYPE_PLUS: self.advance() return PlusNode(self.factor()) elif token.type == TYPE_MINUS: self.advance() return MinusNode(self.factor()) elif token.type == TYPE_NUMBER: self.advance() return NumberNode(self.factor()) elif token.type == TYPE_IDENTIFIER: self.advance() return VarAccessNode(self.factor())
def main(argc, argv): if argc < 2: # @@@ C source has < 1 printf(2, "usage: kill pid...\n") exit_() for i in range(1, argc): kill(atoi(argv[i])) exit_()
def main(argc, argv): if argc != 3: printf(2, "Usage: ln old new\n") exit_() if link(argv[1], argv[2]) < 0: printf(2, "link %s %s: failed\n", argv[1], argv[2]) exit_()
def printEventID(self, event): msgid = str(event['msgid']) color = bcolors.BOLD if msgid is "1": color = bcolors.HEADER if msgid is "5": color = bcolors.OKGREEN if msgid is "3": color = bcolors.OKBLUE printf(color + str(msgid) + bcolors.ENDC)
def print_new_grid(): print "----------------------------------------------------------------------------------" x_count = 0 y_count = 0 for i in new_result_grid: y_count += 1 for j in i: printf(j) x_count += 1 print ''
def main(argc, argv): if argc < 2: printf(2, "Usage: mkdir files...\n") exit_() for i in range(1, argc): if mkdir(argv[i]) < 0: printf(2, "mkdir: %s failed to create\n", argv[i]) break exit_()
def main(argc, argv): if argc < 2: printf(2, "Usage: rm files...\n") exit_() for i in range(1, argc): if unlink(argv[i]) < 0: printf(2, "rm: %s failed to delete\n", argv[i]) break exit_()
def cat(fd): # while((n = read(fd, buf, sizeof(buf))) > 0) while True: n, buf = read(fd, 512) if n <= 0: break write(1, buf, n) if n < 0: printf(1, "cat: read error\n") # @@@ should that be 2? exit_(1)
def update_mr1(self, est_vs_real_mr_output_file=None): """ update the miss-probability in case of a positive indication, using an exponential moving average. """ self.mr1_cur = self.mr1_alpha_over_window * float( self.fp_events_cnt) + self.one_min_mr1_alpha * self.mr1_cur if (est_vs_real_mr_output_file != None): printf( est_vs_real_mr_output_file, 'real_mr1={}, ema_real_mr1={}\n'.format( float(self.fp_events_cnt) / self.mr1_estimation_window, self.mr1_cur)) self.fp_events_cnt = int(0)
def print_grid(): print "----------------------------------------------------------------------------------" x_count = 0 y_count = 0 for i in result_grid: if y_count % 10 == 0: print '' y_count += 1 for j in i: if x_count % 10 == 0: printf(' ') printf(j) x_count += 1 print ''
def print_bar_all_traces (self): """ Print table of service costs, normalized w.r.t. to Opt, in the format below (assuming the tested miss penalty values are 50, 100, and 500): # input FNO50 FNA50 FNO100 FNA100 FNO500 FNA500 # wiki 2.0280 1.7800 2.4294 1.1564 2.4859 1.1039 # gradle 2.5706 2.3600 3.8177 1.3357 4.0305 1.2014 # scarab 2.5036 2.3053 3.2211 1.1940 3.3310 1.1183 # F2 2.3688 2.2609 2.9604 1.1507 3.0546 1.0766 """ self.bar_all_traces_output_file = open ("../res/three_caches.dat", "w") traces = ['wiki', 'gradle', 'scarab', 'umass'] printf (self.bar_all_traces_output_file, 'input \t\t FNO50 \t\t FNA50 \t\t FNO100 \t FNA100 \t FNO500 \t FNA500\n') self.gen_filtered_list(self.list_of_dicts, num_of_req = 1000) for trace in traces: trace_to_print = 'F2\t' if trace == 'umass' else trace printf (self.bar_all_traces_output_file, '{}\t\t' .format (trace_to_print)) for missp in [50, 100, 500]: for alg_mode in ['FNOA', 'FNAA']: opt_cost = self.gen_filtered_list(self.list_of_dicts, trace = trace, cache_size = 10, num_of_DSs = 3, Kloc = 1,missp = missp, alg_mode = 'Opt') \ [0]['cost'] alg_cost = self.gen_filtered_list(self.list_of_dicts, trace = trace, cache_size = 10, bpe = 14, num_of_DSs = 3, Kloc = 1, missp = missp, uInterval = 1000, alg_mode = alg_mode) \ [0]['cost'] printf (self.bar_all_traces_output_file, ' {:.4f} \t' .format(alg_cost / opt_cost)) printf (self.bar_all_traces_output_file, ' \n')
def main(argc, argv): if argc <= 1: wc(0, "") exit_() for i in range(1, argc): fd = open_(argv[i], 0) if fd < 0: printf(1, "wc: cannot open %s\n", argv[i]) # @@@ xv6 had 'cat' for 'wc' exit_() wc(fd, argv[i]) close(fd) exit_()
def parsecmd(st): s = 0 es = s + strlen(st) cmd, s = parseline(st, s, es) dummy, s = peek(st, s, es, "\0") if s != es: printf(2, "leftovers: %s\n", st) panic("syntax") # nulterminate(cmd) return cmd
def print_num_of_caches_plot_abs (self): """ Print a tikz plot of the service cost as a func' of the number of DSs, absolute values """ add_legend_str = None for uInterval in [256, 1024]: if (uInterval == 1024): add_legend_str = self.add_legend_str printf (self.output_file, '%% uInterval = {}\n' .format (uInterval)) for alg_mode in ['Opt', 'FNOA', 'FNAA']: filtered_list = self.gen_filtered_list(self.list_of_dicts, Kloc = 1, missp = 100, alg_mode = alg_mode, uInterval = uInterval) self.print_single_tikz_plot (filtered_list, key_to_sort = 'num_of_DSs', addplot_str = self.add_plot_str_dict[alg_mode], add_legend_str = add_legend_str, legend_entry = self.legend_entry_dict[alg_mode])
def print_cube(): for z in range(0, width): empty = 1 for y in range(0, width): for x in range(0, width): if cube[z][y][x] == '#': empty = 0 if empty == 1: continue print z - offset for y in range(0, width): for x in range(0, width): printf(str(cube[z][y][x])) print '' print '\n\n'
def main(argc, argv): if argc <= 1: cat(0) exit_() for i in range(1, argc): fd = open_(argv[i], 0) if fd < 0: printf(1, "cat: cannot open %s\n", argv[i]) # @@@ should that be 2? exit_() cat(fd) close(fd) exit_()
def startnewGame(): minesArray = random.sample(range(0, rowTimesCol), MINES) for i in range(MINES): printf ("%d ", minesArray[i]) y = 0 for row in buttons: x = 0 for button in row: button['text'] = '?' button.isOpen = False if ((x*ROWS) + y) in minesArray: button.isMine = True else: button.isMine = False x += 1 y += 1
def init_est_vs_real_mr_output_files(self): """ Init per-DS output file, to which the simulator writes data about the estimated mr (conditional miss rates, namely pr of a miss given a negative ind (mr0), or a positive ind (mr1)). The simulator also writes to this data (via Datastore.py) about each access whether it results in a True Positive, True Negative, False Positive, or False negative. """ settings_str = MyConfig.settings_string(self.trace_file_name, self.DS_size, self.bpe, self.req_cnt, self.num_of_DSs, self.k_loc, self.missp, self.bw, self.uInterval, self.alg_mode) self.est_vs_real_mr_output_file = [None] * self.num_of_DSs for ds in range(self.num_of_DSs): self.est_vs_real_mr_output_file[ds] = open( '../res/{}_est_vs_real_mr_ds{}.mr'.format(settings_str, ds), 'w') printf(self.est_vs_real_mr_output_file[ds], '//format: \n')
def make_number(self): decimal_count = 0 num = self.current_char self.advance() while self.current_char != None and (self.current_char.isnumeric() or self.current_char == '.'): if self.current_char == '.': decimal_count += 1 if decimal_count > 1: printf("ERROR: too many decimal points in one number") num += '.' elif self.current_char.isnumeric(): num += self.current_char self.advance() if '.' in num: self.tokens.append(Token(TYPE_NUMBER, float(num))) else: self.tokens.append(Token(TYPE_NUMBER, int(num)))
def main(argc, argv): if argc <= 1: printf(2, "usage: grep pattern [file ...]\n") exit_() pattern = argv[1] if argc <= 2: grep(pattern, 0) exit_() for i in range(2, argc): fd = open_(argv[i], 0) if fd < 0: printf(1, "grep: cannot open %s\n", argv[i]) exit_() grep(pattern, fd) close(fd) exit_()
def run_FN_by_staleness_sim (): max_num_of_req = 1000000 # Shorten the num of requests for debugging / shorter runs DS_cost = calc_DS_cost () output_file = open ("../res/FN_by_staleness.res", "a") print("now = ", datetime.now(), 'running FN_by_staleness sim') for trace_file_name in ['scarab/scarab.recs.trace.20160808T073231Z.15M_req_1000K_3DSs.csv', 'umass/storage/F2.3M_req_1000K_3DSs.csv']: requests = gen_requests (trace_file_name, max_num_of_req) # In this sim', each item's location will be calculated as a hash of the key. Hence we actually don't use the k_loc pre-computed entries. trace_file_name = trace_file_name.split("/")[0] num_of_req = requests.shape[0] printf (output_file, '\n\ntrace = {}\n///////////////////\n' .format (trace_file_name)) for bpe in [2, 4, 8, 16]: tic() sm = sim.Simulator(output_file, trace_file_name, sim.ALG_PGM_FNO_MR1_BY_HIST, requests, DS_cost, bpe = bpe, verbose = sim.CNT_FN_BY_STALENESS, uInterval = 8192, use_given_loc_per_item = True) sm.run_simulator() toc()
def opentest(): printf(stdout, "open test\n") fd = open_("echo", 0) if fd < 0: printf(stdout, "open echo failed!\n") exit_() close(fd) fd = open_("doesnotexist", 0) if fd >= 0: printf(stdout, "open doesnotexist succeeded!\n") exit_() printf(stdout, "open test ok\n")
def print_normalized_plot (self, key_to_sort, uInterval = 0, print_add_legend = True): """ Print a tikz plot of the service cost as a func' of the update interval The print shows FNO and FNA, both normalized w.r.t. Opt """ filtered_list = self.gen_filtered_list (self.list_of_dicts, cache_size = 10, missp = 100, bpe = 14, num_of_req = 1000) # Filter only relevant from the results file opt_cost = self.gen_filtered_list(self.list_of_dicts, cache_size = 10, num_of_DSs = 3, Kloc = 1, missp = 100, alg_mode = 'Opt')[0]['cost'] if (uInterval > 0 ): printf (self.output_file, '%% uInterval = {}\n' .format (uInterval)) for alg_mode in ['FNOA', 'FNAA']: filtered_list = self.gen_filtered_list(self.list_of_dicts, uInterval = uInterval, cache_size = 10, num_of_DSs = 3, Kloc = 1, missp = 100, alg_mode = alg_mode) add_legend_str = self.add_legend_str if print_add_legend else None for dict in filtered_list: dict['cost'] /= opt_cost self.print_single_tikz_plot (filtered_list, key_to_sort = key_to_sort, addplot_str = self.add_plot_str_dict[alg_mode], add_legend_str = add_legend_str, legend_entry = self.legend_entry_dict[alg_mode])
def print_num_of_caches_plot_normalized (self): """ Print a tikz plot of the service cost as a func' of the number of DSs, normalized by the cost of Opt """ opt_list = sorted (self.gen_filtered_list (self.list_of_dicts, alg_mode = 'Opt'), key = lambda i: i['num_of_DSs']) add_legend_str = None for uInterval in [256, 1024]: if (uInterval == 1024): add_legend_str = self.add_legend_str printf (self.output_file, '%% uInterval = {}\n' .format (uInterval)) for alg_mode in ['FNOA', 'FNAA']: filtered_list = self.gen_filtered_list(self.list_of_dicts, Kloc = 1, missp = 100, alg_mode = alg_mode, uInterval = uInterval) for dict in filtered_list: dict['cost'] /= self.gen_filtered_list (opt_list, num_of_DSs = dict['num_of_DSs'])[0]['cost'] # normalize the cost w.r.t. Opt self.print_single_tikz_plot (filtered_list, key_to_sort = 'num_of_DSs', addplot_str = self.add_plot_str_dict[alg_mode], add_legend_str = add_legend_str, legend_entry = self.legend_entry_dict[alg_mode])
def Read_W(_path_train): list_diverse_conditions_w = [] w_files = os.listdir(_path_train) for i_path_train in range(len(w_files)): isExisted = os.path.exists(_path_train) if not isExisted: pf.printf(_path_train) pf.printf('上面列出的路径不存在,请设置正确路径!') else: pass # pf.printf('目录[' + _path_train + ']存在,正在读取...') list_same_condition_w = [] file_content = open(_path_train + str(i_path_train) + ".txt", 'rt') # 将训练数据得到的权重w给出 for line in file_content: list_same_condition_w.append( list(map(float, line.strip("\n").split(',')))) list_diverse_conditions_w.append(list_same_condition_w) return list_diverse_conditions_w
def createtest(): printf(stdout, "many creates, followed by unlink test\n") name = [None, None, None] name[0] = "a" name[2] = "\0" for i in range(52): name[1] = chr(ord("0") + i) fd = open_("".join(name), O_CREATE | O_RDWR) close(fd) name[0] = "a" name[2] = "\0" for i in range(52): name[1] = chr(ord("0") + i) unlink("".join(name)) printf(stdout, "many creates, followed by unlink; ok\n")
def main(): if open_("console", O_RDWR) < 0: mknod("console", 1, 1) open_("console", O_RDWR) dup(0) # stdout dup(0) # stderr while True: printf(1, "init: starting sh\n") pid = fork() if pid < 0: printf(1, "init: fork failed\n") exit() if pid == 0: exec_("sh", argv) printf(1, "init: exec sh failed\n") exit() while True: wpid = wait() if wpid < 0 or wpid == pid: break print(1, "zombie!\n")
def get_Stress_Data(path_stress): isExisted = os.path.exists(path_stress) if not isExisted: pf.printf(path_stress) pf.printf('上面列出的路径不存在,请设置正确路径!') return else: pf.printf('目录[' + path_stress + ']存在,正在读取...') files = os.listdir(path_stress) # 获取当前文档下的文件 list_stress_allfile = [] # 存放加上位移后的所有坐标值的list str_stress_allfile = '' for file in files: # 遍历文件夹 if not os.path.isdir(file): # 判断是否是文件夹,不是文件夹才打开 filename = os.path.basename(file) # 返回文件名 fullpath_input = path_stress + filename # 得到文件夹中每个文件的完整路径 textIO = open(fullpath_input, 'rt') # 以文本形式读取文件 list_stress = [] i_line = 0 for line in textIO: if i_line > 380: continue if i_line > 0: list_line = list(map(float, line.split('\t'))) list_line.pop(0) list_stress.append(list_line[3]) i_line += 1 str_stress_eachfile = ','.join(map(str, list_stress)) textIO.close() list_stress_allfile.append(np.array(list_stress)) str_stress_allfile += str_stress_eachfile + '\n' return np.array(list_stress_allfile), str_stress_allfile.rstrip('\n')
def run_simulator(self): """ Run a simulation, gather statistics and prints outputs """ np.random.seed(self.rand_seed) num_of_req = self.req_df.shape[0] print( 'running', MyConfig.settings_string(self.trace_file_name, self.DS_size, self.bpe, num_of_req, self.num_of_DSs, self.k_loc, self.missp, self.bw, self.uInterval, self.alg_mode)) if (self.alg_mode == ALG_MEAURE_FP_FN): self.run_trace_measure_fp_fn() elif self.alg_mode == ALG_OPT: self.run_trace_opt_hetro() self.gather_statistics() elif (self.alg_mode == ALG_PGM_FNO_MR1_BY_HIST or self.alg_mode == ALG_PGM_FNO_MR1_BY_ANALYSIS): self.run_trace_pgm_fno_hetro() self.gather_statistics() elif (self.alg_mode == ALG_PGM_FNA_MR1_BY_ANALYSIS or self.alg_mode == ALG_PGM_FNA_MR1_BY_HIST or self.alg_mode == ALG_PGM_FNA_MR1_BY_HIST_ADAPT): self.speculate_accs_cost = 0 # Total accs cost paid for speculative accs self.speculate_accs_cnt = 0 # num of speculative accss, that is, accesses to a DS despite a miss indication self.speculate_hit_cnt = 0 # num of hits among speculative accss self.indications = np.array(range(self.num_of_DSs), dtype='bool') self.run_trace_pgm_fna_hetro() self.gather_statistics() # avg_num_of_updates_per_DS = sum (DS.num_of_updates for DS in self.DS_list) / self.num_of_DSs # avg_update_interval = -1 if (avg_num_of_updates_per_DS == 0) else self.req_cnt / avg_num_of_updates_per_DS if (self.verbose == 1): printf( self.output_file, '// spec accs cost = {:.0f}, num of spec hits = {:.0f}'. format(self.speculate_accs_cost, self.speculate_hit_cnt)) else: printf(self.output_file, 'Wrong alg_mode: {:.0f}\n'.format(self.alg_mode))
def main(argc, argv): printf(1, "usertests starting\n") if open_("usertests.ran", 0) >= 0: printf(1, "already ran user tests -- rebuild fs.img\n") exit_() close(open_("usertests.ran", O_CREATE)) opentest() writetest() writetest1() createtest() # mem() # pipe1() # preempt() # exitwait() # # rmdot() # fourteen() # bigfile() # subdir() # concreate() # linktest() # unlinkread() # createdelete() # twofiles() # sharedfd() # dirfile() # iref() # forktest() # bigdir() exectest() exit_()
def outputWorld(self): [x, y] = self.__land.shape for i in range(x): for j in range(y): terrian = self.__land[i][j].getTerrain() creature = self.__land[i][j].getLivingCreature() direction = '-' + creature.getDirection( ).name[:1] if creature is not None else '' creatureName = creature.getSpecies( ).name if creature is not None else '' printf("[%s, %s%s]\t\t\t", terrian.name, creatureName, direction) printf("\r\n") printf("\r\n")
def print_est_mr_func(self): """ print the extimated mr (miss rate) probabilities. """ # Estimate mr0, by letting the clients calculate mr, where they think that all the indications were negative printf( self.est_mr0_output_file, 'mr0={}, '.format( self.client_list[self.client_id].estimate_mr1_mr0_by_analysis( indications=self.zeros_ar, quiet=True))) printf( self.est_mr0_output_file, 'q={}, '.format( self.client_list[self.client_id].pr_of_pos_ind_estimation)) printf( self.est_mr0_output_file, 'hit ratio={}\n'.format( self.client_list[self.client_id].hit_ratio))
def Read_SData(path): isExisted = os.path.exists(path) if not isExisted: pf.printf(path) pf.printf('上面列出的路径不存在,请设置正确路径!') return else: pf.printf('目录[' + path + ']存在,正在读取...') list_different_angle = [] file_content = open(path, 'rt') list_1 = [] list_2 = [] list_3 = [] list_4 = [] list_5 = [] list_6 = [] list_7 = [] list_8 = [] list_angle = [] i = 0 for line in file_content: i += 1 if i % 16 == 1: list_1.append(np.abs(float(line))) elif i % 16 == 2: list_angle.append(float(line)) elif i % 16 == 3: list_2.append(float(line)) elif i % 16 == 5: list_3.append(float(line)) elif i % 16 == 7: list_4.append(float(line)) elif i % 16 == 9: list_5.append(float(line)) elif i % 16 == 11: list_6.append(float(line)) elif i % 16 == 13: list_7.append(float(line)) elif i % 16 == 15: list_8.append(float(line)) else: continue file_content.close() return list_1, list_2, list_3, list_4, list_5, list_6, list_7, list_8, list_angle
def Read_Data_Single(path): """ :param path: 多个static structural数据路径 :param angle_pieces: 数据按照角度分了多少份 :param train_pieces: 训练数据有多少份 :return: """ isExisted = os.path.exists(path) if not isExisted: pf.printf(path) pf.printf('上面列出的路径不存在,请设置正确路径!') return else: pf.printf('目录[' + path + ']存在,正在读取...') files = os.listdir(path) # 获取当前文档下的文件 abandon_files = ["file0.page", "file1.page"] for file in files: file_name = os.path.basename(file) if file_name in abandon_files: os.remove(path + file_name) # 按照角度排序 files = os.listdir(path) files_cut = sorted(files, key=lambda x: int(x[:-4])) # 真实的所有角度的数据 list_different_angle = [] # 训练用的提取出的角度数据 list_selected_train_data_angle = [] angle_arr = ["0", "24", "48", "72"] # 取出所有的数据,因为前面排序好了,取出来就是先按照角度排序,后按照力排序的数据 for file in files_cut: file_content = open(path + os.path.basename(file), 'rt') first_line = file_content.read() each_ele = first_line.split() list_different_angle.append(np.abs(float(each_ele[-1]))) file_content.close() # 根据文件名判断是不是训练数据 which_angle = str(int(file[:-4]) - 1) # 因为apdl导出的文件一直是从1开始 # 取出训练的数据 if which_angle in angle_arr: list_selected_train_data_angle.append( np.abs(float(each_ele[-1].strip()))) return np.asarray(list_different_angle), np.asarray( list_selected_train_data_angle)
# list_stress = [] # for angle in list_simulation_data[8]: # dict_1[angle] = [] # # list1 = sorted(list(set(list_simulation_data[8])), key=lambda x: int(x)) # for angle, stress in zip(list_simulation_data[8][0:num], list_test_data[1][0][0:num]): # dict_1[angle].append(stress) # print(dict_1) # for value in sorted(dict_1): # list_stress.append(np.average(dict_1[value], axis=-1)) # 创建文件夹 mkdir(path_test + load) # 读取RBF训练的权重w数据 isExisted = os.path.exists(path_train) if not isExisted: pf.printf(path_train) pf.printf('上面列出的路径不存在,请设置正确路径!') else: pf.printf('目录[' + path_train + ']存在,正在读取...') list_w = [] file_content = open(path_train, 'rt') # 将训练数据得到的权重w给出 for line in file_content: list_w.append(list(map(float, line.strip("\n").split(',')))) def Read_Data_Single(path): """ :param path: 多个static structural数据路径 :param angle_pieces: 数据按照角度分了多少份 :param train_pieces: 训练数据有多少份
def ls(path): fd = open_(path, 0) if fd < 0: printf(2, "ls: cannot open %s\n", path) return n, st = fstat(fd) if n < 0: printf(2, "ls: cannot stat %s\n", path) close(fd) return if st.type == T_FILE: printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size) elif st.type == T_DIR: if strlen(path) + 1 + DIRSIZ + 1 > 512: printf(1, "ls: path too long\n") else: prefix = path + "/" #while (read(fd, &de, sizeof(de)) == sizeof(de)) while True: n, de = read(fd, 20) # @@@ 20 = sizeof(de) if n != 20: break de_inum = int(de[:6]) de_name = de[6:].strip() # @@@ if de_inum == 0: continue path = prefix + de_name n, st = stat(path) if n < 0: printf(1, "ls: cannot stat %s\n", path) continue printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size) close(fd)
f = sys.stdin.read().splitlines() else: filename = sys.argv[1] f = open(filename, 'r') csv = csv.reader(f) data = list(csv) for row in data: r = row[5-1] t = row[20-1] # remove leading text from description r = re.sub('\$.* per ', '', r) r = re.sub('USD .* per ', '', r) r = re.sub('RDS.*running ', '', r) # remove instance name from description r = re.sub(',', '', r) r = re.sub(' ' + t + ' .*', '', r) r = re.sub(' db.m4.10xl res.*', '', r) for n in range(len(row)): if (n+1) in a: if (n+1) == 50: print "%s" % (row[n]) else: if (n+1) == 5: printf("%s|", (r)) else: printf("%s|", (row[n])) except Exception, e: print "Error reading from file:"
def runcmd(cmd): p = [0, 0] if cmd == 0: exit_() if cmd.type == EXEC: ecmd = cmd if ecmd.argv[0] == 0: exit_() exec_(ecmd.argv[0], ecmd.argv) printf(2, "exec %s failed\n", ecmd.argv[0]) elif cmd.type == REDIR: rcmd = cmd close(rcmd.fd) if open_(rcmd.file, rcmd.mode) < 0: printf(2, "open %s failed\n", rcmd.file) exit_() runcmd(rcmd.cmd) elif cmd.type == LIST: lcmd = cmd # if fork1() == 0: # runcmd(lcmd.left) # wait() # runcmd(lcmd.right) fork1(runcmd, lcmd.left) wait() runcmd(lcmd.right) elif cmd.type == PIPE: pcmd = cmd if pipe(p) < 0: panic("pipe") if fork1() == 0: close(1) dup(p[1]) close(p[0]) close(p[1]) runcmd(pcmd.left) if fork1() == 0: close(0) dup(p[0]) close(p[0]) close(p[1]) runcmd(pcmd.right) close(p[0]) close(p[1]) wait() wait() elif cmd.type == BACK: bcmd = cmd if fork1() == 0: runcmd(bcmd.cmd) else: panic("runcmd") exit_()
""" Use for testing printf.py """ from printf import printf printf("THIS IS A TEST OF THE PRINTF WITH NO SPEED ARGUMENT GIVEN TO INPUT") printf("THIS IS A TEST OF THE PRINTF WITH A SPEED ARGUMENT OF 1ms", 1) printf("THIS IS A TEST OF THE PRINTF WITH A SPEED ARGUMENT OF 100ms", 100) printf(''' Eu non duis amet aliquip minim ad ad cillum commodo pariatur deserunt voluptate ad. Exercitation id adipisicing pariatur commodo eiusmod officia magna qui duis anim non exercitation aliqua. Sunt ipsum veniam tempor sit ex adipisicing ipsum proident ut minim irure velit adipisicing mollit. Cillum nulla et aliquip minim commodo ad cupidatat enim amet eiusmod laborum magna voluptate culpa. MULTI-LINE TEST COMPLETE. ''')
def print_tbl (self): """ Print table of service costs, normalized w.r.t. to Opt, in tikz format """ self.tbl_output_file = open ("../res/tbl.dat", "w") traces = ['wiki', 'gradle', 'scarab', 'umass'] printf (self.tbl_output_file, '\tMiss Penalty & Policy ') for trace in traces: trace_to_print = 'F2' if trace == 'umass' else trace printf (self.tbl_output_file, '& {}' .format (trace_to_print)) printf (self.tbl_output_file, '\\\\\n\t\\hline\n\t\\hline\n') self.gen_filtered_list(self.list_of_dicts, num_of_req = 1000) for missp in [40, 400, 4000]: printf (self.tbl_output_file, '\t\\multirow{3}{*}{') printf (self.tbl_output_file, '{}' .format (missp)) printf (self.tbl_output_file, '}\n') for alg_mode in ['FNOA', 'FNAA']: if (alg_mode == 'FNOA'): printf (self.tbl_output_file, '\t&$\\fno$' .format(alg_mode)) if (alg_mode == 'FNAA'): printf (self.tbl_output_file, '\t&$\\fna$' .format(alg_mode)) for trace in traces: opt_cost = self.gen_filtered_list(self.list_of_dicts, trace = trace, cache_size = 10, num_of_DSs = 3, Kloc = 1, missp = missp, alg_mode = 'Opt')[0]['cost'] alg_cost = self.gen_filtered_list(self.list_of_dicts, trace = trace, cache_size = 10, bpe = 14, num_of_DSs = 3, Kloc = 1, missp = missp, uInterval = 1000, alg_mode = alg_mode)[0]['cost'] printf (self.tbl_output_file, ' & {:.4f}' .format(alg_cost / opt_cost)) printf (self.tbl_output_file, ' \\\\\n') printf (self.tbl_output_file, '\t\\hline\n\n')
import printf series = {0: 1, 1: 1} def fib(n): if (series.has_key(n)): return series[n] else: series[n] = fib(n - 1) + fib(n - 2) return series[n] x = int(raw_input("Enter a number: --->")) if x < 0: print "Input Correct No." else: for i in range(0, x): printf.printf(str(fib(i)) + ",")
def writetest(): printf(stdout, "small file test\n") fd = open_("small", O_CREATE | O_RDWR) if fd >= 0: printf(stdout, "creat small succeeded; ok\n") else: printf(stdout, "error: creat small failed!\n") exit_() for i in range(100): if write(fd, "aaaaaaaaaa", 10) != 10: printf(stdout, "error: write aa %d new file failed\n", i) exit_() if write(fd, "bbbbbbbbbb", 10) != 10: printf(stdout, "error: write bb %d new file failed\n", i) exit_() printf(stdout, "writes ok\n") close(fd) fd = open_("small", O_RDONLY) if fd >= 0: printf(stdout, "open small succeeded ok\n") else: printf(stdout, "error: open small failed!\n") exit_() i, buf = read(fd, 2000) if i == 2000: printf(stdout, "read succeeded ok\n") else: printf(stdout, "read failed\n") exit_() close(fd) if unlink("small") < 0: printf(stdout, "unlink small failed\n") exit_() printf(stdout, "small file test ok\n")
def exectest(): printf(stdout, "exec test\n") if exec_("echo", echoargv) < 0: printf(stdout, "exec echo failed\n") exit_()
def writetest1(): buf = "\0" * 2048 printf(stdout, "big files test\n") fd = open_("big", O_CREATE | O_RDWR) if fd < 0: printf(stdout, "error: creat big failed!\n") exit_() for i in range(MAXFILE): buf = chr(i % 256) + buf[1:] if write(fd, buf, 512) != 512: printf(stdout, "error: write big file failed\n", i) exit_() close(fd) fd = open_("big", O_RDONLY) if fd < 0: printf(stdout, "error: open big failed!\n") exit_() n = 0 while True: i, buf = read(fd, 512) if i == 0: if n == MAXFILE - 1: printf(stdout, "read only %d blocks from big", n) exit_() break elif i != 512: printf(stdout, "read failed %d\n", i) exit_() if buf[0] != chr(n % 256): printf(stdout, "read content of block %d is %d\n", n, buf[0]) exit_() n += 1 close(fd) if unlink("big") < 0: printf(stdout, "unlink big failed\n") exit_() printf(stdout, "big files ok\n")
def print_single_tikz_plot (self, list_of_dict, key_to_sort, addplot_str = None, add_legend_str = None, legend_entry = None): """ Prints a single plot in a tikz format. Inputs: The "x" value is the one which the user asks to sort the inputs (e.g., "x" value may be the cache size, uInterval, etc). The "y" value is the cost for this "x". list_of_dicts - a list of Python dictionaries. key_to_sort - the function sorts the items by this key, e.g.: cache size, uInterval, etc. addplot_str - the "add plot" string to be added before each list of points (defining the plot's width, color, etc.). addlegend_str - the "add legend" string to be added after each list of points. legend_entry - the entry to be written (e.g., 'Opt', 'Alg', etc). """ if (not (addplot_str == None)): printf (self.output_file, addplot_str) for dict in sorted (list_of_dict, key = lambda i: i[key_to_sort]): printf (self.output_file, '({:.0f}, {:.04f})' .format (dict[key_to_sort], dict['cost'])) printf (self.output_file, self.end_add_plot_str) if (not (add_legend_str == None)): # if the caller requested to print an "add legend" str printf (self.output_file, '\t\t{}{}' .format (self.add_legend_str, legend_entry)) printf (self.output_file, '}\n') printf (self.output_file, '\n\n')
def draw_canvas(canvas): with open("output.txt", "w") as outFile: for row in canvas: for c in row: printf(c, outFile) print >> outFile
def panic(s): printf(2, "%s\n", s) exit_()
def main(argc, argv): for i in range(1, argc): printf(1, "%s%s", argv[i], " " if i + 1 < argc else "\n") exit_()
def getcmd(nbuf): printf(2, "$ ") n, buf = gets(nbuf) if buf[0] == 0: # EOF return -1, buf return 0, buf
from dropbox.client.watchdog import Watchdog2, WatchdogThread from dropbox.client.authenticate import AuthenticationThread from dropbox.client.unlink_cookie import read_unlink_cookie, write_unlink_cookie, write_unlink_cookie_no_sync_engine, UNLINK_COOKIE_PREFS from dropbox.client.wipe import delete_data from dropbox.client.update import UpgradeLogic from dropbox.client.mapreduce import DBKeyStore, CLIENT_KEY_NAME import dropbox.client.photouploader from dropbox.client.photocontroller import CameraController from dropbox.client.screenshots import ScreenshotsCallbacks from dropbox.client.screenshots import ScreenshotsController from dropbox.client.status import StatusController from ui.icon_overlay import StatusThread from ui.common.tray import TrayController if feature_enabled('cffi-printf-on-startup'): from printf import printf printf('CFFI is working!\n') except Exception: import traceback import sys import os traceback.print_exc() sys.stdout.flush() sys.stderr.flush() os._exit(-2) MEMORY_TRACKER_ENABLED = True FATALDB_RESTART_TIMEOUT = 60 * 60 class DropboxApplication(object): def __init__(self, unicode_argv):