105 lines
3.0 KiB
Python
105 lines
3.0 KiB
Python
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
import matplotlib.mlab as mlab
|
|
import numpy as np
|
|
import sys
|
|
import re
|
|
import os
|
|
import json
|
|
import getopt
|
|
import math
|
|
import concurrent.futures as CF
|
|
import libpar as par
|
|
|
|
num_bins = 250
|
|
extra_pct = []
|
|
|
|
def saveplot(fp : str, data : [], title : str):
|
|
plt.hist(data, num_bins)
|
|
plt.xlabel("Delay")
|
|
plt.title(title)
|
|
plt.ylabel("Frequency")
|
|
f = plt.gcf()
|
|
f.set_size_inches(11.69, 8.27)
|
|
f.savefig(fp + "_" + title + "_" + ".png", dpi=160)
|
|
plt.clf()
|
|
print("Generated - " + fp + "_" + title + "_" + ".png")
|
|
|
|
executor = CF.ProcessPoolExecutor(max_workers=int(os.cpu_count()))
|
|
|
|
def clean_data(dat: []):
|
|
ret = []
|
|
arr = np.array(dat)
|
|
cutoff = np.percentile(arr, 99)
|
|
for i in arr:
|
|
if i <= cutoff:
|
|
ret.append(i)
|
|
return ret
|
|
|
|
def process_file(each_dir):
|
|
try:
|
|
print("Processing " + each_dir + " ...")
|
|
with open(each_dir, 'r') as f:
|
|
parser = par.khat_parser()
|
|
parser.parse(f.read())
|
|
|
|
sh = []
|
|
ss = []
|
|
ch = []
|
|
cs = []
|
|
for pt in parser.datapt:
|
|
sh.append(pt.s_htx - pt.s_hrx)
|
|
ss.append(pt.s_stx - pt.s_srx)
|
|
ch.append(pt.c_hrx - pt.c_htx)
|
|
cs.append(pt.c_srx - pt.c_stx)
|
|
|
|
sh = clean_data(sh)
|
|
ss = clean_data(ss)
|
|
ch = clean_data(ch)
|
|
cs = clean_data(cs)
|
|
|
|
saveplot(each_dir, sh, "server_hw_delay")
|
|
saveplot(each_dir, ss, "server_sw_delay")
|
|
saveplot(each_dir, ch, "client_hw_delay")
|
|
saveplot(each_dir, cs, "client_sw_delay")
|
|
|
|
# output median, etc.
|
|
with open(each_dir + "_" + "stats.txt", 'w') as f:
|
|
f.write("===================== SERVER HW ====================\n")
|
|
f.write(par.mutilate_data.build_mut_output(sh, [len(sh)]))
|
|
f.write("\n===================== SERVER SW ====================\n")
|
|
f.write(par.mutilate_data.build_mut_output(ss, [len(ss)]))
|
|
f.write("\n===================== CLIENT HW ====================\n")
|
|
f.write(par.mutilate_data.build_mut_output(ch, [len(ch)]))
|
|
f.write("\n===================== CLIENT SW ====================\n")
|
|
f.write(par.mutilate_data.build_mut_output(cs, [len(cs)]))
|
|
|
|
except Exception:
|
|
print("Unexpected error:", sys.exc_info())
|
|
|
|
def process_dir(rootdir):
|
|
for subdir in os.listdir(rootdir):
|
|
each_dir = os.path.join(rootdir, subdir)
|
|
if os.path.isfile(each_dir):
|
|
if each_dir.endswith(".txt") or each_dir.endswith(".sample"):
|
|
process_file(each_dir)
|
|
else:
|
|
process_dir(each_dir)
|
|
|
|
def main():
|
|
datdir = None
|
|
options = getopt.getopt(sys.argv[1:], 'd:')[0]
|
|
|
|
for opt, arg in options:
|
|
if opt in ('-d'):
|
|
datdir = arg
|
|
|
|
if datdir == None:
|
|
raise Exception("Must specify -d parameter")
|
|
|
|
process_dir(datdir)
|
|
executor.shutdown()
|
|
|
|
if __name__ == "__main__":
|
|
main() |