From 4e77a823cbd989acf9af926ad688239593491ebe Mon Sep 17 00:00:00 2001 From: Hamed Gorjiara Date: Thu, 4 Oct 2018 11:51:24 -0700 Subject: [PATCH] Parser for the tuner's log file --- src/autotunerparser.py | 83 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/autotunerparser.py diff --git a/src/autotunerparser.py b/src/autotunerparser.py new file mode 100644 index 0000000..1632f4b --- /dev/null +++ b/src/autotunerparser.py @@ -0,0 +1,83 @@ +import re +import argparse +import sys + + +class AutoTunerArgParser: + def __init__(self): + self.parser = argparse.ArgumentParser(description='Parsing the output log of the CSolver auto tuner ...') + self.parser.add_argument('--file', '-f', metavar='out.log', type=str, nargs=1,help='output log of running the autotuner ...') + self.args = self.parser.parse_args() + + def getFileName(self): + return self.args.file[0] + +configs = {"EXECTIME": "-", + "SATTIME":"-", + "TESTCASE":"-", + "PREPROCESS" : "-", + "ELEMENTOPT" : "-", + "ELEMENTOPTSETS" : "-", + "PROXYVARIABLE" : "-", + "#SubGraph" : "-", + "NODEENCODING" : "-", + "EDGEENCODING" : "-", + "NAIVEENCODER" :"-", + "ENCODINGGRAPHOPT" : "-" + } + +REGEXES = {"EXECTIME": "CSOLVER solve time: (.*)", + "SATTIME":"SAT Solving time: (.*)", + "TESTCASE": "deserializing (.+) ...", + "PREPROCESS" : "Param PREPROCESS = (.*)range=\[0,1\]", + "ELEMENTOPT" : "Param ELEMENTOPT = (.*)range=\[0,1\]", + "ELEMENTOPTSETS" : "Param ELEMENTOPTSETS = (.*)range=\[0,1\]", + "PROXYVARIABLE" : "Param PROXYVARIABLE = (.*)range=\[1,5\]", + "#SubGraph" : "#SubGraph = (.*)", + "NODEENCODING" : "Param NODEENCODING = (.*)range=\[0,3\](.*)", + "EDGEENCODING" : "Param EDGEENCODING = (.*)range=\[0,2\](.*)", + "NAIVEENCODER" : "Param NAIVEENCODER = (.*)range=\[1,3\](.*)", + "ENCODINGGRAPHOPT" : "Param ENCODINGGRAPHOPT = (.*)range=\[0,1\]" + } + +def printHeader(file): + global configs + mystr="" + for config in configs: + mystr+=str(config)+"," + print >>file, mystr + +def printConfig(file, data): + print data + mystr="" + for config in data: + mystr+=str(data[config])+"," + print >> file, mystr + +def main(): + global configs + argprocess = AutoTunerArgParser() + output = open("tuner.csv", "w") + printHeader(output) + with open(argprocess.getFileName()) as file: + for line in file: + if line.startswith("Mutating"): + printConfig(output,configs) + elif line.startswith("Best tuner"): + printConfig(output,configs); + else : + for regex in REGEXES: + p = re.compile(REGEXES[regex]) + token = p.search(line) + if token is not None: + if regex == "TESTCASE": + configs[regex] = re.search(REGEXES[regex], line).group(1) + else: + configs[regex] = re.findall("\d+\.?\d*", line)[0] + + configs["EXECTIME"] = "BEST TUNE:" + printConfig(output, configs) + print "Done with parsing " + argprocess.getFileName() + +if __name__ == "__main__": + main() -- 2.34.1