koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 1 | import sys |
| 2 | |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 3 | import texttable as TT |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 4 | |
| 5 | import numpy as np |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 6 | import matplotlib.pyplot as plt |
| 7 | from numpy.polynomial.chebyshev import chebfit, chebval |
| 8 | |
koder aka kdanilov | cff7b2e | 2015-04-18 20:48:15 +0300 | [diff] [blame^] | 9 | from .io_results_loader import load_data, filter_data |
| 10 | from .statistic import approximate_line, difference |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 11 | |
| 12 | |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 13 | def linearity_plot(data, types, vals=None): |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 14 | 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-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 24 | colors = ['red', 'green', 'blue', 'cyan', |
| 25 | 'magenta', 'black', 'yellow', 'burlywood'] |
| 26 | markers = ['*', '^', 'x', 'o', '+', '.'] |
| 27 | color = 0 |
| 28 | marker = 0 |
| 29 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 30 | for tp in types: |
| 31 | filtered_data = filter_data('linearity_test_' + tp, fields) |
| 32 | x = [] |
| 33 | y = [] |
| 34 | e = [] |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 35 | # values to make line |
| 36 | ax = [] |
| 37 | ay = [] |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 38 | |
| 39 | for sz, med, dev in sorted(filtered_data(data)): |
| 40 | iotime_ms = 1000. // med |
| 41 | iotime_max = 1000. // (med - dev * 3) |
| 42 | |
Ved-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 43 | x.append(sz / 1024.0) |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 44 | y.append(iotime_ms) |
| 45 | e.append(iotime_max - iotime_ms) |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 46 | if vals is None or sz in vals: |
Ved-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 47 | ax.append(sz / 1024.0) |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 48 | ay.append(iotime_ms) |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 49 | |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 50 | 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 57 | plt.legend(loc=2) |
Ved-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 58 | plt.title("Linearity test by %i dots" % (len(vals))) |
| 59 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 60 | |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 61 | def 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-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 83 | 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-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 88 | row = ["{0:.1f}".format(i), "{0:.1f}".format(d[0]), "{0:.0f}".format(d[1]*100)] |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 89 | table_data.append(row) |
| 90 | |
| 91 | tab = TT.Texttable() |
Ved-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 92 | tab.set_deco(tab.VLINES) |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 93 | |
| 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-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 101 | # 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 113 | def 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 | |
| 159 | def main(argv): |
| 160 | data = list(load_data(open(argv[1]).read())) |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 161 | 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 kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 165 | # th_plot(data, 'rrs') |
| 166 | plt.show() |
| 167 | |
| 168 | |
| 169 | if __name__ == "__main__": |
| 170 | exit(main(sys.argv)) |