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_table(data, types, vals): |
| 14 | """ create table by pyplot with diferences |
| 15 | between original and approximated |
| 16 | vals - values to make line""" |
| 17 | fields = 'blocksize_b', 'iops_mediana' |
| 18 | for tp in types: |
| 19 | filtered_data = filter_data('linearity_test_' + tp, fields) |
| 20 | # all values |
| 21 | x = [] |
| 22 | y = [] |
| 23 | # values to make line |
| 24 | ax = [] |
| 25 | ay = [] |
| 26 | |
| 27 | for sz, med in sorted(filtered_data(data)): |
| 28 | iotime_ms = 1000. // med |
| 29 | x.append(sz / 1024.0) |
| 30 | y.append(iotime_ms) |
| 31 | if sz in vals: |
| 32 | ax.append(sz / 1024.0) |
| 33 | ay.append(iotime_ms) |
| 34 | |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 35 | ynew = approximate_line(ax, ay, x, True) |
| 36 | |
| 37 | dif, _, _ = difference(y, ynew) |
| 38 | table_data = [] |
| 39 | for i, d in zip(x, dif): |
Ved-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 40 | 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] | 41 | table_data.append(row) |
| 42 | |
| 43 | tab = TT.Texttable() |
Ved-vampir | 1143b66 | 2015-04-11 00:05:05 +0300 | [diff] [blame] | 44 | tab.set_deco(tab.VLINES) |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 45 | |
| 46 | header = ["BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)"] |
| 47 | tab.add_row(header) |
| 48 | tab.header = header |
| 49 | |
| 50 | for row in table_data: |
| 51 | tab.add_row(row) |
| 52 | |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 53 | # uncomment to get table in pretty pictures :) |
| 54 | # colLabels = ("BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)") |
| 55 | # fig = plt.figure() |
| 56 | # ax = fig.add_subplot(111) |
| 57 | # ax.axis('off') |
| 58 | # #do the table |
| 59 | # the_table = ax.table(cellText=table_data, |
| 60 | # colLabels=colLabels, |
| 61 | # loc='center') |
| 62 | # plt.savefig(tp+".png") |
| 63 | |
| 64 | |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 65 | def th_plot(data, tt): |
| 66 | fields = 'concurence', 'iops_mediana', 'lat_mediana' |
| 67 | conc_4k = filter_data('concurrence_test_' + tt, fields, blocksize='4k') |
| 68 | filtered_data = sorted(list(conc_4k(data))) |
| 69 | |
| 70 | x, iops, lat = zip(*filtered_data) |
| 71 | |
| 72 | _, ax1 = plt.subplots() |
| 73 | |
| 74 | xnew = np.linspace(min(x), max(x), 50) |
| 75 | # plt.plot(xnew, power_smooth, 'b-', label='iops') |
| 76 | ax1.plot(x, iops, 'b*') |
| 77 | |
| 78 | for degree in (3,): |
| 79 | c = chebfit(x, iops, degree) |
| 80 | vals = chebval(xnew, c) |
| 81 | ax1.plot(xnew, vals, 'g--') |
| 82 | |
| 83 | # ax1.set_xlabel('thread count') |
| 84 | # ax1.set_ylabel('iops') |
| 85 | |
| 86 | # ax2 = ax1.twinx() |
| 87 | # lat = [i / 1000 for i in lat] |
| 88 | # ax2.plot(x, lat, 'r*') |
| 89 | |
| 90 | # tck = splrep(x, lat, s=0.0) |
| 91 | # power_smooth = splev(xnew, tck) |
| 92 | # ax2.plot(xnew, power_smooth, 'r-', label='lat') |
| 93 | |
| 94 | # xp = xnew[0] |
| 95 | # yp = power_smooth[0] |
| 96 | # for _x, _y in zip(xnew[1:], power_smooth[1:]): |
| 97 | # if _y >= 100: |
| 98 | # xres = (_y - 100.) / (_y - yp) * (_x - xp) + xp |
| 99 | # ax2.plot([xres, xres], [min(power_smooth), max(power_smooth)], 'g--') |
| 100 | # break |
| 101 | # xp = _x |
| 102 | # yp = _y |
| 103 | |
| 104 | # ax2.plot([min(x), max(x)], [20, 20], 'g--') |
| 105 | # ax2.plot([min(x), max(x)], [100, 100], 'g--') |
| 106 | |
| 107 | # ax2.set_ylabel("lat ms") |
| 108 | # plt.legend(loc=2) |
| 109 | |
| 110 | |
| 111 | def main(argv): |
| 112 | data = list(load_data(open(argv[1]).read())) |
Ved-vampir | 0316644 | 2015-04-10 17:28:23 +0300 | [diff] [blame] | 113 | linearity_table(data, ["rwd", "rws", "rrd"], [4096, 4096*1024]) |
| 114 | # linearity_plot(data, ["rwd", "rws", "rrd"])#, [4096, 4096*1024]) |
| 115 | # linearity_plot(data, ["rws", "rwd"]) |
| 116 | # th_plot(data, 'rws') |
koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 117 | # th_plot(data, 'rrs') |
| 118 | plt.show() |
| 119 | |
| 120 | |
| 121 | if __name__ == "__main__": |
| 122 | exit(main(sys.argv)) |