Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 1 | import argparse |
| 2 | from collections import OrderedDict |
| 3 | import sys |
| 4 | |
Yulia Portnova | 5c9c6dd | 2015-02-11 13:29:04 +0200 | [diff] [blame] | 5 | from chart import charts |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 6 | |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 7 | |
| 8 | |
Yulia Portnova | 7b3b1d4 | 2015-02-13 14:08:35 +0200 | [diff] [blame] | 9 | OPERATIONS = (('async', ('randwrite asynchronous', 'randread asynchronous', |
| 10 | 'write asynchronous', 'read asynchronous')), |
| 11 | ('sync', ('randwrite synchronous', 'randread synchronous', |
| 12 | 'write synchronous', 'read synchronous'))) |
| 13 | |
| 14 | sync_async_view = {'s': 'synchronous', |
| 15 | 'a': 'asynchronous'} |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 16 | |
| 17 | |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 18 | def ssize_to_kb(ssize): |
| 19 | try: |
| 20 | smap = dict(k=1, K=1, M=1024, m=1024, G=1024**2, g=1024**2) |
| 21 | for ext, coef in smap.items(): |
| 22 | if ssize.endswith(ext): |
| 23 | return int(ssize[:-1]) * coef |
| 24 | |
| 25 | if int(ssize) % 1024 != 0: |
| 26 | raise ValueError() |
| 27 | |
| 28 | return int(ssize) / 1024 |
| 29 | |
| 30 | except (ValueError, TypeError, AttributeError): |
| 31 | tmpl = "Unknow size format {0!r} (or size not multiples 1024)" |
| 32 | raise ValueError(tmpl.format(ssize)) |
| 33 | |
| 34 | |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 35 | def parse_args(argv): |
| 36 | parser = argparse.ArgumentParser() |
| 37 | parser.add_argument('-s', '--storage', help='storage location', dest="url") |
| 38 | parser.add_argument('-e', '--email', help='user email', |
| 39 | default="aaa@gmail.com") |
| 40 | parser.add_argument('-p', '--password', help='user password', |
| 41 | default="1234") |
| 42 | return parser.parse_args(argv) |
| 43 | |
| 44 | |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 45 | def build_vertical_bar(results): |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 46 | data = {} |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 47 | charts_url = [] |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 48 | |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 49 | for build, results in results.items(): |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 50 | for key, value in results.results.items(): |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 51 | keys = key.split(' ') |
| 52 | if not data.get(keys[2]): |
| 53 | data[keys[2]] = {} |
| 54 | if not data[keys[2]].get(build): |
| 55 | data[keys[2]][build] = {} |
Yulia Portnova | 7b3b1d4 | 2015-02-13 14:08:35 +0200 | [diff] [blame] | 56 | data[keys[2]][build][ |
| 57 | ' '.join([keys[0], sync_async_view[keys[1]]])] = value |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 58 | |
| 59 | for name, value in data.items(): |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 60 | for op_type, operations in OPERATIONS: |
Yulia Portnova | 7b3b1d4 | 2015-02-13 14:08:35 +0200 | [diff] [blame] | 61 | title = "Block size: " + name |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 62 | legend = [] |
| 63 | dataset = [] |
Yulia Portnova | e440802 | 2015-02-10 15:39:25 +0200 | [diff] [blame] | 64 | |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 65 | scale_x = [] |
Yulia Portnova | 6d72d7f | 2015-02-04 16:48:50 +0200 | [diff] [blame] | 66 | |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 67 | for build_id, build_results in value.items(): |
| 68 | vals = [] |
Yulia Portnova | e440802 | 2015-02-10 15:39:25 +0200 | [diff] [blame] | 69 | |
Yulia Portnova | 042344d | 2015-02-10 17:38:33 +0200 | [diff] [blame] | 70 | for key in operations: |
| 71 | res = build_results.get(key) |
| 72 | if res: |
| 73 | vals.append(res) |
| 74 | scale_x.append(key) |
| 75 | if vals: |
| 76 | dataset.append(vals) |
| 77 | legend.append(build_id) |
| 78 | |
| 79 | if dataset: |
| 80 | charts_url.append(str(charts.render_vertical_bar |
| 81 | (title, legend, dataset, scale_x=scale_x))) |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 82 | return charts_url |
| 83 | |
| 84 | |
| 85 | def build_lines_chart(results): |
| 86 | data = {} |
| 87 | charts_url = [] |
| 88 | |
| 89 | for build, results in results.items(): |
| 90 | for key, value in results.results.items(): |
| 91 | keys = key.split(' ') |
| 92 | if not data.get(' '.join([keys[0], keys[1]])): |
| 93 | data[' '.join([keys[0], keys[1]])] = {} |
| 94 | if not data[' '.join([keys[0], keys[1]])].get(build): |
| 95 | data[' '.join([keys[0], keys[1]])][build] = {} |
| 96 | data[' '.join([keys[0], keys[1]])][build][keys[2]] = value |
| 97 | |
| 98 | for name, value in data.items(): |
| 99 | title = name |
| 100 | legend = [] |
| 101 | dataset = [] |
| 102 | scale_x = [] |
| 103 | for build_id, build_results in value.items(): |
| 104 | legend.append(build_id) |
koder aka kdanilov | e21d747 | 2015-02-14 19:02:04 -0800 | [diff] [blame] | 105 | |
| 106 | OD = OrderedDict |
| 107 | ordered_build_results = OD(sorted(build_results.items(), |
| 108 | key=lambda t: ssize_to_kb(t[0]))) |
| 109 | |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 110 | if not scale_x: |
| 111 | scale_x = ordered_build_results.keys() |
| 112 | dataset.append(zip(*ordered_build_results.values())[0]) |
| 113 | |
| 114 | chart = charts.render_lines(title, legend, dataset, scale_x) |
| 115 | charts_url.append(str(chart)) |
| 116 | |
| 117 | return charts_url |
| 118 | |
| 119 | |
| 120 | def render_html(charts_urls): |
| 121 | templ = open("report.html", 'r').read() |
| 122 | body = "<div><ol>%s</ol></div>" |
| 123 | li = "<li><img src='%s'></li>" |
| 124 | ol = [] |
| 125 | for chart in charts_urls: |
| 126 | ol.append(li % chart) |
| 127 | html = templ % {'body': body % '\n'.join(ol)} |
| 128 | open('results.html', 'w').write(html) |
| 129 | |
| 130 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 131 | # def report(url, email=None, password=None): |
| 132 | # results = storage.recent_builds() |
| 133 | # bars = build_vertical_bar(results) |
| 134 | # lines = build_lines_chart(results) |
| 135 | # |
| 136 | # render_html(bars + lines) |
Yulia Portnova | 919f3be | 2015-02-06 12:49:22 +0200 | [diff] [blame] | 137 | |
gstepanov | ec9048c | 2015-02-16 19:17:09 +0200 | [diff] [blame] | 138 | # |
| 139 | # def main(argv): |
| 140 | # opts = parse_args(argv) |
| 141 | # report(opts.url) |
| 142 | # return 0 |
| 143 | # |
| 144 | # |
| 145 | # if __name__ == '__main__': |
| 146 | # exit(main(sys.argv[1:])) |