96de28a1937e6991b74f66dd1f48f59c54c7f0ff
[bluesky.git] / results / parse-sfsres.py
1 #!/usr/bin/python
2 # coding=utf-8
3 #
4 # Parse the sfsres log file generated by SPECsfs to generate more detailed
5 # latency statistics than in the sfssum summary file.
6
7 import re, sys
8
9 def extract_re(lines, regexp):
10     if isinstance(regexp, str):
11         regexp = re.compile(regexp)
12     for l in lines:
13         m = regexp.match(l)
14         if m: return m
15
16 def parse_run(lines, timestamp, outfp=sys.stdout):
17     #print timestamp
18     requested_load = extract_re(lines, r"\s*Requested Load.*= (\d+)")
19     load = int(requested_load.group(1))
20     results = extract_re(lines, r"SFS NFS THROUGHPUT:\s*([\d.]+).*RESPONSE TIME:\s*([\d.]+) Msec/Op")
21
22     # Extract the stable of per-operation counts, response times, etc.
23     regexp = re.compile(r"^(\w+)" + r"\s*([\d.]+)%?" * 9)
24     table = {}
25     for l in lines:
26         m = regexp.match(l)
27         if m:
28             table[m.group(1)] = [float(m.group(i)) for i in range(2, 11)]
29
30     outfp.write("%d\t%s\t%s" % (load, results.group(1), results.group(2)))
31     for o in ('read', 'write', 'getattr'):
32         outfp.write("\t%s\t%s" % (table[o][5], table[o][6]))
33     outfp.write("\n")
34
35 def parse_sfsres(fp):
36     timestamp = None
37     run_data = []
38     for line in fp:
39         m = re.match(r"^([^*]+) \*{32,}$", line)
40         if m:
41             if len(run_data) > 0:
42                 parse_run(run_data, timestamp)
43             run_data = []
44             timestamp = m.group(1)
45         else:
46             run_data.append(line)
47     if len(run_data) > 0:
48         parse_run(run_data, timestamp)
49
50 if __name__ == '__main__':
51     parse_sfsres(sys.stdin)