94 lines
No EOL
3.3 KiB
Python
94 lines
No EOL
3.3 KiB
Python
import matplotlib.pyplot as plt
|
|
import json
|
|
import sys
|
|
|
|
|
|
def do_port_ranges(name: str, data: dict, include_ports: list[str]):
|
|
|
|
# average percentage of data transferred per connection port (bar graph)
|
|
|
|
percentages_transferred = []
|
|
for port in include_ports:
|
|
cumulative = sum(d["total_data_received"] for d in data[port])
|
|
n = len(data[port])
|
|
percentages_transferred.append((cumulative / n) / 256_000 * 100)
|
|
|
|
plt.bar(include_ports, percentages_transferred)
|
|
plt.axhline(y=100, color="#fc8080", linestyle="--")
|
|
plt.title("Average percentage of expected data transferred per connection per port")
|
|
plt.ylabel("Percentage of 256KB")
|
|
plt.xlabel("Port number")
|
|
plt.savefig(f"{name}-data-transferred.png")
|
|
plt.clf() # clear figure
|
|
|
|
# percentage of dropped connections per port (bar graph)
|
|
|
|
amount_dropped = []
|
|
for port in include_ports:
|
|
count = sum(1 if d["was_connection_reset"] and d["reset_by_remote"] else 0 for d in data[port])
|
|
n = len(data[port])
|
|
amount_dropped.append(count / n * 100)
|
|
|
|
plt.bar(include_ports, amount_dropped)
|
|
plt.axhline(y=100, color="#fc8080", linestyle="--")
|
|
plt.title("Percentage of connections reset by the remote per port")
|
|
plt.ylabel("Percentage of runs")
|
|
plt.xlabel("Port number")
|
|
plt.savefig(f"{name}-connections-closed.png")
|
|
plt.clf() # clear figure
|
|
|
|
# number of successful transactions (bar graph)
|
|
|
|
successes = []
|
|
total = []
|
|
for port in include_ports:
|
|
successes.append(sum(1 if not d["was_connection_reset"] else 0 for d in data[port]))
|
|
total.append(len(data[port]))
|
|
|
|
plt.bar(include_ports, total, label="failures")
|
|
plt.bar(include_ports, successes, label="successes")
|
|
plt.legend()
|
|
plt.title("Number of successful transactions per port")
|
|
plt.xlabel("Port number")
|
|
plt.savefig(f"{name}-number-successes.png")
|
|
plt.clf() # clear figure
|
|
|
|
# average duration of successful transactions (bar graph)
|
|
|
|
ports_with_successes = include_ports.copy()
|
|
durations = []
|
|
for port in include_ports:
|
|
cumulative_time = 0
|
|
n_successes = 0
|
|
|
|
for result in data[port]:
|
|
if result["was_connection_reset"]:
|
|
continue
|
|
|
|
cumulative_time += result["runtime"]
|
|
n_successes += 1
|
|
|
|
if n_successes == 0:
|
|
ports_with_successes.remove(port)
|
|
else:
|
|
durations.append(cumulative_time / n_successes)
|
|
|
|
plt.bar(ports_with_successes, durations)
|
|
plt.title("Average duration of successful transactions per port")
|
|
plt.ylabel("Runtime (seconds)")
|
|
plt.xlabel("Port number")
|
|
plt.savefig(f"{name}-success-durations.png")
|
|
plt.clf() # clear figure
|
|
|
|
return
|
|
|
|
if __name__ == "__main__":
|
|
INPUT_DATA = sys.argv[1]
|
|
|
|
with open(INPUT_DATA) as f:
|
|
data = json.load(f)
|
|
|
|
do_port_ranges("400X", data, list(map(str, range(4000, 4010)))) # normal (with SACK and window scaling)
|
|
do_port_ranges("401X", data, list(map(str, range(4010, 4020)))) # without SACK
|
|
do_port_ranges("402X", data, list(map(str, range(4020, 4030)))) # without window scaling
|
|
do_port_ranges("403X", data, list(map(str, range(4030, 4040)))) # without SACK or window scaling |