remove version in all files
[dpdk.git] / app / test / graph_ring.py
1 #!/usr/bin/env python
2
3 #   BSD LICENSE
4
5 #   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
6 #   All rights reserved.
7
8 #   Redistribution and use in source and binary forms, with or without 
9 #   modification, are permitted provided that the following conditions 
10 #   are met:
11
12 #     * Redistributions of source code must retain the above copyright 
13 #       notice, this list of conditions and the following disclaimer.
14 #     * Redistributions in binary form must reproduce the above copyright 
15 #       notice, this list of conditions and the following disclaimer in 
16 #       the documentation and/or other materials provided with the 
17 #       distribution.
18 #     * Neither the name of Intel Corporation nor the names of its 
19 #       contributors may be used to endorse or promote products derived 
20 #       from this software without specific prior written permission.
21
22 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
25 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
29 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
30 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34
35 import sys, re
36 import numpy as np
37 import matplotlib
38 matplotlib.use('Agg') # we don't want to use X11
39 import matplotlib.pyplot as plt
40 from matplotlib.ticker import FuncFormatter
41
42 INT = "([-+]?[0-9][0-9]*)"
43
44 class RingTest:
45     l = []
46
47     def __init__(self):
48         pass
49
50     # sort a test case list
51     def sort(self, x, y):
52         for t in [ "enq_core", "deq_core", "enq_bulk", "deq_bulk", "rate" ]:
53             if x[t] > y[t]:
54                 return 1
55             if x[t] < y[t]:
56                 return -1
57         return 0
58
59     # add a test case
60     def add(self, **args):
61         self.l.append(args)
62
63     # get an ordered list matching parameters
64     # ex: r.get(enq_core=1, deq_core=1)
65     def get(self, **args):
66         retlist = []
67         for t in self.l:
68             add_it = 1
69             for a in args:
70                 if args[a] != t[a]:
71                     add_it = 0
72                     break
73             if add_it:
74                 retlist.append(t)
75         retlist.sort(cmp=self.sort)
76         return retlist
77
78     # return an ordered list of all values for this param or param list
79     # ex: r.get_value_list("enq_core")
80     def get_value_list(self, param):
81         retlist = []
82         if type(param) is not list:
83             param = [param]
84         for t in self.l:
85             entry = []
86             for p in param:
87                 entry.append(t[p])
88             if len(entry) == 1:
89                 entry = entry[0]
90             else:
91                 entry = tuple(entry)
92             if not entry in retlist:
93                 retlist.append(entry)
94         retlist.sort()
95         return retlist
96
97 # read the file and return a RingTest object containing all data
98 def read_data_from_file(filename):
99
100     ring_test = RingTest()
101
102     # parse the file: it produces a list of dict containing the data for
103     # each test case (each dict in the list corresponds to a line)
104     f = open(filename)
105     while True:
106         l = f.readline()
107
108         if l == "":
109             break
110
111         regexp  = "ring_autotest "
112         regexp += "e/d_core=%s,%s e/d_bulk=%s,%s "%(INT, INT, INT, INT)
113         regexp += "sp=%s sc=%s "%(INT, INT)
114         regexp += "rate_persec=%s"%(INT)
115         m = re.match(regexp, l)
116         if m == None:
117             continue
118
119         ring_test.add(enq_core = int(m.groups()[0]),
120                       deq_core = int(m.groups()[1]),
121                       enq_bulk = int(m.groups()[2]),
122                       deq_bulk = int(m.groups()[3]),
123                       sp = int(m.groups()[4]),
124                       sc = int(m.groups()[5]),
125                       rate = int(m.groups()[6]))
126
127     f.close()
128     return ring_test
129
130 def millions(x, pos):
131     return '%1.1fM' % (x*1e-6)
132
133 # graph one, with specific parameters -> generate a .svg file
134 def graph_one(str, ring_test, enq_core, deq_core, sp, sc):
135     filename = "ring_%d_%d"%(enq_core, deq_core)
136     if sp:
137         sp_str = "sp"
138     else:
139         sp_str = "mp"
140     if sc:
141         sc_str = "sc"
142     else:
143         sc_str = "mc"
144     filename += "_%s_%s.svg"%(sp_str, sc_str)
145
146
147     enq_bulk_list = ring_test.get_value_list("enq_bulk")
148     N_enq_bulk = len(enq_bulk_list)
149     enq_names = map(lambda x:"enq=%d"%x, enq_bulk_list)
150
151     deq_bulk_list = ring_test.get_value_list("deq_bulk")
152     N_deq_bulk = len(deq_bulk_list)
153     deq_names = map(lambda x:"deq=%d"%x, deq_bulk_list)
154
155     N = N_enq_bulk * (N_deq_bulk + 1)
156     rates = []
157
158     colors = []
159     for enq_bulk in ring_test.get_value_list("enq_bulk"):
160         col = 0.
161         for deq_bulk in ring_test.get_value_list("deq_bulk"):
162             col += 0.9 / len(ring_test.get_value_list("deq_bulk"))
163             r = ring_test.get(enq_core=enq_core, deq_core=deq_core,
164                               enq_bulk=enq_bulk, deq_bulk=deq_bulk,
165                               sp=sp, sc=sc)
166             r = r[0]["rate"]
167             rates.append(r)
168             colors.append((1. - col, 0.2, col, 1.)) # rgba
169
170         rates.append(0)
171         colors.append((0.,0.,0.,0.))
172
173     ind = np.arange(N)  # the x locations for the groups
174     width = 1           # the width of the bars: can also be len(x) sequence
175
176
177     formatter = FuncFormatter(millions)
178     fig = plt.figure()
179     p = plt.bar(ind, tuple(rates), width, color=tuple(colors))
180     fig.axes[0].yaxis.set_major_formatter(formatter)
181
182     plt.ylabel('Obj/sec')
183     #plt.ylim(0, 400000000.)
184     plt.title("Ring autotest \"%s\"\nenq core(s)=%d, deq core(s)=%d, %s, %s"\
185                   %(str, enq_core, deq_core, sp_str, sc_str))
186     ind_names = np.arange(N_enq_bulk) * (N_deq_bulk+1) + (N_deq_bulk+1) / 2
187     plt.xticks(ind_names, tuple(enq_names))
188     plt.legend(tuple([p[i] for i in range(N_deq_bulk)]), tuple(deq_names),
189                loc="upper left")
190     plt.savefig(filename)
191
192 if len(sys.argv) != 3:
193     print "usage: graph_ring.py file title"
194     sys.exit(1)
195
196 ring_test = read_data_from_file(sys.argv[1])
197
198 for enq_core, deq_core, sp, sc in \
199         ring_test.get_value_list(["enq_core", "deq_core", "sp", "sc"]):
200     graph_one(sys.argv[2], ring_test, enq_core, deq_core, sp, sc)