blob: 41ae2e02fe211da6974d3348e82effb09a46e13b [file] [log] [blame]
koder aka kdanilov6c491062015-04-09 22:33:13 +03001import sys
2
Ved-vampir03166442015-04-10 17:28:23 +03003import texttable as TT
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03004
5import numpy as np
koder aka kdanilov6c491062015-04-09 22:33:13 +03006import matplotlib.pyplot as plt
7from numpy.polynomial.chebyshev import chebfit, chebval
8
koder aka kdanilovcff7b2e2015-04-18 20:48:15 +03009from .io_results_loader import load_data, filter_data
10from .statistic import approximate_line, difference
koder aka kdanilov6c491062015-04-09 22:33:13 +030011
12
Ved-vampir03166442015-04-10 17:28:23 +030013def linearity_plot(data, types, vals=None):
koder aka kdanilov6c491062015-04-09 22:33:13 +030014 fields = 'blocksize_b', 'iops_mediana', 'iops_stddev'
15
16 names = {}
17 for tp1 in ('rand', 'seq'):
18 for oper in ('read', 'write'):
19 for sync in ('sync', 'direct', 'async'):
20 sq = (tp1, oper, sync)
21 name = "{0} {1} {2}".format(*sq)
22 names["".join(word[0] for word in sq)] = name
23
Ved-vampir03166442015-04-10 17:28:23 +030024 colors = ['red', 'green', 'blue', 'cyan',
25 'magenta', 'black', 'yellow', 'burlywood']
26 markers = ['*', '^', 'x', 'o', '+', '.']
27 color = 0
28 marker = 0
29
koder aka kdanilov6c491062015-04-09 22:33:13 +030030 for tp in types:
31 filtered_data = filter_data('linearity_test_' + tp, fields)
32 x = []
33 y = []
34 e = []
Ved-vampir03166442015-04-10 17:28:23 +030035 # values to make line
36 ax = []
37 ay = []
koder aka kdanilov6c491062015-04-09 22:33:13 +030038
39 for sz, med, dev in sorted(filtered_data(data)):
40 iotime_ms = 1000. // med
41 iotime_max = 1000. // (med - dev * 3)
42
Ved-vampir1143b662015-04-11 00:05:05 +030043 x.append(sz / 1024.0)
koder aka kdanilov6c491062015-04-09 22:33:13 +030044 y.append(iotime_ms)
45 e.append(iotime_max - iotime_ms)
Ved-vampir03166442015-04-10 17:28:23 +030046 if vals is None or sz in vals:
Ved-vampir1143b662015-04-11 00:05:05 +030047 ax.append(sz / 1024.0)
Ved-vampir03166442015-04-10 17:28:23 +030048 ay.append(iotime_ms)
koder aka kdanilov6c491062015-04-09 22:33:13 +030049
Ved-vampir03166442015-04-10 17:28:23 +030050 plt.errorbar(x, y, e, linestyle='None', label=names[tp],
51 color=colors[color], ecolor="black",
52 marker=markers[marker])
53 ynew = approximate_line(ax, ay, ax, True)
54 plt.plot(ax, ynew, color=colors[color])
55 color += 1
56 marker += 1
koder aka kdanilov6c491062015-04-09 22:33:13 +030057 plt.legend(loc=2)
Ved-vampir1143b662015-04-11 00:05:05 +030058 plt.title("Linearity test by %i dots" % (len(vals)))
59
koder aka kdanilov6c491062015-04-09 22:33:13 +030060
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
Ved-vampir03166442015-04-10 17:28:23 +030083 ynew = approximate_line(ax, ay, x, True)
84
85 dif, _, _ = difference(y, ynew)
86 table_data = []
87 for i, d in zip(x, dif):
Ved-vampir1143b662015-04-11 00:05:05 +030088 row = ["{0:.1f}".format(i), "{0:.1f}".format(d[0]), "{0:.0f}".format(d[1]*100)]
Ved-vampir03166442015-04-10 17:28:23 +030089 table_data.append(row)
90
91 tab = TT.Texttable()
Ved-vampir1143b662015-04-11 00:05:05 +030092 tab.set_deco(tab.VLINES)
Ved-vampir03166442015-04-10 17:28:23 +030093
94 header = ["BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)"]
95 tab.add_row(header)
96 tab.header = header
97
98 for row in table_data:
99 tab.add_row(row)
100
Ved-vampir03166442015-04-10 17:28:23 +0300101 # uncomment to get table in pretty pictures :)
102 # colLabels = ("BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)")
103 # fig = plt.figure()
104 # ax = fig.add_subplot(111)
105 # ax.axis('off')
106 # #do the table
107 # the_table = ax.table(cellText=table_data,
108 # colLabels=colLabels,
109 # loc='center')
110 # plt.savefig(tp+".png")
111
112
koder aka kdanilov6c491062015-04-09 22:33:13 +0300113def th_plot(data, tt):
114 fields = 'concurence', 'iops_mediana', 'lat_mediana'
115 conc_4k = filter_data('concurrence_test_' + tt, fields, blocksize='4k')
116 filtered_data = sorted(list(conc_4k(data)))
117
118 x, iops, lat = zip(*filtered_data)
119
120 _, ax1 = plt.subplots()
121
122 xnew = np.linspace(min(x), max(x), 50)
123 # plt.plot(xnew, power_smooth, 'b-', label='iops')
124 ax1.plot(x, iops, 'b*')
125
126 for degree in (3,):
127 c = chebfit(x, iops, degree)
128 vals = chebval(xnew, c)
129 ax1.plot(xnew, vals, 'g--')
130
131 # ax1.set_xlabel('thread count')
132 # ax1.set_ylabel('iops')
133
134 # ax2 = ax1.twinx()
135 # lat = [i / 1000 for i in lat]
136 # ax2.plot(x, lat, 'r*')
137
138 # tck = splrep(x, lat, s=0.0)
139 # power_smooth = splev(xnew, tck)
140 # ax2.plot(xnew, power_smooth, 'r-', label='lat')
141
142 # xp = xnew[0]
143 # yp = power_smooth[0]
144 # for _x, _y in zip(xnew[1:], power_smooth[1:]):
145 # if _y >= 100:
146 # xres = (_y - 100.) / (_y - yp) * (_x - xp) + xp
147 # ax2.plot([xres, xres], [min(power_smooth), max(power_smooth)], 'g--')
148 # break
149 # xp = _x
150 # yp = _y
151
152 # ax2.plot([min(x), max(x)], [20, 20], 'g--')
153 # ax2.plot([min(x), max(x)], [100, 100], 'g--')
154
155 # ax2.set_ylabel("lat ms")
156 # plt.legend(loc=2)
157
158
159def main(argv):
160 data = list(load_data(open(argv[1]).read()))
Ved-vampir03166442015-04-10 17:28:23 +0300161 linearity_table(data, ["rwd", "rws", "rrd"], [4096, 4096*1024])
162 # linearity_plot(data, ["rwd", "rws", "rrd"])#, [4096, 4096*1024])
163 # linearity_plot(data, ["rws", "rwd"])
164 # th_plot(data, 'rws')
koder aka kdanilov6c491062015-04-09 22:33:13 +0300165 # th_plot(data, 'rrs')
166 plt.show()
167
168
169if __name__ == "__main__":
170 exit(main(sys.argv))