from collections import defaultdict
import sys

def main(name):
    with open(name) as f:
        lines = f.readlines()

        d = defaultdict(defaultdict)
        
        for line in lines:
            line = line[:-1]
            if "Inputsize" in line:
                inputsize = int(line.split()[1])
                batchsize = int(line.split()[3])
                continue
            if "Trying" in line:
                method = line.split()[2][1:-1]
                continue
            if "avg." in line:
                d[(inputsize, batchsize, method)][line.split()[0]] = float(line.split()[line.split().index("(avg.") + 1])
                continue
            if "Runtime:" in line:
                d[(inputsize, batchsize, method)]["Runtime"] = float(line.split()[1])
                continue

    print("inputsize,batchsize,method,Runtime,backward,optimizer,norm,linear,layer_norm,weighted_sum")
    for name, value in d.items():
        print(f"{name[0]},{name[1]},{name[2]},{value['Runtime']},{value['backward']},{value['optimizer']},{value['norm']},{value['linear']},{value['layer_norm']},{value['weighted_sum']}")
        
if __name__ == "__main__":
    main(sys.argv[1])