7890715e178511cf10d7a3e2dfd8c91a6a82dfe8
[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 OPERATIONS = ('read', 'write', 'create', 'setattr', 'lookup', 'getattr')
17
18 def parse_run(lines, timestamp, outfp=sys.stdout):
19     #print timestamp
20     requested_load = extract_re(lines, r"\s*Requested Load.*= (\d+)")
21     load = int(requested_load.group(1))
22     results = extract_re(lines, r"SFS NFS THROUGHPUT:\s*([\d.]+).*RESPONSE TIME:\s*([\d.]+) Msec/Op")
23
24     # Extract the stable of per-operation counts, response times, etc.
25     regexp = re.compile(r"^(\w+)" + r"\s*([\d.]+)%?" * 9)
26     table = {}
27     for l in lines:
28         m = regexp.match(l)
29         if m:
30             try:
31                 table[m.group(1)] = [float(m.group(i)) for i in range(2, 11)]
32             except:
33                 #sys.stderr.write("Error parsing line: " + l.strip() + "\n")
34                 pass
35
36     outfp.write("%d\t%s\t%s" % (load, results.group(1), results.group(2)))
37     for o in OPERATIONS:
38         val = '-'
39         try: val = table[o][5]
40         except: pass
41         outfp.write("\t%s" % (val,))
42     outfp.write("\n")
43
44 def parse_sfsres(fp):
45     sys.stdout.write("# target_ops actual_ops latency_avg")
46     for o in OPERATIONS:
47         sys.stdout.write(" " + o)
48     sys.stdout.write("\n")
49     timestamp = None
50     run_data = []
51     for line in fp:
52         m = re.match(r"^([^*]+) \*{32,}$", line)
53         if m:
54             if len(run_data) > 0:
55                 parse_run(run_data, timestamp)
56             run_data = []
57             timestamp = m.group(1)
58         else:
59             run_data.append(line)
60     if len(run_data) > 0:
61         parse_run(run_data, timestamp)
62
63 if __name__ == '__main__':
64     parse_sfsres(sys.stdin)