blob: a9d717d2b5691c8c6e1315ca7bd1a54efd1c02f8 [file] [log] [blame]
Yulia Portnova6d72d7f2015-02-04 16:48:50 +02001import argparse
2from collections import OrderedDict
3import sys
4
5import charts
6import storage_api
7
8
Yulia Portnova042344d2015-02-10 17:38:33 +02009OPERATIONS = ('sync', ('randwrite a', 'randread a', 'write a', 'read a'),
10 'async', ('randwrite s', 'randread s', 'write s', 'read s'))
11
12
Yulia Portnova919f3be2015-02-06 12:49:22 +020013def ssize_to_kb(ssize):
14 try:
15 smap = dict(k=1, K=1, M=1024, m=1024, G=1024**2, g=1024**2)
16 for ext, coef in smap.items():
17 if ssize.endswith(ext):
18 return int(ssize[:-1]) * coef
19
20 if int(ssize) % 1024 != 0:
21 raise ValueError()
22
23 return int(ssize) / 1024
24
25 except (ValueError, TypeError, AttributeError):
26 tmpl = "Unknow size format {0!r} (or size not multiples 1024)"
27 raise ValueError(tmpl.format(ssize))
28
29
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020030def parse_args(argv):
31 parser = argparse.ArgumentParser()
32 parser.add_argument('-s', '--storage', help='storage location', dest="url")
33 parser.add_argument('-e', '--email', help='user email',
34 default="aaa@gmail.com")
35 parser.add_argument('-p', '--password', help='user password',
36 default="1234")
37 return parser.parse_args(argv)
38
39
Yulia Portnova919f3be2015-02-06 12:49:22 +020040def build_vertical_bar(results):
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020041 data = {}
Yulia Portnova919f3be2015-02-06 12:49:22 +020042 charts_url = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020043
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020044 for build, results in results.items():
Yulia Portnova919f3be2015-02-06 12:49:22 +020045 for key, value in results.results.items():
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020046 keys = key.split(' ')
47 if not data.get(keys[2]):
48 data[keys[2]] = {}
49 if not data[keys[2]].get(build):
50 data[keys[2]][build] = {}
51 data[keys[2]][build][' '.join([keys[0], keys[1]])] = value
52
53 for name, value in data.items():
Yulia Portnova042344d2015-02-10 17:38:33 +020054 for op_type, operations in OPERATIONS:
55 title = name
56 legend = []
57 dataset = []
Yulia Portnovae4408022015-02-10 15:39:25 +020058
Yulia Portnova042344d2015-02-10 17:38:33 +020059 scale_x = []
Yulia Portnova6d72d7f2015-02-04 16:48:50 +020060
Yulia Portnova042344d2015-02-10 17:38:33 +020061 for build_id, build_results in value.items():
62 vals = []
Yulia Portnovae4408022015-02-10 15:39:25 +020063
Yulia Portnova042344d2015-02-10 17:38:33 +020064 for key in operations:
65 res = build_results.get(key)
66 if res:
67 vals.append(res)
68 scale_x.append(key)
69 if vals:
70 dataset.append(vals)
71 legend.append(build_id)
72
73 if dataset:
74 charts_url.append(str(charts.render_vertical_bar
75 (title, legend, dataset, scale_x=scale_x)))
Yulia Portnova919f3be2015-02-06 12:49:22 +020076 return charts_url
77
78
79def build_lines_chart(results):
80 data = {}
81 charts_url = []
82
83 for build, results in results.items():
84 for key, value in results.results.items():
85 keys = key.split(' ')
86 if not data.get(' '.join([keys[0], keys[1]])):
87 data[' '.join([keys[0], keys[1]])] = {}
88 if not data[' '.join([keys[0], keys[1]])].get(build):
89 data[' '.join([keys[0], keys[1]])][build] = {}
90 data[' '.join([keys[0], keys[1]])][build][keys[2]] = value
91
92 for name, value in data.items():
93 title = name
94 legend = []
95 dataset = []
96 scale_x = []
97 for build_id, build_results in value.items():
98 legend.append(build_id)
99 ordered_build_results = OrderedDict(sorted(build_results.items(),
100 key=lambda t: ssize_to_kb(t[0])))
101 if not scale_x:
102 scale_x = ordered_build_results.keys()
103 dataset.append(zip(*ordered_build_results.values())[0])
104
105 chart = charts.render_lines(title, legend, dataset, scale_x)
106 charts_url.append(str(chart))
107
108 return charts_url
109
110
111def render_html(charts_urls):
112 templ = open("report.html", 'r').read()
113 body = "<div><ol>%s</ol></div>"
114 li = "<li><img src='%s'></li>"
115 ol = []
116 for chart in charts_urls:
117 ol.append(li % chart)
118 html = templ % {'body': body % '\n'.join(ol)}
119 open('results.html', 'w').write(html)
120
121
122def report(url, email=None, password=None):
123 storage = storage_api.create_storage(url, email, password)
124 results = storage.recent_builds()
125 bars = build_vertical_bar(results)
126 lines = build_lines_chart(results)
127
128 render_html(bars + lines)
Yulia Portnova6d72d7f2015-02-04 16:48:50 +0200129
130
131def main(argv):
132 opts = parse_args(argv)
133 report(opts.url)
134 return 0
135
136
137if __name__ == '__main__':
138 exit(main(sys.argv[1:]))