benchmark silo added
[c11concurrency-benchmarks.git] / silo / benchmarks / results / make_graphs-4.py
1 #!/usr/bin/env python
2
3 import matplotlib
4 import pylab as plt
5 import numpy as np
6
7 import os
8 import sys
9 import math
10
11 def filter_name(results, name):
12   def match(ent):
13     return ent[0]['name'] == name
14   return [x for x in results if match(x)]
15
16 def order_results_by_threads(results):
17   # res is list[(config, results)], change to
18   # list[(num_threads, results)]
19   def trfm(ent):
20     return (ent[0]['threads'], ent[1])
21   return map(trfm, results)
22
23 def split_results_by_predicate(results, pred):
24   s0, s1 = [], []
25   for res in results:
26     if pred(res):
27       s0.append(res)
28     else:
29       s1.append(res)
30   return s0, s1
31
32 def extract_result_position(k, res):
33   if type(res) == list:
34     return [x[k] for x in res]
35   return res[k]
36
37 def extract_throughput(results, persist):
38   def trfm(ent):
39     return (ent[0], extract_result_position(0 if not persist else 1, ent[1]))
40   return map(trfm, results)
41
42 def extract_latency(results, persist):
43   def trfm(ent):
44     return (ent[0], extract_result_position(2 if not persist else 3, ent[1]))
45   return map(trfm, results)
46
47 def XX(x):
48   return [e[0] for e in x]
49
50 def median(x): return sorted(x)[len(x)/2]
51
52 def YY(x):
53   def checked(e):
54     if type(e) == list:
55       return median(e)
56     return e
57   return [checked(e[1]) for e in x]
58
59 def YYPC(x):
60   def checked(e):
61     if type(e) == list:
62       return median(e)
63     return e
64   return [checked(e[1])/float(e[0]) for e in x]
65
66 def YERR(x):
67   ypts = [e[1] for e in x]
68   ymins = np.array([min(x) for x in ypts])
69   ymaxs = np.array([max(x) for x in ypts])
70   ymid = np.array([median(x) for x in ypts])
71   yerr=np.array([ymid - ymins, ymaxs - ymid])
72   return yerr
73
74 def YERRPC(x):
75   ypts = [[ee/float(e[0]) for ee in e[1]] for e in x]
76   ymins = np.array([min(x) for x in ypts])
77   ymaxs = np.array([max(x) for x in ypts])
78   ymid = np.array([median(x) for x in ypts])
79   yerr=np.array([ymid - ymins, ymaxs - ymid])
80   return yerr
81
82 def handle_scale_tpcc(f, results):
83   # two graphs
84   # x-axis is num threads on both
85   # y-axis[0] is throughput
86   # y-axis[1] is latency
87
88   no_persist, with_persist = \
89       split_results_by_predicate(results, lambda x: not x[0]['persist'])
90   no_persist, with_persist = \
91       order_results_by_threads(no_persist), order_results_by_threads(with_persist)
92
93   no_persist_throughput, no_persist_latency = \
94       extract_throughput(no_persist, False), extract_latency(no_persist, False)
95   with_persist_throughput, with_persist_latency = \
96       extract_throughput(with_persist, True), extract_latency(with_persist, True)
97
98   fig = plt.figure()
99   ax = plt.subplot(111)
100   ax.errorbar(XX(no_persist_throughput), YY(no_persist_throughput), yerr=YERR(no_persist_throughput))
101   ax.errorbar(XX(with_persist_throughput), YY(with_persist_throughput), yerr=YERR(with_persist_throughput))
102   ax.legend(('No-Persist', 'Persist'), loc='upper left')
103   ax.set_xlabel('threads')
104   ax.set_ylabel('throughput (txns/sec)')
105   bname = '.'.join(os.path.basename(f).split('.')[:-1])
106   fig.savefig('.'.join([bname + '-scale_tpcc-throughput', 'pdf']))
107
108   fig = plt.figure()
109   ax = plt.subplot(111)
110   ax.errorbar(XX(no_persist_throughput), YYPC(no_persist_throughput), yerr=YERRPC(no_persist_throughput))
111   ax.errorbar(XX(with_persist_throughput), YYPC(with_persist_throughput), yerr=YERRPC(with_persist_throughput))
112   ax.legend(('No-Persist', 'Persist'), loc='upper left')
113   ax.set_xlabel('threads')
114   ax.set_ylabel('throughput (txns/sec/core)')
115   ax.set_ylim([20000, 32000])
116   bname = '.'.join(os.path.basename(f).split('.')[:-1])
117   fig.savefig('.'.join([bname + '-scale_tpcc-per-core-throughput', 'pdf']))
118
119   fig = plt.figure()
120   ax = plt.subplot(111)
121   ax.errorbar(XX(no_persist_latency), YY(no_persist_latency), yerr=YERR(no_persist_latency))
122   ax.errorbar(XX(with_persist_latency), YY(with_persist_latency), yerr=YERR(with_persist_latency))
123   ax.legend(('No-Persist', 'Persist'), loc='upper left')
124   ax.set_xlabel('threads')
125   ax.set_ylabel('latency (ms/txn)')
126   bname = '.'.join(os.path.basename(f).split('.')[:-1])
127   fig.savefig('.'.join([bname + '-scale_tpcc-latency', 'pdf']))
128
129 if __name__ == '__main__':
130   files = sys.argv[1:]
131   for f in files:
132     execfile(f)
133
134     # scale_tpcc
135     scale_tpcc = filter_name(RESULTS, 'scale_tpcc')
136     if scale_tpcc:
137       handle_scale_tpcc(f, scale_tpcc)