Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 1 | import itertools |
| 2 | import json |
| 3 | import math |
| 4 | |
| 5 | |
| 6 | def get_formatter(test_type): |
koder aka kdanilov | 6e2ae79 | 2015-03-04 18:02:24 -0800 | [diff] [blame] | 7 | if test_type == "iozone" or test_type == "fio": |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 8 | 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 | |
| 15 | def 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 | |
| 49 | def 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]) |
yportnova | a47b33e | 2015-03-05 20:20:31 +0200 | [diff] [blame] | 65 | if len(results) > 1: |
| 66 | dev = math.sqrt(sum_sq / (len(results) - 1)) |
| 67 | else: |
| 68 | dev = 0 |
Yulia Portnova | 7ddfa73 | 2015-02-24 17:32:58 +0200 | [diff] [blame] | 69 | data[key] = (mean, dev) |
| 70 | return data |
| 71 | |