blob: 434c844d0c9b2fe30bfad2100ffb41cf981ea837 [file] [log] [blame]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02001import argparse
2from collections import OrderedDict
3import sys
4
Yulia Portnova5c9c6dd2015-02-11 13:29:04 +02005from chart import charts
gstepanovec9048c2015-02-16 19:17:09 +02006
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02007
8
Yulia Portnova7b3b1d42015-02-13 14:08:35 +02009OPERATIONS = (('async', ('randwrite asynchronous', 'randread asynchronous',
10 'write asynchronous', 'read asynchronous')),
11 ('sync', ('randwrite synchronous', 'randread synchronous',
12 'write synchronous', 'read synchronous')))
13
14sync_async_view = {'s': 'synchronous',
15 'a': 'asynchronous'}
Yulia Portnova042344d2015-02-10 17:38:33 +020016
17
Yulia Portnova919f3be2015-02-06 12:49:22 +020018def 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 Portnova6d72d7f2015-02-04 16:48:50 +020035def 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 Portnova919f3be2015-02-06 12:49:22 +020045def build_vertical_bar(results):
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020046 data = {}
Yulia Portnova919f3be2015-02-06 12:49:22 +020047 charts_url = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020048
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020049 for build, results in results.items():
Yulia Portnova919f3be2015-02-06 12:49:22 +020050 for key, value in results.results.items():
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020051 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 Portnova7b3b1d42015-02-13 14:08:35 +020056 data[keys[2]][build][
57 ' '.join([keys[0], sync_async_view[keys[1]]])] = value
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020058
59 for name, value in data.items():
Yulia Portnova042344d2015-02-10 17:38:33 +020060 for op_type, operations in OPERATIONS:
Yulia Portnova7b3b1d42015-02-13 14:08:35 +020061 title = "Block size: " + name
Yulia Portnova042344d2015-02-10 17:38:33 +020062 legend = []
63 dataset = []
Yulia Portnovae4408022015-02-10 15:39:25 +020064
Yulia Portnova042344d2015-02-10 17:38:33 +020065 scale_x = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020066
Yulia Portnova042344d2015-02-10 17:38:33 +020067 for build_id, build_results in value.items():
68 vals = []
Yulia Portnovae4408022015-02-10 15:39:25 +020069
Yulia Portnova042344d2015-02-10 17:38:33 +020070 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 Portnova919f3be2015-02-06 12:49:22 +020082 return charts_url
83
84
85def 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 kdanilove21d7472015-02-14 19:02:04 -0800105
106 OD = OrderedDict
107 ordered_build_results = OD(sorted(build_results.items(),
108 key=lambda t: ssize_to_kb(t[0])))
109
Yulia Portnova919f3be2015-02-06 12:49:22 +0200110 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
120def 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
gstepanovec9048c2015-02-16 19:17:09 +0200131# 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 Portnova919f3be2015-02-06 12:49:22 +0200137
gstepanovec9048c2015-02-16 19:17:09 +0200138#
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:]))