-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot-combined.py
More file actions
179 lines (133 loc) · 5.52 KB
/
Copy pathplot-combined.py
File metadata and controls
179 lines (133 loc) · 5.52 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import re
import os
from datetime import datetime
from os import path
import math
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 26}
plt.rc('font', **font)
def plot():
blue = "#1E88E5"
red = "#D81B60"
yellow = "#A8810C"
# Colorblind mode
sns.set("paper", palette="colorblind")
# Prepare data
x = np.arange(35)
delay_omnia_ebpf = parse_ping_logfile("./results/ebpf/latency-omnia.txt")
delay_omnia_nft = parse_ping_logfile("./results/nft/latency-omnia.txt")
throughput_omnia_ebpf = parse_iperf_logfile("./results/ebpf/throughput-omnia.txt")
throughput_omnia_nft = parse_iperf_logfile("./results/nft/throughput-omnia.txt")
# combined results (delay and throughput)
fig, ax1 = plt.subplots()
ax1.axvline(x=19, color='gray', linestyle='dotted', linewidth=1)
color = 'tab:red'
ax1.set_xlabel('time (s)')
ax1.set_ylabel('latency in ms', color=color)
ax1.step(x, delay_omnia_nft['y'], color=color, drawstyle='steps-post', linestyle="dotted", label="Delay Netfilter")
ax1.step(x, delay_omnia_ebpf['y'], color=color, drawstyle='steps-post', label="Delay eBPF")
ax1.tick_params(axis='y', labelcolor=color)
ax1.set_ylim([20, 40])
ax2 = ax1.twinx() # instantiate a second Axes that shares the same x-axis
color = 'tab:blue'
x= throughput_omnia_nft['x']
ax2.set_ylabel('Throughput in Mbit/s', color=color) # we already handled the x-label with ax1
ax2.step(x, throughput_omnia_nft['y'], color=color, drawstyle='steps-post', linestyle="dotted",label="Throughput Netfilter")
ax2.step(x, throughput_omnia_ebpf['y'], color=color, drawstyle='steps-post', label="Throughput eBPF")
ax2.tick_params(axis='y', labelcolor=color)
ax2.set_ylim([550, 950])
plt.xlim([0,30])
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
ax1.legend(h1+h2, l1+l2, loc=2, bbox_to_anchor=(0.01, 0.9))
#plt.legend(loc="upper left", bbox_to_anchor=(0.5, 0.5))
fig.tight_layout() # otherwise the right y-label is slightly clipped
plt.savefig("./results/results_combined.pdf", format='pdf')
plt.savefig("./results/results_combined.svg", format='svg')
plt.close(fig)
def parse_ping_logfile(file_path: str):
file = open(file_path, 'r')
lines = file.readlines()
start_time = None
time_fmt = "%H:%M:%S.%f"
# Only lines with package results
lines = filter(lambda line: "ttl=" in line, lines)
results = {"x": [], "y": []}
for line in lines:
# https://regex101.com/r/GkS5lX/3
regex_result = re.search(
r"(\d+:\d+:\d+[.]\d{6})(.*)(icmp_seq=)(\d+)(.*)(time=)(\d*[.]?\d*)", line
)
time_string = regex_result.group(1)
# icpm_seq = regex_result.group(4)
latency = regex_result.group(7)
if start_time is None:
start_time = datetime.strptime(time_string, time_fmt)
time_offset = datetime.strptime(time_string, time_fmt) - start_time
results["x"].append(time_offset.total_seconds())
results["y"].append(float(latency))
# Compress the array into 1 second intervals
x = np.arange(35)
y = [0] * 35
start = 0
end = 0
for interval in x:
if end >= len(results["x"]) - 1:
break # we are done with all values
while math.floor(results["x"][end]) == interval:
if end >= len(results["x"]) - 1:
break # we are done with all values
end = end + 1
# if the time offsets get bigger that the current interval
if start == end:
y[interval] = 0 # No recorded values = 0
else:
# take the mean of all values in current interval
y[interval] = np.mean(results["y"][start:end])
start = end
return {"x": x[:35], "y": y[:35]}
def parse_iperf_logfile(file_path: str):
file = open(file_path, "r")
lines = file.readlines()
# Only lines with bandwith results
lines = filter(lambda line: "sec" in line, lines)
results = {"x": [], "y": []}
for line in lines:
# https://regex101.com/r/GYMmWI/1
interval_start = re.search(r"(\d+\.\d+)-", line).group(1)
# https://regex101.com/r/cxraYv/1
bandwidth = re.search(r"(\d+)(\ \w+/sec)", line).group(1)
results["x"].append(float(interval_start))
results["y"].append(float(bandwidth))
return {"x": results["x"][:-3], "y": results["y"][:-3]}
def parse_load_logfile(file_path: str):
file = open(file_path, "r")
lines = file.readlines()
start_time = None
#time_fmt = "%H:%M:%S.%f"
time_fmt = "%H:%M:%S"
# Only lines with bandwith results
lines = filter(lambda line: "load" in line.lower(), lines)
results = {"x": np.arange(35), "y": []}
i = 0
for line in lines:
# https://regex101.com/r/Z5J49M/1
regex_result = re.search(r"(.*) - Load averages: (\d*.\d*) (.*)", line)
time_string = regex_result.group(1)
load = regex_result.group(2)
if start_time is None:
start_time = datetime.strptime(time_string, time_fmt)
time_offset = datetime.strptime(time_string, time_fmt) - start_time
#results["x"].append(time_offset.total_seconds())
results["y"].append(float(load))
results["y"].append(float(load))
return {"x": results["x"], "y": results["y"][:35]}
if __name__ == "__main__":
plot()