-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirty-tail-cdf2.py
executable file
·206 lines (159 loc) · 5.62 KB
/
dirty-tail-cdf2.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
205
206
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
from numpy import ma
from matplotlib import scale as mscale
from matplotlib import transforms as mtransforms
from matplotlib.ticker import FixedFormatter, FixedLocator
import re
import itertools
from collections import OrderedDict
from cycler import cycler
from sys import argv, exit
from os import environ
from paperstyle import FIGSIZE, IS_PDF, OUTFNAME, NOSHOW
USAGE_STR = "[FREQ=freq_mhz] ./script <nines> <label> <P0> <P1> ... <P100> <label> <P0> <P1> ... <P100> ..."
if len(argv[2:]) % 102 != 0:
print("./Usage: %s" % USAGE_STR)
FREQ = float(environ["FREQ"]) if "FREQ" in environ else None
NINES = float(argv[1])
NPLOTS = int(len(argv[2:]) / 102)
SCALE = [float(x) for x in environ["SCALE"].split()]
def style(label):
COLORS = {
"Linux": "#c9bc00",
"CBMM": "#3977a3",
"HawkEye": "#d13838",
"CBMM-perapp": "#d13838",
"CBMM-only-huge": "#d13838",
"Linux4.3": "black",
"CBMM-tuned": "green",
"CBMM-shared": "black",
"CBMM-huge": "black",
"CBMM-async" : "red",
}
linesty = "--" if "frag" in label else "solid"
color = COLORS[label.split(",")[0]]
return color,linesty
plt.figure(figsize=FIGSIZE)
#CYCLER = (cycler(color=['r', 'g', 'b', 'y', 'c', 'm', 'k']) + cycler(linestyle=['-', '--', ':', '-.']))
colormap = plt.cm.nipy_spectral
colors = [colormap(i) for i in np.linspace(0, 1, NPLOTS)]
styles = itertools.cycle(['-', '--', ':', '-.'])
#plt.gca().set_prop_cycle('color', colors)
class CloseToOne(mscale.ScaleBase):
name = 'close_to_one'
def __init__(self, axis, **kwargs):
mscale.ScaleBase.__init__(self)
self.nines = int(NINES)
def get_transform(self):
return self.Transform(self.nines)
def set_default_locators_and_formatters(self, axis):
axis.set_major_locator(FixedLocator(
np.array([100-10**(2-k) for k in range(1+self.nines)])))
axis.set_major_formatter(FixedFormatter(
[str(100-10**(2-k)) for k in range(1+self.nines)]))
def limit_range_for_scale(self, vmin, vmax, minpos):
return vmin, min(100 - 10**(2-self.nines), vmax)
class Transform(mtransforms.Transform):
input_dims = 1
output_dims = 1
is_separable = True
def __init__(self, nines):
mtransforms.Transform.__init__(self)
self.nines = nines
def transform_non_affine(self, a):
masked = ma.masked_where(a > 100-10**(2-1-self.nines), a)
if masked.mask.any():
return -ma.log10(1-a/100.) * 100.
else:
return -np.log10(1-a/100.) * 100.
def inverted(self):
return CloseToOne.InvertedTransform(self.nines)
class InvertedTransform(mtransforms.Transform):
input_dims = 1
output_dims = 1
is_separable = True
def __init__(self, nines):
mtransforms.Transform.__init__(self)
self.nines = nines
def transform_non_affine(self, a):
return 100. - 10**(2-a/100.)
def inverted(self):
return CloseToOne.Transform(self.nines)
mscale.register_scale(CloseToOne)
ys = [y for y in range(0, 101)] # 0 ..= 100
ys = [y * NINES / 100. for y in ys] # 0 ..= nines
ys = [100. - 10. ** (2 - y) for y in ys] # log space
ys = [1 / (100 - y) for y in ys]
# {label:(xs, ys)}
data_tmp = {}
s = ""
for (i, factor) in zip(range(NPLOTS), SCALE):
label = argv[2+i*102]
#label = label.split("(")[0]
xs = [float(x) for x in argv[2+i*102+1:2+(i+1)*102]]
if FREQ is not None:
xs = [x / FREQ for x in xs]
#ls = next(styles)
c,ls = style(label)
scaledys = [y / factor for y in ys]
if label in []:
plt.plot(xs, scaledys, label=label, linewidth=0)
else:
plt.plot(xs, scaledys, label=label, color=c, linestyle=ls, linewidth=2)
data_tmp[label] = (xs, scaledys)
s+=label
print(s)
if "SHADED" in environ:
plt.fill(data_tmp["CBMM"][0] + data_tmp["Linux"][0][::-1],
data_tmp["CBMM"][1] + data_tmp["Linux"][1][::-1], color=(1, 0, 0, 0.2))
plt.fill(data_tmp["CBMM,fragmented"][0] + data_tmp["Linux,fragmented"][0][::-1],
data_tmp["CBMM,fragmented"][1] + data_tmp["Linux,fragmented"][1][::-1], color=(1, 0, 0, 0.2))
# convert milliseconds to a human-readable label
def ms_to_label(ms, fp=1):
text = None
if ms < 1:
ms *= 1000.
text = "$\mu$s"
elif ms < 1000:
text = "ms"
elif ms < 60 * 1000:
ms /= 1000.
text = "s"
elif ms < 60 * 60 * 1000:
ms /= 60. * 1000.
text = "m"
else:
ms /= 60. * 60. * 1000.
text = "h"
return ("%." + str(fp) + "f %s") % (ms, text)
plt.ylabel("Avg time between events")
#plt.yscale("close_to_one")
plt.yscale("log")
plt.ylim((10**-1, 10**(NINES-4)))
yt, oldlab = plt.yticks()
yl = list(map(ms_to_label, yt))
print(yt)
print(yl)
plt.yticks(yt, yl)
plt.xscale("log")
#plt.xticks(rotation=90)
plt.xticks(rotation=45)
#plt.xlabel("Latency (%s)" % ("cycles" if FREQ is None else "usec"))
plt.xlabel("Latency")
plt.xlim((10,1e6))
xt, oldlab = plt.xticks()
xl = list(map(lambda x: ms_to_label(x/1000., 0), xt))
print(xt)
print(xl)
plt.xticks(xt, xl)
plt.grid(True)
if environ.get("NOLEGEND") is None:
plt.legend(bbox_to_anchor=(0, 1.05), loc='lower left', ncol=2)
#plt.legend(bbox_to_anchor=(1.05, 1.0), loc='upper left')
#plt.legend(loc='lower right')
plt.tight_layout()
plt.savefig("/tmp/%s.%s" % (OUTFNAME, ("pdf" if IS_PDF else "png")), bbox_inches="tight")
if not NOSHOW:
plt.show()