Extract wall clock timestamp of each run when parsing sfsres files
[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, subprocess, 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_date(datestr):
19     p = subprocess.Popen(['/bin/date', '-d', datestr, '+%s'],
20                          stdout=subprocess.PIPE)
21     d = p.stdout.read()
22     p.wait()
23     return int(d.strip())
24
25 def parse_run(lines, timestamp, outfp=sys.stdout):
26     #print timestamp
27     requested_load = extract_re(lines, r"\s*Requested Load.*= (\d+)")
28     load = int(requested_load.group(1))
29     results = extract_re(lines, r"SFS NFS THROUGHPUT:\s*([\d.]+).*RESPONSE TIME:\s*([\d.]+) Msec/Op")
30     timestamp = extract_re(lines, r"SFS Aggregate Results.*, (.*)")
31     if timestamp is not None:
32         try:
33             timestamp = parse_date(timestamp.group(1))
34         except:
35             timestamp = None
36
37     # Extract the stable of per-operation counts, response times, etc.
38     regexp = re.compile(r"^(\w+)" + r"\s*([\d.]+)%?" * 9)
39     table = {}
40     for l in lines:
41         m = regexp.match(l)
42         if m:
43             try:
44                 table[m.group(1)] = [float(m.group(i)) for i in range(2, 11)]
45             except:
46                 #sys.stderr.write("Error parsing line: " + l.strip() + "\n")
47                 pass
48
49     outfp.write("# finish_timestamp: " + str(timestamp) + "\n")
50     outfp.write("%d\t%s\t%s" % (load, results.group(1), results.group(2)))
51     for o in OPERATIONS:
52         val = '-'
53         try: val = table[o][5]
54         except: pass
55         outfp.write("\t%s" % (val,))
56     outfp.write("\n")
57
58 def parse_sfsres(fp):
59     sys.stdout.write("# target_ops actual_ops latency_avg")
60     for o in OPERATIONS:
61         sys.stdout.write(" " + o)
62     sys.stdout.write("\n")
63     timestamp = None
64     run_data = []
65     for line in fp:
66         m = re.match(r"^([^*]+) \*{32,}$", line)
67         if m:
68             if len(run_data) > 0:
69                 parse_run(run_data, timestamp)
70             run_data = []
71             timestamp = m.group(1)
72         else:
73             run_data.append(line)
74     if len(run_data) > 0:
75         parse_run(run_data, timestamp)
76
77 if __name__ == '__main__':
78     parse_sfsres(sys.stdin)