-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_avg_latency.py
executable file
·204 lines (194 loc) · 6.79 KB
/
get_avg_latency.py
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python3
"""
This file is obsolete and no longer compatible with benchmark output.
Use get_avg_perf.py to compute average latency
"""
import os
import sys
import getopt
usage = '''USAGE: python3 {} [OPTIONS] [FILENAME] [...]
OPTIONS:
-h display help message
-t <type> specify the type of output -- REQUIRED
options:
linux
rust
docker
process
-d <directory> read output files from given directory
'''.format(sys.argv[0])
types = ['linux', 'rust', 'docker', 'process']
try:
optlist, args = getopt.getopt(sys.argv[1:], 'ht:d:')
except getopt.GetoptError as err:
print(err, file=sys.stderr)
print(usage, file=sys.stderr)
exit(1)
ftype = None
directories = []
for o, a in optlist:
if o == '-h':
print(usage, file=sys.stderr)
exit(1)
elif o == '-t':
ftype = a
elif o == '-d':
directories.append(a)
else:
print('ERROR: option "{}" unrecognized\n'.format(o), file=sys.stderr)
print(usage, file=sys.stderr)
exit(1)
for d in directories:
for f in os.listdir(d):
args.append('{}/{}'.format(d, f))
latencies = []
questionable = 0
unsuccessful = 0
if ftype == 'linux':
# Files should have the following form:
# <timestamp> QEMU initiated
# <timestamp> VM successfully running
# <timestamp> QEMU exited successfully
for filename in args:
with open(filename) as infile:
start_ts = None
active_ts = None
question = False
success = False
for line in infile:
if 'QEMU initiated' in line:
try:
start_ts = int(line.split()[0])
except ValueError:
question = True
elif 'VM successfully running' in line:
try:
active_ts = int(line.split()[0])
except ValueError:
question = True
elif 'QEMU exited successfully' in line:
success = True
if question:
questionable += 1
elif not success:
unsuccessful += 1
elif start_ts is None or active_ts is None:
questionable += 1
else:
latency = active_ts - start_ts
latencies.append(latency)
elif ftype == 'rust':
# Files should have the following form:
# <timestamp> QEMU initiated
# Hello 42!
# <timestamp> QEMU exited with error code 33
for filename in args:
with open(filename) as infile:
start_ts = None
exit_ts = None
question = False
success = False
for line in infile:
if 'QEMU initiated' in line:
try:
start_ts = int(line.split()[0])
except ValueError:
question = True
elif 'QEMU exited with error code 33' in line:
try:
exit_ts = int(line.split()[0])
except ValueError:
question = True
else:
success = True
if question:
questionable += 1
elif not success:
unsuccessful += 1
elif start_ts is None or exit_ts is None:
questionable += 1
else:
latency = exit_ts - start_ts
latencies.append(latency)
elif ftype == 'docker':
# Files should have the following form:
# <timestamp> Docker initiated
# <timestamp> Docker exited successfully
for filename in args:
with open(filename) as infile:
start_ts = None
exit_ts = None
question = False
success = False
for line in infile:
if 'Docker initiated' in line:
try:
start_ts = int(line.split()[0])
except ValueError:
question = True
elif 'Docker exited successfully' in line:
try:
exit_ts = int(line.split()[0])
except ValueError:
question = True
else:
success = True
if question:
questionable += 1
elif not success:
unsuccessful += 1
elif start_ts is None or exit_ts is None:
questionable += 1
else:
latency = exit_ts - start_ts
latencies.append(latency)
elif ftype == 'process':
# Files should have the following form:
# <timestamp> Process initiated
# <timestamp> Hello World!
# <timestamp> Process exited successfully
for filename in args:
with open(filename) as infile:
start_ts = None
active_ts = None
question = False
success = False
for line in infile:
if 'Process initiated' in line:
try:
start_ts = int(line.split()[0])
except ValueError:
question = True
elif 'Hello World!' in line:
try:
active_ts = int(line.split()[0])
except ValueError:
question = True
elif 'Process exited successfully' in line:
success = True
if question:
questionable += 1
elif not success:
unsuccessful += 1
elif start_ts is None or active_ts is None:
questionable += 1
else:
latency = active_ts - start_ts
latencies.append(latency)
elif ftype is None:
print('ERROR: please specify an output type using -t\n', file=sys.stderr)
print(usage, file=sys.stderr)
exit(1)
else:
print('ERROR: type {} unrecognized; available types:'.format(ftype), file=sys.stderr)
[print(t, file=sys.stderr) for t in types]
exit(1)
print('Found {} successful runs'.format(len(latencies)))
print('Found {} questionable runs'.format(questionable))
print('Found {} unsuccessful runs'.format(unsuccessful))
# dividing by powers of 10 is not precise enough, so I'll do it manually
avg_latency = sum(latencies) // len(latencies)
latency_str = str(avg_latency).zfill(10)
seconds = latency_str[:-9]
nanoseconds = latency_str[-9:]
print('Average latency: {}.{} seconds'.format(seconds, nanoseconds))