-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-queuesize.py
executable file
·54 lines (40 loc) · 1.26 KB
/
plot-queuesize.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
#!/usr/bin/env python3
import sys
from matplotlib import pyplot
from itertools import accumulate
from LogReader import LogReader
if len(sys.argv) != 2:
print("Usage: {} <simulation.log>".format(sys.argv[0]))
sys.exit(1)
pyplot.rcParams["figure.figsize"] = [5.75, 4.0]
reader = LogReader(sys.argv[1])
def calculateQueue(packets):
timeQueue = {}
sentPackets = filter(lambda pe: pe.successful, packets)
injects = list(reader.injects)
queue = {}
def enqueue(packet):
if packet not in queue: queue[packet] = 0
queue[packet] += 1
def recordInTimeQueue(time):
for packet in queue:
if packet not in timeQueue: timeQueue[packet] = []
timeQueue[packet].append((time, queue[packet]))
for pe in sentPackets:
while injects and injects[0][0] <= pe.end:
enqueue(injects[0][1])
injects.pop(0)
queue[pe.packet] -= 1
recordInTimeQueue(pe.end)
return timeQueue
l = []
def plotTimeQueue(timeQueue, label):
for packet in timeQueue:
tx, = pyplot.plot(*zip(*timeQueue[packet]))
l.append((tx, "qs($\mathsf{{{0}}}$, {1})".format(label, packet)))
algTimeQueue = calculateQueue(reader.algPackets)
plotTimeQueue(algTimeQueue, "ALG")
advTimeQueue = calculateQueue(reader.advPackets)
plotTimeQueue(advTimeQueue, "ADV")
pyplot.legend(*zip(*l), loc=2)
pyplot.show()