97 lines
2.8 KiB
Python
Executable file
97 lines
2.8 KiB
Python
Executable file
#!/usr/bin/python3
|
|
import os,sys,re,functools
|
|
|
|
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))
|
|
|
|
def compute_circuit_distri(s):
|
|
s['current']['lats'] = l = sorted(s['current']['lats'])
|
|
s['current']['distri'] = d = {}
|
|
perc = lambda p: l[round(p * (len(l) - 1))]
|
|
for x in [0, 0.25, 0.5, 0.75, 0.99, 0.999, 1]:
|
|
d[str(x)] = perc(x)
|
|
|
|
def compute_interval_distri(s):
|
|
for inter, val in s['per_interval']:
|
|
s['per_interval_res'][inter] = {}
|
|
s['per_interval_res'][inter]['agg'] = sorted([].extend([ elem['lats'] for elem in val]))
|
|
|
|
def extract_measlat(log, s):
|
|
s['current']['max_pkt'] = 0
|
|
s['current']['lats'] = []
|
|
with open(log) as f:
|
|
for l in f:
|
|
x = re.search(r'Packet (\d+) latency (\d+)µs with', l)
|
|
if x:
|
|
lat = x.groups()[0]
|
|
s['current']['max_pkt'] = max(s['current']['max_pkt'], int(lat))
|
|
s['current']['lats'].append(lat)
|
|
|
|
def extract_info(inf, s):
|
|
with open(inf) as f:
|
|
full = ''.join(f.readlines())
|
|
x = re.search(r'orig-server (\d+) (\d+) \d+', full)
|
|
s['current']['npkt'] = int(x.groups()[0])
|
|
s['current']['interval'] = int(x.groups()[1])
|
|
|
|
def extract_folder(p, s):
|
|
extract_info(p + '/info.txt', s)
|
|
extract_measlat(p + '/log/client-measlat-stdout.log', s)
|
|
|
|
compute_failure(s)
|
|
compute_circuit_distri(s) if s['current']['interval'] == 40
|
|
|
|
def categorize(folder, s):
|
|
s[folder] = s['current']
|
|
|
|
i = s['current']['interval']
|
|
if i not in s['per_interval']: s['per_interval'][i] = []
|
|
s['per_interval'][i].append(current)
|
|
|
|
def extract(p, s):
|
|
item_count = functools.reduce(lambda acc, prev: acc + 1, os.listdir(p), 0)
|
|
|
|
counter = 0
|
|
print("extracting...")
|
|
for folder in os.listdir(p):
|
|
s['current'] = {}
|
|
extract_folder(p + '/' + folder, s)
|
|
categorize(folder, s)
|
|
counter += 1
|
|
progress = round(counter / item_count * 100)
|
|
print(f"{progress}%", end="\r")
|
|
print("done")
|
|
|
|
def compute_global(s):
|
|
print("computing global...")
|
|
compute_interval_distri(s)
|
|
|
|
def analyze_failure(s):
|
|
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)
|
|
score = 0
|
|
f.write(f"{rate},0,0\n")
|
|
for idx,e in enumerate(v,start=1):
|
|
if e >= 90:
|
|
f.write(f"{rate},90,{score}\n")
|
|
break
|
|
score = idx/total
|
|
f.write(f"{rate},{e},{score}\n")
|
|
|
|
def analyze(s):
|
|
print("analyzing...")
|
|
analyze_failure(s)
|
|
|
|
state = {'failure': {}, 'per_interval': {}, 'per_interval_res': {}}
|
|
extract(sys.argv[1], state)
|
|
compute_global(state)
|
|
analyze(state)
|
|
|
|
#for key, value in state.items():
|
|
# print(value)
|