blob: fdea7e1c5be8c26a41c31425c716c6b63e1b1dda [file] [log] [blame]
koder aka kdanilov6c491062015-04-09 22:33:13 +03001import sys
2
3import numpy as np
Ved-vampir03166442015-04-10 17:28:23 +03004import texttable as TT
koder aka kdanilov6c491062015-04-09 22:33:13 +03005import matplotlib.pyplot as plt
6from numpy.polynomial.chebyshev import chebfit, chebval
7
Ved-vampir03166442015-04-10 17:28:23 +03008from io_results_loader import load_data, filter_data
9from statistic import approximate_line, difference, round_deviation
koder aka kdanilov6c491062015-04-09 22:33:13 +030010
11
Ved-vampir03166442015-04-10 17:28:23 +030012def linearity_plot(data, types, vals=None):
koder aka kdanilov6c491062015-04-09 22:33:13 +030013 fields = 'blocksize_b', 'iops_mediana', 'iops_stddev'
14
15 names = {}
16 for tp1 in ('rand', 'seq'):
17 for oper in ('read', 'write'):
18 for sync in ('sync', 'direct', 'async'):
19 sq = (tp1, oper, sync)
20 name = "{0} {1} {2}".format(*sq)
21 names["".join(word[0] for word in sq)] = name
22
Ved-vampir03166442015-04-10 17:28:23 +030023 colors = ['red', 'green', 'blue', 'cyan',
24 'magenta', 'black', 'yellow', 'burlywood']
25 markers = ['*', '^', 'x', 'o', '+', '.']
26 color = 0
27 marker = 0
28
koder aka kdanilov6c491062015-04-09 22:33:13 +030029 for tp in types:
30 filtered_data = filter_data('linearity_test_' + tp, fields)
31 x = []
32 y = []
33 e = []
Ved-vampir03166442015-04-10 17:28:23 +030034 # values to make line
35 ax = []
36 ay = []
koder aka kdanilov6c491062015-04-09 22:33:13 +030037
38 for sz, med, dev in sorted(filtered_data(data)):
39 iotime_ms = 1000. // med
40 iotime_max = 1000. // (med - dev * 3)
41
Ved-vampir1143b662015-04-11 00:05:05 +030042 x.append(sz / 1024.0)
koder aka kdanilov6c491062015-04-09 22:33:13 +030043 y.append(iotime_ms)
44 e.append(iotime_max - iotime_ms)
Ved-vampir03166442015-04-10 17:28:23 +030045 if vals is None or sz in vals:
Ved-vampir1143b662015-04-11 00:05:05 +030046 ax.append(sz / 1024.0)
Ved-vampir03166442015-04-10 17:28:23 +030047 ay.append(iotime_ms)
koder aka kdanilov6c491062015-04-09 22:33:13 +030048
Ved-vampir03166442015-04-10 17:28:23 +030049 plt.errorbar(x, y, e, linestyle='None', label=names[tp],
50 color=colors[color], ecolor="black",
51 marker=markers[marker])
52 ynew = approximate_line(ax, ay, ax, True)
53 plt.plot(ax, ynew, color=colors[color])
54 color += 1
55 marker += 1
koder aka kdanilov6c491062015-04-09 22:33:13 +030056 plt.legend(loc=2)
Ved-vampir1143b662015-04-11 00:05:05 +030057 plt.title("Linearity test by %i dots" % (len(vals)))
58
koder aka kdanilov6c491062015-04-09 22:33:13 +030059
60
Ved-vampir03166442015-04-10 17:28:23 +030061def linearity_table(data, types, vals):
62 """ create table by pyplot with diferences
63 between original and approximated
64 vals - values to make line"""
65 fields = 'blocksize_b', 'iops_mediana'
66 for tp in types:
67 filtered_data = filter_data('linearity_test_' + tp, fields)
68 # all values
69 x = []
70 y = []
71 # values to make line
72 ax = []
73 ay = []
74
75 for sz, med in sorted(filtered_data(data)):
76 iotime_ms = 1000. // med
77 x.append(sz / 1024.0)
78 y.append(iotime_ms)
79 if sz in vals:
80 ax.append(sz / 1024.0)
81 ay.append(iotime_ms)
82
83
84 ynew = approximate_line(ax, ay, x, True)
85
86 dif, _, _ = difference(y, ynew)
87 table_data = []
88 for i, d in zip(x, dif):
Ved-vampir1143b662015-04-11 00:05:05 +030089 row = ["{0:.1f}".format(i), "{0:.1f}".format(d[0]), "{0:.0f}".format(d[1]*100)]
Ved-vampir03166442015-04-10 17:28:23 +030090 table_data.append(row)
91
92 tab = TT.Texttable()
Ved-vampir1143b662015-04-11 00:05:05 +030093 tab.set_deco(tab.VLINES)
Ved-vampir03166442015-04-10 17:28:23 +030094
95 header = ["BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)"]
96 tab.add_row(header)
97 tab.header = header
98
99 for row in table_data:
100 tab.add_row(row)
101
102 print tp
103 print tab.draw()
104
105 # uncomment to get table in pretty pictures :)
106 # colLabels = ("BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)")
107 # fig = plt.figure()
108 # ax = fig.add_subplot(111)
109 # ax.axis('off')
110 # #do the table
111 # the_table = ax.table(cellText=table_data,
112 # colLabels=colLabels,
113 # loc='center')
114 # plt.savefig(tp+".png")
115
116
koder aka kdanilov6c491062015-04-09 22:33:13 +0300117def th_plot(data, tt):
118 fields = 'concurence', 'iops_mediana', 'lat_mediana'
119 conc_4k = filter_data('concurrence_test_' + tt, fields, blocksize='4k')
120 filtered_data = sorted(list(conc_4k(data)))
121
122 x, iops, lat = zip(*filtered_data)
123
124 _, ax1 = plt.subplots()
125
126 xnew = np.linspace(min(x), max(x), 50)
127 # plt.plot(xnew, power_smooth, 'b-', label='iops')
128 ax1.plot(x, iops, 'b*')
129
130 for degree in (3,):
131 c = chebfit(x, iops, degree)
132 vals = chebval(xnew, c)
133 ax1.plot(xnew, vals, 'g--')
134
135 # ax1.set_xlabel('thread count')
136 # ax1.set_ylabel('iops')
137
138 # ax2 = ax1.twinx()
139 # lat = [i / 1000 for i in lat]
140 # ax2.plot(x, lat, 'r*')
141
142 # tck = splrep(x, lat, s=0.0)
143 # power_smooth = splev(xnew, tck)
144 # ax2.plot(xnew, power_smooth, 'r-', label='lat')
145
146 # xp = xnew[0]
147 # yp = power_smooth[0]
148 # for _x, _y in zip(xnew[1:], power_smooth[1:]):
149 # if _y >= 100:
150 # xres = (_y - 100.) / (_y - yp) * (_x - xp) + xp
151 # ax2.plot([xres, xres], [min(power_smooth), max(power_smooth)], 'g--')
152 # break
153 # xp = _x
154 # yp = _y
155
156 # ax2.plot([min(x), max(x)], [20, 20], 'g--')
157 # ax2.plot([min(x), max(x)], [100, 100], 'g--')
158
159 # ax2.set_ylabel("lat ms")
160 # plt.legend(loc=2)
161
162
163def main(argv):
164 data = list(load_data(open(argv[1]).read()))
Ved-vampir03166442015-04-10 17:28:23 +0300165 linearity_table(data, ["rwd", "rws", "rrd"], [4096, 4096*1024])
166 # linearity_plot(data, ["rwd", "rws", "rrd"])#, [4096, 4096*1024])
167 # linearity_plot(data, ["rws", "rwd"])
168 # th_plot(data, 'rws')
koder aka kdanilov6c491062015-04-09 22:33:13 +0300169 # th_plot(data, 'rrs')
170 plt.show()
171
172
173if __name__ == "__main__":
174 exit(main(sys.argv))