Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / bench / smalliobenchprocessor.py
1 import json
2 import sys
3 from pylab import hist
4 import gzip
5 import io
6
7 def get_next_line(line, output):
8     val = json.loads(line)
9     if val['type'] not in output:
10         output[val['type']] = {}
11     for (name, value) in val.items():
12         if name == "type":
13             continue
14         if name == "seq":
15             continue
16         if name not in output[val['type']]:
17             output[val['type']][name] = []
18         output[val['type']][name] += [float(value)]
19
20 def wrapgz(gfilename):
21     gfile = gzip.open(gfilename, 'rb')
22     if sys.version_info[0] >= 3:
23         gfile = io.TextIOWrapper(gfile)
24     return gfile
25
26 def read_all_input(filename):
27     cur = {}
28     openfn = open
29     if ".gz" in filename:
30         openfn = wrapgz
31     with openfn(filename) as fh:
32         for line in fh:
33             get_next_line(line, cur)
34     return cur
35
36 def write_committed_latency(out, bins, **kwargs):
37     hist(out['write_committed']['latency'], bins, **kwargs)
38
39 def read_latency(out):
40     hist(out['read']['latency'], 100)
41
42 def com(out): return out['write_committed']['latency']
43 def app(out): return out['write_applied']['latency']