From 2580dee925d245333cb3999af474f3ecdb55ea5a Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 20 Jan 2020 10:31:59 +0000 Subject: [PATCH] Add new parsing file --- scripts/jantoran_2.py | 99 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 scripts/jantoran_2.py diff --git a/scripts/jantoran_2.py b/scripts/jantoran_2.py new file mode 100755 index 0000000..04ba26f --- /dev/null +++ b/scripts/jantoran_2.py @@ -0,0 +1,99 @@ +#!/usr/bin/python3 +import os,sys,re,functools + +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 + +def compute_failure(s): + it = s['current']['strat'] + if it not in s['failure']: s['failure'][it] = [] + s['failure'][it].append(round(s['current']['max_pkt'] * s['current']['interval'] / 1000 / 60)) + return True + +def extract_measlat(log, s): + s['current']['max_pkt'] = 0 + s['current']['lats'] = [] + try: + with open(log) as f: + for l in f: + x = re.search(r'Packet (\d+) latency (\d+)µs with', l) + if x: + pkt = int(x.groups()[0]) + lat = int(x.groups()[1]) + s['current']['max_pkt'] = max(s['current']['max_pkt'], pkt) + #s['current']['lats'].append(lat) + return True + except: + return False + +def extract_info(inf, s): + try: + with open(inf) as f: + full = ''.join(f.readlines()) + x = re.search(r'server= (\S+) (\d+) (\d+) \d+ (\d+ (\S+))?', full) + if x: + s['current']['strat'] = x.groups()[0] + if x.groups()[4] != None: + y = re.search(r'tick_tock=(\d)', x.groups()[4]) + if y: + s['current']['strat'] += "-ticktock" if y.groups()[0] == '1' else "-duplicate" + s['current']['npkt'] = int(x.groups()[1]) + s['current']['interval'] = int(x.groups()[2]) + return True + else: + print("parse error for",inf) + return False + except Exception as e: + print("read error", inf, e) + return False + +def extract_folder(p, s): + return extract_info(p + '/info.txt', s) and extract_measlat(p + '/log/client-measlat-stdout.log', s) and compute_failure(s) + +def categorize(folder, s): + s[folder] = s['current'] + + i = str(s['current']['strat']) + if i not in s['per_strat']: s['per_strat'][i] = [] + s['per_strat'][i].append(s['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) and categorize(folder, s) + counter += 1 + progress = round(counter / item_count * 100) + print(f"{progress}%", end="\r") + print("done") + +def analyze_failure(s): + with open('jan2_failure.csv', 'w') as f: + f.write(f"strat,duration,ecdf\n") + for strat, v in s['failure'].items(): + v = sorted(v) + total = len(v) + score = 0 + f.write(f"{strat},0,0\n") + for idx,e in enumerate(v,start=1): + if e >= 90: + f.write(f"{strat},90,{score}\n") + break + score = idx/total + f.write(f"{strat},{e},{score}\n") + +def analyze(s): + print("analyzing...") + analyze_failure(s) + +state = {'failure': {}, 'per_strat': {}, 'per_interval_res': {}, 'per_circuit_res': []} +extract(sys.argv[1], state) +analyze(state)