blob: 2a476491250055b4d89167b5d04c9535563a071a [file] [log] [blame]
Yulia Portnova7ddfa732015-02-24 17:32:58 +02001import itertools
2import json
3import math
4
5
6def get_formatter(test_type):
koder aka kdanilov6e2ae792015-03-04 18:02:24 -08007 if test_type == "iozone" or test_type == "fio":
Yulia Portnova7ddfa732015-02-24 17:32:58 +02008 return format_io_stat
9 elif test_type == "pgbench":
10 return format_pgbench_stat
11 else:
12 raise Exception("Cannot get formatter for type %s" % test_type)
13
14
15def format_io_stat(res):
16 if len(res) != 0:
17 bw_mean = 0.0
18 for measurement in res:
19 bw_mean += measurement["bw_mean"]
20
21 bw_mean /= len(res)
22
23 it = ((bw_mean - measurement["bw_mean"]) ** 2 for measurement in res)
24 bw_dev = sum(it) ** 0.5
25
26 meta = res[0]['__meta__']
27
28 sync = meta['sync']
29 direct = meta['direct_io']
30
31 if sync and direct:
32 ss = "d+"
33 elif sync:
34 ss = "s"
35 elif direct:
36 ss = "d"
37 else:
38 ss = "a"
39
40 key = "{0} {1} {2} {3}k".format(meta['action'], ss,
41 meta['concurence'],
42 meta['blocksize'])
43
44 data = json.dumps({key: (int(bw_mean), int(bw_dev))})
45
46 return data
47
48
49def format_pgbench_stat(res):
50 """
51 Receives results in format:
52 "<num_clients> <num_transactions>: <tps>
53 <num_clients> <num_transactions>: <tps>
54 ....
55 "
56 """
57 if res:
58 data = {}
59 grouped_res = itertools.groupby(res, lambda x: x[0])
60 for key, group in grouped_res:
61 results = list(group)
62 sum_res = sum([r[1] for r in results])
63 mean = sum_res/len(results)
64 sum_sq = sum([(r[1] - mean) ** 2 for r in results])
yportnovaa47b33e2015-03-05 20:20:31 +020065 if len(results) > 1:
66 dev = math.sqrt(sum_sq / (len(results) - 1))
67 else:
68 dev = 0
Yulia Portnova7ddfa732015-02-24 17:32:58 +020069 data[key] = (mean, dev)
70 return data
71