-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_table.py
More file actions
67 lines (49 loc) · 3 KB
/
Copy pathmake_table.py
File metadata and controls
67 lines (49 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os, sys
import glob
import argparse
import numpy as np
import pandas as pd
from tqdm import tqdm
def generate_results_table(results_dir, key, savepath=None, append=False):
flist = glob.glob(os.path.join(results_dir, '*_sender_RTT.csv'))
table = [] # key, tracename, duration, blksize, qsize, mmdelay, avg cap, avg tput, avg util, delay statistics
for fpath in tqdm(flist, desc='Parsing all output files in \'{}\''.format(results_dir)):
fname = os.path.basename(fpath)
trace, rest = fname.split('_T')
if '_Q' in rest:
duration, blksize, qsize, mmdelay, _ = rest.split('_', 4)
qsize = int(float(qsize[1:]))
else:
duration, blksize, mmdelay, _ = rest.split('_', 3)
qsize = None
duration = int(duration[1:])
mmdelay = int(mmdelay[5:])
df_rtt = pd.read_csv(fpath, header=None, names=['timestamp', 'rtt'])
df_rtt.set_index('timestamp', inplace=True)
df_rtt['seconds'] = df_rtt.index.values.round()
df_rtt = df_rtt.groupby('seconds').mean()
df_rtt.loc[:, 'rtt'] = df_rtt.rtt.values * 1000 # convert RTT to milliseconds
df_tput = pd.read_csv(fpath.replace('sender_RTT', 'uplink_mmtput'), index_col=[0])
df_tput = (df_tput * 8 / 1e6)
table.append((key, trace, duration, blksize, qsize, mmdelay, df_tput.capacity_bytes.mean(), df_tput.egress_bytes.mean(), (df_tput.egress_bytes*100 / df_tput.capacity_bytes).mean(), df_rtt.rtt.min(), df_rtt.rtt.max(), df_rtt.rtt.mean(), df_rtt.rtt.std(), df_rtt.rtt.quantile(0.25), df_rtt.rtt.quantile(0.5), df_rtt.rtt.quantile(0.75)))
df = pd.DataFrame(table, columns=['key', 'trace', 'duration', 'blksize', 'qsize', 'mmdelay', 'capacity', 'throughput', 'utilization', 'delay_min', 'delay_max', 'delay_avg', 'delay_std', 'delay_25', 'delay_50', 'delay_75'])
df = df.set_index(['key', 'trace', 'duration', 'blksize', 'qsize', 'mmdelay'])
df.sort_index(level=[0,1,2,3,4,5], inplace=True)
if savepath is None:
savepath = os.path.join('results', 'results_{}.csv'.format(key))
else:
if os.path.exists(savepath) and append:
df_existing = pd.read_csv(savepath, index_col=[0,1,2,3,4,5])
df = pd.concat([df_existing, df], axis=0)
df.to_csv(savepath, float_format='%.4f')
return df
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('results_dir', help='Directory where the sim run outputs are present')
parser.add_argument('save_key', help='Name for this group of results (usually name of the CCA)')
parser.add_argument('--savepath', '-o', help='Path to save the results table')
parser.add_argument('--append', '-a', action='store_true', help='Append to an existing table (ignored if --savepath is not provided)')
args = parser.parse_args()
if not os.path.exists('results'):
os.makedirs('results')
generate_results_table(args.results_dir, args.save_key, savepath=args.savepath, append=args.append)