Skip to content

Instantly share code, notes, and snippets.

@gspetrou
Created March 29, 2019 01:09
Show Gist options
  • Save gspetrou/acb832f8a82963b2a41c970b8fd88d9f to your computer and use it in GitHub Desktop.
Save gspetrou/acb832f8a82963b2a41c970b8fd88d9f to your computer and use it in GitHub Desktop.
Extracts relevant data from the bunch of benchmark simulations we had and saves the data into an excel spreadsheet
benchmarkFilesDir = "/Users/georgepetrou/Desktop/431_pe3/raw"
outputExcelFilePath = "/Users/georgepetrou/Desktop/431_pe3/output.xlsx"
## Dont edit below here
import os
import mmap
import xlsxwriter
def processData():
processedData = {}
benchmarkFiles = [file for file in os.listdir(benchmarkFilesDir) if os.path.isfile(os.path.join(benchmarkFilesDir, file)) and file.endswith(".simout")]
for fileName in sorted(benchmarkFiles):
fullBenchmarkFilePath = os.path.join(benchmarkFilesDir, fileName)
extractDataFromFile(fullBenchmarkFilePath, fileName, processedData)
return processedData
infoWeWant = ["bpred_nottaken.misses", "bpred_bimod.misses", "bpred_2lev.misses", "bpred_comb.misses", "sim_CPI", "sim_num_insn"]
def extractDataFromFile(path, fileNameOnly, processedData):
processedData[fileNameOnly] = {}
with open(path, 'r') as file:
numMisses = 0
numInstructions = 0
for line in file:
if any(x in line for x in infoWeWant):
info = line.strip().split(None, 2)[:-1]
if "misses" in info[0]:
numMisses = float(info[1])
processedData[fileNameOnly]["Misses"] = numMisses
elif "sim_CPI" in info[0]:
numInstructions = float(info[1])
processedData[fileNameOnly]["CPI"] = numInstructions
if numMisses > 0 and numInstructions > 0:
missPerInstr = "{0:.6f}".format(numInstructions/numMisses)
processedData[fileNameOnly]["MissPerInstr"] = missPerInstr
else:
processedData[fileNameOnly]["MissPerInstr"] = 0
if numMisses <= 0:
processedData[fileNameOnly]["Misses"] = 0
def handleExcelOutput():
workbook = xlsxwriter.Workbook(outputExcelFilePath)
worksheet = workbook.add_worksheet()
curRow = 1
for fileName, fileData in sorted(processedData.items()):
worksheet.write(curRow, 0, fileName[:-7])
worksheet.write(curRow, 1, fileData.get("CPI"))
worksheet.write(curRow, 2, fileData.get("Misses"))
worksheet.write(curRow, 3, fileData.get("MissPerInstr"))
curRow += 1
workbook.close()
if __name__ == "__main__":
processedData = processData()
handleExcelOutput()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment