Repository navigation
Expand file tree
/
Copy pathdiff_rtts.py
More file actions
executable file
·168 lines (145 loc) · 4.1 KB
/
Copy pathdiff_rtts.py
File metadata and controls
executable file
·168 lines (145 loc) · 4.1 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
#!/usr/bin/python3
# Copyright (c) 2023 Homa Developers
# SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0+
"""
Compare two .rtts files to identify differences between them.
Usage: diff_rtts.py file1 file2
"""
from __future__ import annotations
from glob import glob
from operator import itemgetter
from optparse import OptionParser
import math
import os
import re
import string
import sys
def read_rtts(file: str) -> list[list[float]]:
"""
Read a .rtts file and returns a list of (length, slowdown) pairs.
file: Name of file to read
"""
slowdowns = []
f = open(file)
for line in f:
if line.startswith('#') or not line:
continue
match = re.match(' *([0-9]+) +([0-9.]+)', line)
if not match:
raise Exception("Malformed line in .rtts file: %s" % (line.rstrip()))
length = int(match.group(1))
rtt = float(match.group(2))
# Optimal time (usecs) assumes 13 usec minimum, 25 Gbps network
optimal = 13.0 + length*8/25000.0
slowdown = rtt/optimal
slowdowns.append([length, slowdown])
f.close()
return slowdowns
def avg_slowdown(slowdowns: list[list[float]]) -> float:
"""
Return average slowdown from a list of (length, slowdown) pairs.
slowdowns: Input list
"""
sum = 0.0
for item in slowdowns:
sum += item[1]
return sum/len(slowdowns)
def deciles(slowdowns: list[list[float]]) -> tuple[list[float], list[float], list[float], list[float], list[float], list[float]]:
"""
Given a list of (length, slowdown) pairs, divide into 10 groups by
length, then returns 6 lists (each with one entry per decile),
containing:
* largest length in the decile
* P50 slowdown for the decile
* P90 slowdown for the decile
* P99 slowdown for the decile
* P99.9 slowdown for the decile
* max slowdown for the decile
"""
p50 = []
p90 = []
p99 = []
p999 = []
max = []
cutoffs = []
s = sorted(slowdowns, key = itemgetter(0))
for split in range(1, 11):
split_start = len(s)*(split-1)//10
split_end = len(s)*split//10
decile = []
for i in range(split_start, split_end):
decile.append(s[i][1])
cutoffs.append(s[split_end-1][0])
decile = sorted(decile)
p50.append(decile[len(decile)//2])
p90.append(decile[len(decile)*9//10])
p99.append(decile[len(decile)*99//100])
p999.append(decile[len(decile)*999//1000])
max.append(decile[-1])
return cutoffs, p50, p90, p99, p999, max
if len(sys.argv) != 3:
print("Usage: diff_rtts.py file1 file2")
exit(1)
f1 = sys.argv[1]
f2 = sys.argv[2]
s1 = read_rtts(f1)
print("Average slowdown in %s: %.1f" % (f1, avg_slowdown(s1)))
s2 = read_rtts(sys.argv[2])
print("Average slowdown in %s: %.1f" % (f2, avg_slowdown(s2)))
print("")
c1, p50_1, p90_1, p99_1, p999_1, max_1 = deciles(s1)
c2, p50_2, p90_2, p99_2, p999_2, max_2 = deciles(s2)
out = ""
for cutoff in c1:
out += " %d" % (cutoff)
print("Cutoffs for %s:%s" % (f1, out))
out = ""
for cutoff in c2:
out += " %d" % (cutoff)
print("Cutoffs for %s:%s" % (f2, out))
print("")
out = ""
for val in p50_1:
out += " %5.1f" % (val)
print("P50s for %s:%s" % (f1, out))
out = ""
for val in p50_2:
out += " %5.1f" % (val)
print("P50s for %s:%s" % (f2, out))
print("")
out = ""
for val in p90_1:
out += " %5.1f" % (val)
print("P90s for %s:%s" % (f1, out))
out = ""
for val in p90_2:
out += " %5.1f" % (val)
print("P90s for %s:%s" % (f2, out))
print("")
out = ""
for val in p99_1:
out += " %5.1f" % (val)
print("P99s for %s:%s" % (f1, out))
out = ""
for val in p99_2:
out += " %5.1f" % (val)
print("P99s for %s:%s" % (f2, out))
print("")
out = ""
for val in p999_1:
out += " %5.1f" % (val)
print("P99.9s for %s:%s" % (f1, out))
out = ""
for val in p999_2:
out += " %5.1f" % (val)
print("P99.9s for %s:%s" % (f2, out))
print("")
out = ""
for val in max_1:
out += " %5.1f" % (val)
print("Maxes for %s:%s" % (f1, out))
out = ""
for val in max_2:
out += " %5.1f" % (val)
print("Maxes for %s:%s" % (f2, out))
exit(0)