| import sys |
| |
| import texttable as TT |
| |
| import numpy as np |
| import matplotlib.pyplot as plt |
| from numpy.polynomial.chebyshev import chebfit, chebval |
| |
| from .io_results_loader import load_data, filter_data |
| from .statistic import approximate_line, difference |
| |
| |
| def linearity_table(data, types, vals): |
| """ create table by pyplot with diferences |
| between original and approximated |
| vals - values to make line""" |
| fields = 'blocksize_b', 'iops_mediana' |
| for tp in types: |
| filtered_data = filter_data('linearity_test_' + tp, fields) |
| # all values |
| x = [] |
| y = [] |
| # values to make line |
| ax = [] |
| ay = [] |
| |
| for sz, med in sorted(filtered_data(data)): |
| iotime_ms = 1000. // med |
| x.append(sz / 1024.0) |
| y.append(iotime_ms) |
| if sz in vals: |
| ax.append(sz / 1024.0) |
| ay.append(iotime_ms) |
| |
| ynew = approximate_line(ax, ay, x, True) |
| |
| dif, _, _ = difference(y, ynew) |
| table_data = [] |
| for i, d in zip(x, dif): |
| row = ["{0:.1f}".format(i), "{0:.1f}".format(d[0]), "{0:.0f}".format(d[1]*100)] |
| table_data.append(row) |
| |
| tab = TT.Texttable() |
| tab.set_deco(tab.VLINES) |
| |
| header = ["BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)"] |
| tab.add_row(header) |
| tab.header = header |
| |
| for row in table_data: |
| tab.add_row(row) |
| |
| # uncomment to get table in pretty pictures :) |
| # colLabels = ("BlockSize, kB", "Absolute difference (ms)", "Relative difference (%)") |
| # fig = plt.figure() |
| # ax = fig.add_subplot(111) |
| # ax.axis('off') |
| # #do the table |
| # the_table = ax.table(cellText=table_data, |
| # colLabels=colLabels, |
| # loc='center') |
| # plt.savefig(tp+".png") |
| |
| |
| def th_plot(data, tt): |
| fields = 'concurence', 'iops_mediana', 'lat_mediana' |
| conc_4k = filter_data('concurrence_test_' + tt, fields, blocksize='4k') |
| filtered_data = sorted(list(conc_4k(data))) |
| |
| x, iops, lat = zip(*filtered_data) |
| |
| _, ax1 = plt.subplots() |
| |
| xnew = np.linspace(min(x), max(x), 50) |
| # plt.plot(xnew, power_smooth, 'b-', label='iops') |
| ax1.plot(x, iops, 'b*') |
| |
| for degree in (3,): |
| c = chebfit(x, iops, degree) |
| vals = chebval(xnew, c) |
| ax1.plot(xnew, vals, 'g--') |
| |
| # ax1.set_xlabel('thread count') |
| # ax1.set_ylabel('iops') |
| |
| # ax2 = ax1.twinx() |
| # lat = [i / 1000 for i in lat] |
| # ax2.plot(x, lat, 'r*') |
| |
| # tck = splrep(x, lat, s=0.0) |
| # power_smooth = splev(xnew, tck) |
| # ax2.plot(xnew, power_smooth, 'r-', label='lat') |
| |
| # xp = xnew[0] |
| # yp = power_smooth[0] |
| # for _x, _y in zip(xnew[1:], power_smooth[1:]): |
| # if _y >= 100: |
| # xres = (_y - 100.) / (_y - yp) * (_x - xp) + xp |
| # ax2.plot([xres, xres], [min(power_smooth), max(power_smooth)], 'g--') |
| # break |
| # xp = _x |
| # yp = _y |
| |
| # ax2.plot([min(x), max(x)], [20, 20], 'g--') |
| # ax2.plot([min(x), max(x)], [100, 100], 'g--') |
| |
| # ax2.set_ylabel("lat ms") |
| # plt.legend(loc=2) |
| |
| |
| def main(argv): |
| data = list(load_data(open(argv[1]).read())) |
| linearity_table(data, ["rwd", "rws", "rrd"], [4096, 4096*1024]) |
| # linearity_plot(data, ["rwd", "rws", "rrd"])#, [4096, 4096*1024]) |
| # linearity_plot(data, ["rws", "rwd"]) |
| # th_plot(data, 'rws') |
| # th_plot(data, 'rrs') |
| plt.show() |
| |
| |
| if __name__ == "__main__": |
| exit(main(sys.argv)) |