-
Notifications
You must be signed in to change notification settings - Fork 11
/
plotlatency.py
executable file
·34 lines (27 loc) · 1.02 KB
/
plotlatency.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
#!/usr/bin/python2
#
# Plot latency numbers for simulation stats in outdir to latency_file
import os
import sys
## Parse stats.txt for the specified key and return the associated value as float
def getStatsForString(stats_file, key):
with open(stats_file, "rt") as f:
for line in f:
if key in line:
split = line.split()
return float(split[-1])
return 0.0
if len(sys.argv) < 4:
print("Usage: %s <simulation directory> " \
"<latency output file> <injection rate>" % sys.argv[0])
outdir = sys.argv[1]
latency_file = sys.argv[2]
injrate = float(sys.argv[3])
stats_file = os.path.join(outdir, "stats.txt")
latest_latency_file = os.path.join(outdir, "../latest_latency.txt")
latency = getStatsForString(stats_file, "system.ruby.network.average_packet_latency")
if latency > -1:
with open(latency_file, "a") as f:
f.write("{0:f} {1:f}\n".format(injrate, latency))
with open(latest_latency_file, "w") as f:
f.write("{0:d}".format(int(latency)))