tor_multipath_voip/scripts/jantoran.py

140 lines
4.1 KiB
Python
Raw Normal View History

2020-01-13 17:01:57 +00:00
#!/usr/bin/python3
2020-01-14 11:09:52 +00:00
import os,sys,re,functools
2020-01-13 17:01:57 +00:00
2020-01-16 17:53:29 +00:00
default_perc = [0, 0.25, 0.5, 0.75, 0.99, 0.999, 1]
def tool_distri(arr, perc):
r = {}
for p in perc:
r[str(p)] = arr[round(p * (len(arr) - 1))]
return r
2020-01-14 11:09:52 +00:00
def compute_failure(s):
it = s['current']['interval']
if it not in s['failure']: s['failure'][it] = []
s['failure'][it].append(round(s['current']['max_pkt'] * s['current']['interval'] / 1000 / 60))
2020-01-13 17:01:57 +00:00
2020-01-16 16:59:29 +00:00
def compute_circuit_distri(s):
2020-01-16 17:53:29 +00:00
l = sorted(s['current']['lats'])
2020-01-16 18:29:24 +00:00
s['per_circuit_res'].append(tool_distri(l, default_perc))
2020-01-16 16:59:29 +00:00
def compute_interval_distri(s):
2020-01-16 17:53:29 +00:00
print(" + latency distribution for given packet freq.")
to_process = len(s['per_interval'])
processed = 0
for inter, val in s['per_interval'].items():
progress = round(processed / to_process * 100)
print(f"{progress}%", end="\r")
2020-01-16 18:08:04 +00:00
#print(val[0]['lats'][0:10])
2020-01-16 17:53:29 +00:00
x = sorted(functools.reduce(lambda acc, v: acc + v['lats'], val, []))
s['per_interval_res'][inter] = tool_distri(x, default_perc)
processed += 1
2020-01-16 16:59:29 +00:00
2020-01-14 11:09:52 +00:00
def extract_measlat(log, s):
2020-01-16 16:59:29 +00:00
s['current']['max_pkt'] = 0
s['current']['lats'] = []
2020-01-14 11:09:52 +00:00
with open(log) as f:
for l in f:
x = re.search(r'Packet (\d+) latency (\d+)µs with', l)
if x:
2020-01-16 18:08:04 +00:00
pkt = int(x.groups()[0])
lat = int(x.groups()[1])
s['current']['max_pkt'] = max(s['current']['max_pkt'], pkt)
2020-01-16 16:59:29 +00:00
s['current']['lats'].append(lat)
2020-01-14 11:09:52 +00:00
def extract_info(inf, s):
with open(inf) as f:
full = ''.join(f.readlines())
x = re.search(r'orig-server (\d+) (\d+) \d+', full)
2020-01-20 08:44:37 +00:00
if x:
s['current']['npkt'] = int(x.groups()[0])
s['current']['interval'] = int(x.groups()[1])
return True
else:
print("read error for",inf)
return False
2020-01-14 11:09:52 +00:00
def extract_folder(p, s):
2020-01-20 08:44:37 +00:00
if not extract_info(p + '/info.txt', s): return False
2020-01-14 11:09:52 +00:00
extract_measlat(p + '/log/client-measlat-stdout.log', s)
compute_failure(s)
2020-01-16 17:53:29 +00:00
compute_circuit_distri(s) if s['current']['interval'] == 40 else None
2020-01-16 16:59:29 +00:00
def categorize(folder, s):
s[folder] = s['current']
2020-01-16 17:53:29 +00:00
i = str(s['current']['interval'])
2020-01-16 16:59:29 +00:00
if i not in s['per_interval']: s['per_interval'][i] = []
2020-01-16 17:53:29 +00:00
s['per_interval'][i].append(s['current'])
2020-01-14 11:09:52 +00:00
def extract(p, s):
item_count = functools.reduce(lambda acc, prev: acc + 1, os.listdir(p), 0)
counter = 0
print("extracting...")
2020-01-13 17:01:57 +00:00
for folder in os.listdir(p):
2020-01-14 11:09:52 +00:00
s['current'] = {}
2020-01-20 08:44:37 +00:00
extract_folder(p + '/' + folder, s) and categorize(folder, s)
2020-01-14 11:09:52 +00:00
counter += 1
progress = round(counter / item_count * 100)
print(f"{progress}%", end="\r")
print("done")
2020-01-16 16:59:29 +00:00
def compute_global(s):
2020-01-16 17:53:29 +00:00
print("computing on global values...")
2020-01-16 16:59:29 +00:00
compute_interval_distri(s)
2020-01-14 11:09:52 +00:00
def analyze_failure(s):
2020-01-14 14:32:20 +00:00
with open('jan_failure.csv', 'w') as f:
f.write(f"rate,duration,ecdf\n")
for k, v in s['failure'].items():
v = sorted(v)
total = len(v)
rate = round(1000 / k)
2020-01-14 17:16:34 +00:00
score = 0
f.write(f"{rate},0,0\n")
2020-01-14 14:32:20 +00:00
for idx,e in enumerate(v,start=1):
2020-01-14 17:16:34 +00:00
if e >= 90:
f.write(f"{rate},90,{score}\n")
break
score = idx/total
f.write(f"{rate},{e},{score}\n")
2020-01-14 11:09:52 +00:00
2020-01-16 18:08:04 +00:00
def analyze_interval(s):
with open('jan_interval.csv', 'w') as f:
f.write(f"rate,perc,lat\n")
2020-01-17 17:07:03 +00:00
for inter, entr in s['per_interval_res'].items():
rate = round(1000 / int(inter))
2020-01-16 18:08:04 +00:00
for perc, lat in entr.items():
2020-01-17 17:07:03 +00:00
f.write(f"{rate},{float(perc)*100}%,{lat/1000}\n")
2020-01-16 18:08:04 +00:00
2020-01-16 18:29:24 +00:00
def analyze_circuit(s):
a = sorted(s['per_circuit_res'], key=lambda v: v['0.5'])
with open('jan_circuit_median.csv', 'w') as f:
f.write(f"id,perc,lat\n")
for idx,e in enumerate(a,start=1):
for perc, lat in e.items():
2020-01-17 17:07:03 +00:00
f.write(f"{idx},{float(perc)*100}%,{lat/1000}\n")
2020-01-16 18:29:24 +00:00
a = sorted(s['per_circuit_res'], key=lambda v: v['1'])
with open('jan_circuit_max.csv', 'w') as f:
f.write(f"id,perc,lat\n")
for idx,e in enumerate(a,start=1):
for perc, lat in e.items():
2020-01-17 17:07:03 +00:00
f.write(f"{idx},{float(perc)*100}%,{lat/1000}\n")
2020-01-16 18:29:24 +00:00
2020-01-14 11:09:52 +00:00
def analyze(s):
print("analyzing...")
analyze_failure(s)
2020-01-16 18:08:04 +00:00
analyze_interval(s)
2020-01-16 18:29:24 +00:00
analyze_circuit(s)
2020-01-14 11:09:52 +00:00
2020-01-16 18:29:24 +00:00
state = {'failure': {}, 'per_interval': {}, 'per_interval_res': {}, 'per_circuit_res': []}
2020-01-14 11:09:52 +00:00
extract(sys.argv[1], state)
2020-01-16 16:59:29 +00:00
compute_global(state)
2020-01-14 11:09:52 +00:00
analyze(state)
2020-01-13 17:01:57 +00:00
2020-01-14 11:09:52 +00:00
#for key, value in state.items():
# print(value)