Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import csv
- path = os.listdir("C:\\Users\\elias\\Documents")
- CompletePath = "C:\\Users\\elias\\Documents\\Complete"
- #Combine logfiles
- for file in path:
- output_line = ""
- first_bench = file.partition("-")[0]
- if file.startswith("4"):
- with open(file, 'r') as input_file, open(os.path.join(CompletePath, 'ALL.txt'), 'a') as output_file:
- lines = input_file.read().splitlines()
- if first_bench in lines[0]:
- for line in lines:
- output_line += line
- output_line += " "
- else:
- #swap lines
- lines[0], lines[1] = lines[1], lines[0]
- for line in lines:
- output_line += line
- output_line += " "
- #Columns in right order
- output_line = output_line.split(" ")
- output_line[1], output_line[2] = output_line[2], output_line[1]
- output_line = " ".join(output_line)
- output_file.write(output_line)
- output_file.write("\n")
- #Create seperate files for each program
- if __name__ == '__main__':
- benchmark_list = ['400.perlbench.sh', '401.bzip2.sh', '403.gcc.sh', '429.mcf.sh', '445.gobmk.sh', '456.hmmer.sh', '458.sjeng.sh', '462.libquantum.sh', '464.h264ref.sh', '471.omnetpp.sh', '473.astar.sh', '483.xalancbmk.sh']
- for benchmark in benchmark_list:
- with open(os.path.join(CompletePath, 'ALL.txt'), 'r') as input_file, open(os.path.join(CompletePath,'{}.txt'.format(benchmark)), 'w') as output_file:
- lines = input_file.read().splitlines()
- output_data = []
- for line in lines:
- columns = line.split(' ')
- if benchmark in line:
- if benchmark in columns[0]:
- output_data.append(" ".join(columns))
- else:
- columns[0], columns[1] = columns[1], columns[0]
- columns[2], columns[3] = columns[3], columns[2]
- output_data.append(" ".join(columns))
- output_data = sorted(output_data, key=lambda x: float(x.split(" ")[2]), reverse=True)
- for line in output_data:
- output_file.write(line)
- output_file.write("\n")
- #Convert all files to .csv
- os.chdir(CompletePath)
- for filename in os.listdir(CompletePath):
- txt_file = filename
- csv_file = filename.replace('.txt', '.csv')
- in_txt = csv.reader(open(txt_file, 'r'), delimiter = ' ')
- out_csv = csv.writer(open(csv_file, 'w'))
- out_csv.writerows(in_txt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement