-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotter.py
80 lines (72 loc) · 2.94 KB
/
Plotter.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
from enum import Enum
import matplotlib.pyplot as plt
class Plotter:
class PlotType(Enum):
FullSize = 1
Compact = 2
def __init__(self, nodes, links, fastest_freq, slowest_freq):
self.mode = self.PlotType.FullSize
self.nodes = nodes
self.links = links
self.fastest_freq = fastest_freq
self.slowest_freq = slowest_freq
self.node_labels = []
self.buffer_labels = []
for node in nodes.values():
self.node_labels.append(node.name)
for link in links[node.name]:
self.buffer_labels.append(links[node.name][link].destNode + "->" + node.name)
self.timesteps = []
self.node_frequencies = []
self.control_outputs = []
self.buffer_occupancies = []
self.logical_delay = []
self.buffer_latencies = []
self.jitter = []
def plot(self,t):
step_frequencies = []
step_occupancies = []
step_delays = []
step_jitter = []
step_latencies = []
for node in self.nodes.values():
step_jitter.append(node.last_jitter)
step_latencies.extend(node.get_latencies())
step_frequencies.append(node.get_frequency())
step_occupancies.extend(node.get_occupancies_as_percent())
step_delays.extend(node.get_logical_delays())
self.timesteps.append(t)
self.jitter.append(step_jitter)
self.node_frequencies.append(step_frequencies)
self.buffer_occupancies.append(step_occupancies)
self.buffer_latencies.append(step_latencies)
self.logical_delay.append(step_delays)
def render(self):
if self.mode == self.PlotType.FullSize:
plt.figure(figsize=(4, 2), dpi=160)
plt.subplot(2, 1, 1)
plt.title("Frequency")
plt.ylabel("Hz")
plt.plot(self.timesteps, self.node_frequencies, label=self.node_labels)
plt.ylim([self.slowest_freq/1.01,self.fastest_freq*1.01])
plt.legend(loc='best')
plt.subplot(2, 1, 2)
plt.title("Buffer Occupancies")
tnrfont = {'fontname':'Times New Roman'}
plt.ylabel("Percent Occ. ")
plt.xlabel("firing count")
plt.plot(self.timesteps, self.buffer_occupancies, label=self.buffer_labels,alpha=0.7)
plt.ylim([0,100])
plt.xticks(fontproperties='Times New Roman', size=10)
plt.yticks(fontproperties='Times New Roman', size=10)
plt.legend(fontsize=8,loc='lower right',ncol=2, frameon=False, borderpad=0,labelspacing=0)
plt.subplots_adjust(left=0.1,
bottom=0.15,
right=0.9,
top=0.85,
wspace=0.4,
hspace=0.8)
elif self.mode == self.PlotType.Compact:
#render freq and occ in separate windows
pass
plt.show()