Commit 5398915a authored by Sanjana Sridhar's avatar Sanjana Sridhar
Browse files

more general csv generation

parent 8c8e7226
import csv
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('inputfolder', type=str, default="")
parser.add_argument('outputfolder', type=str, default="")
args = parser.parse_args()
def get_data(path):
f = open(path)
text = f.readlines()
offset = 0
data_needed = ['L1-icache-load-misses', 'instructions', 'l2_rqsts.miss', 'dTLB-load-misses', 'L1-dcache-load-misses', 'iTLB-load-misses']
if text[1].startswith('energy'):
offset = 1
......@@ -19,67 +13,51 @@ def get_data(path):
else:
energy = text[0].split()
energy = float(energy[4])
print(energy)
j = 0
data = []
key_lines = [4, 5, 6, 7, 8, 9, 10]
for i in key_lines:
if i == 6:
data.append(cast(text[i + offset].split(), 3))
else:
data.append(cast(text[i + offset].split(), 0))
for i in range(4, len(text)):
if data_needed[j] in text[i]:
if text[i] == 'instructions':
data.append(cast(text[i].split(), 3))
data.append(cast(text[i].split(), 0))
j += 1
if (len(data) != len(data_needed) + 1):
print("something went wrong")
return energy, data
def cast(input, index):
return float(input[index].replace(',', ''))
files = ['bc', 'bfs', 'cc', 'cc_sv', 'l1_msr', 'l2_msr', 'pr', 'pr_spmv', 'sssp', 'tc', 'tlb_msr']
all_data = []
energy_list = []
files = []
# CREATES CSV FILE OF ENERGIES
with open(args.outputfolder + "/" + 'b_data.csv', 'w') as f:
with open('b_data.csv', 'w') as f:
writer = csv.writer(f)
for filename in os.scandir(args.inputfolder):
energy, data = get_data(filename.path)
files.append(filename.name)
for path in files:
energy, data = get_data(path)
all_data.append(data)
energy_list.append(energy)
# writer.writerow(data)
writer.writerow([energy])
# CREATES INPUT FOR MATRIX A
f1 = open(args.outputfolder + "/" + "A_data", "w")
f1 = open("A_data", "w")
line1 = ""
f2 = open(args.outputfolder + "/" + "temp", "w")
for i in range(len(all_data) - 1):
f2.write(files[i] + "\n")
data = all_data[i]
for j in range(len(data) - 1):
line1 += str(data[j]) + " "
line2 = str(data[j]) + "\n"
f2.write(line2)
line1 += str(data[len(data) - 1]) + "; "
line2 = str(data[len(data)-1]) + "\n"
f2.write(line2)
line2 = str(energy_list[i]) + "\n"
f2.write(line2)
data = all_data[len(all_data) - 1]
f2.write(files[len(all_data)-1] + "\n")
for j in range(len(data) - 1):
line1 += str(data[j]) + " "
line2 = str(data[j]) + "\n"
f2.write(line2)
line1 += str(data[len(data) - 1])
line2 = str(data[len(data)-1]) + "\n"
f2.write(line2)
line2 = str(energy_list[len(all_data)-1]) + "\n"
f2.write(line2)
f2.write(';')
f1.write(line1)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment