-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot-mm-stats-over-time.py
executable file
·119 lines (90 loc) · 3.25 KB
/
plot-mm-stats-over-time.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
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import animation
from sys import argv, exit
from os import environ
from paperstyle import FIGSIZE
USAGE = "Usage: [FREQ=freq_mhz] ./script is_exp min nbins width file \n where file = [too_low too_high bin0 bin1 ... name]... \\n [too_low too_high bin0 bin1 ... name]..."
if len(argv) < 6:
print(USAGE)
exit(1)
INTERVAL = 200
FREQ = float(environ["FREQ"]) if "FREQ" in environ else None
IS_EXP = argv[1] == "1"
MIN = int(argv[2])
NBINS = int(argv[3])
WIDTH = int(argv[4])
FILE = argv[5]
def parse_dataset(raw):
raw = raw.split()
NDATASETS = int(len(raw) / (NBINS + 3))
max_val = 0
data_labels = []
data = []
for i in range(NDATASETS):
d = [int(raw[i*(NBINS+3)])] # too_low
# data..., too_high
d += map(lambda x: int(x), raw[i*(NBINS + 3) + 1 : (i+1)*(NBINS + 3) - 1])
max_val = max(max_val, max(d))
data.append(d)
data_labels.append(raw[(i+1)*(NBINS + 3)-1])
return (data, data_labels, max_val)
data_labels = []
data_per_step = []
n = 0
max_all = 0
NDATASETS = 0
with open(FILE, 'r') as f:
for line in f.readlines():
(data, dl, max_val) = parse_dataset(line.strip())
NDATASETS = len(data)
data_labels = dl
max_all = max(max_all, max_val)
n += 1
data_per_step.append(data)
# compute the boundaries of each bin.
if IS_EXP: # exponential bins
bin_lower_bounds = [MIN + (1<<i)*WIDTH for i in range(NBINS)]
bin_upper_bounds = [MIN + (1<<(i+1))*WIDTH for i in range(NBINS)]
else: # linear bins
bin_lower_bounds = [MIN + i*WIDTH for i in range(NBINS)]
bin_upper_bounds = [MIN + (i+1)*WIDTH for i in range(NBINS)]
if FREQ is not None:
bin_lower_bounds = list(map(lambda x: x / FREQ, bin_lower_bounds))
bin_upper_bounds = list(map(lambda x: x / FREQ, bin_upper_bounds))
# create some text bin labels for the plot.
labels = ["< {:.1f}".format(bin_upper_bounds[0])]
for (l, u) in zip(bin_lower_bounds, bin_upper_bounds):
l = "[{:.1f}, {:.1f})".format(l, u)
labels.append(l)
labels.append(">= {:.1f}".format(bin_upper_bounds[-1]))
# Actually plot now
fig = plt.figure(1, figsize=FIGSIZE)
bars = []
TOTAL_WIDTH = 0.7
WIDTH = TOTAL_WIDTH / NDATASETS
x = np.arange(NBINS+2)
for (i, (d, l)) in enumerate(zip(data, data_labels)):
bar = plt.bar(x + WIDTH / 2 - TOTAL_WIDTH / 2 + i * WIDTH, d, label=l, width=WIDTH)
bars.append(bar)
plt.xticks(x, labels, rotation=60, ha='right')
plt.yscale('symlog')
plt.ylabel("Frequency")
plt.xlabel("Latency (%s)" % ("cycles" if FREQ is None else "usec"))
plt.legend(bbox_to_anchor=(0, 1.02, 1, 0.2), loc="lower left", mode="expand")
plt.ylim((0, max_all))
plt.tight_layout()
# Animate
text = plt.text(0.05, 0.95, str(0), transform = fig.axes[0].transAxes, fontsize='xx-large')
def animate(i):
y = data_per_step[i]
text.set_text(str(i))
for bi, bs in enumerate(bars):
for i, b in enumerate(bs):
b.set_height(y[bi][i])
anim=animation.FuncAnimation(fig,animate,repeat=True,blit=False,frames=n,
interval=INTERVAL)
#anim.save('test.mp4', writer=animation.FFMpegWriter(fps=1000/INTERVAL))
anim.save('test.gif', writer='imagemagick', fps=1000/INTERVAL)
plt.show()