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