def _get_data_list(self): cpu_core = 8 worker_process = cpu_core*2 + 1 all_test = {} for path ,dirs ,files in os.walk(self.data_path): for file in files: one_test_cpu_list,one_test_mem_list = [],[] if file.endswith("_K.log"): with open(path + file,'r') as f: print file lines = f.readlines() new_lines = [] for line in lines: line = line.rstrip('\n').split() if not check_isDigit(line[8]) or not check_isDigit(line[9]): continue else: new_lines.append(line) for every_17_line_of_list in F(new_lines,worker_process): every_17_cpu_usage,every_17_mem_usage = 0,0 for every_line_of_list in every_17_line_of_list: single_cpu,single_mem = float(every_line_of_list[8]),float(every_line_of_list[9]) every_17_cpu_usage += single_cpu every_17_mem_usage += single_mem one_test_cpu_list.append(every_17_cpu_usage/cpu_core) one_test_mem_list.append(every_17_mem_usage) all_test[file] = { "cpu":one_test_cpu_list, "mem":one_test_mem_list, } # print all_test return all_test
def get_avgCPUList(path,filename): del avgCPUList[:] cpuFile=path+'/'+filename file_object = open(cpuFile) try: cpu_lines = file_object.readlines( ) for cpu_line in cpu_lines: fileds_line=cpu_line.split() if isDigit.check_isDigit(fileds_line[8]) != 1: continue else: cpu_field=float(fileds_line[8]) singlcore_cpu=cpu_field/cpu_cores avgCPUList.append(singlcore_cpu) finally: file_object.close( ) return avgCPUList