import statistics import sys import os from glob import glob #DIR = "/home/ederi2t/Tofino_P4rformance/UDPServer/Golang/results/test4_old/" DIR = "/home/ederi2t/Tofino_P4rformance/UDPServer/Golang/results/test4_95g_20B" RES_FILE = "9.5gb_20B_res.txt" result = [y for x in os.walk(DIR) for y in glob(os.path.join(x[0], '*conv_ingress_latency.txt'))] #print(result) meanResults = {} for file in result: name=file.split("/")[8] byteNum = name.split("_")[2].split("B")[0] headerAmount = name.split("-")[-1].split("x")[1][:-3] extractByte = name.split("-")[2].split("B")[0] #print(name) #print(byteNum) #print(headerAmount) #print(extractByte) #sys.exit() latencies = [] with open(file, 'r') as reader: lines = reader.readlines() for line in lines[1:]: ingress_latency = line.split(",")[0] #ingress_latency = line.split(",")[int(sys.argv[0])] latencies.append(int(ingress_latency)) if byteNum not in meanResults: meanResults[byteNum] = [0] * 11 mean=format(statistics.mean(latencies), ".3f") index = 0 if headerAmount == "ETH_O": index = 0 else: index = headerAmount print("%s -> Mean: %s" % (name, mean,)) with open(DIR+"/"+RES_FILE, 'a') as the_file: the_file.write('%s,%s,%s,%s\n' %(extractByte, index, byteNum, mean))