blob: 4d23b6067077756ef34fe6f4fe89afa1a52018c6 [file] [log] [blame]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02001import argparse
2from collections import OrderedDict
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02003
Yulia Portnova5c9c6dd2015-02-11 13:29:04 +02004from chart import charts
koder aka kdanilov8ad6e812015-03-22 14:42:18 +02005from utils import ssize_to_kb
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02006
7
Yulia Portnova7b3b1d42015-02-13 14:08:35 +02008OPERATIONS = (('async', ('randwrite asynchronous', 'randread asynchronous',
9 'write asynchronous', 'read asynchronous')),
10 ('sync', ('randwrite synchronous', 'randread synchronous',
11 'write synchronous', 'read synchronous')))
12
13sync_async_view = {'s': 'synchronous',
14 'a': 'asynchronous'}
Yulia Portnova042344d2015-02-10 17:38:33 +020015
16
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020017def 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 Portnova919f3be2015-02-06 12:49:22 +020027def build_vertical_bar(results):
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020028 data = {}
Yulia Portnova919f3be2015-02-06 12:49:22 +020029 charts_url = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020030
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020031 for build, results in results.items():
Yulia Portnova919f3be2015-02-06 12:49:22 +020032 for key, value in results.results.items():
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020033 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 Portnova7b3b1d42015-02-13 14:08:35 +020038 data[keys[2]][build][
39 ' '.join([keys[0], sync_async_view[keys[1]]])] = value
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020040
41 for name, value in data.items():
Yulia Portnova042344d2015-02-10 17:38:33 +020042 for op_type, operations in OPERATIONS:
Yulia Portnova7b3b1d42015-02-13 14:08:35 +020043 title = "Block size: " + name
Yulia Portnova042344d2015-02-10 17:38:33 +020044 legend = []
45 dataset = []
Yulia Portnovae4408022015-02-10 15:39:25 +020046
Yulia Portnova042344d2015-02-10 17:38:33 +020047 scale_x = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020048
Yulia Portnova042344d2015-02-10 17:38:33 +020049 for build_id, build_results in value.items():
50 vals = []
Yulia Portnovae4408022015-02-10 15:39:25 +020051
Yulia Portnova042344d2015-02-10 17:38:33 +020052 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 Portnova919f3be2015-02-06 12:49:22 +020064 return charts_url
65
66
67def 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 kdanilove21d7472015-02-14 19:02:04 -080087
88 OD = OrderedDict
89 ordered_build_results = OD(sorted(build_results.items(),
90 key=lambda t: ssize_to_kb(t[0])))
91
Yulia Portnova919f3be2015-02-06 12:49:22 +020092 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
102def 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
gstepanovec9048c2015-02-16 19:17:09 +0200113# 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 Portnova919f3be2015-02-06 12:49:22 +0200119
gstepanovec9048c2015-02-16 19:17:09 +0200120#
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:]))