blob: f4d628e11f04bb5052efac8573211d89ff319c7e [file] [log] [blame]
Craig Tillerb6996402017-03-06 16:10:20 -08001# Copyright 2017, Google Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
8# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above
11# copyright notice, this list of conditions and the following disclaimer
12# in the documentation and/or other materials provided with the
13# distribution.
14# * Neither the name of Google Inc. nor the names of its
15# contributors may be used to endorse or promote products derived from
16# this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30import os
31
32_BM_SPECS = {
33 'BM_UnaryPingPong': {
34 'tpl': ['fixture', 'client_mutator', 'server_mutator'],
35 'dyn': ['request_size', 'response_size'],
36 },
37 'BM_PumpStreamClientToServer': {
38 'tpl': ['fixture'],
39 'dyn': ['request_size'],
40 },
41 'BM_PumpStreamServerToClient': {
42 'tpl': ['fixture'],
43 'dyn': ['request_size'],
44 },
45 'BM_StreamingPingPong': {
46 'tpl': ['fixture', 'client_mutator', 'server_mutator'],
47 'dyn': ['request_size', 'request_count'],
48 },
49 'BM_StreamingPingPongMsgs': {
50 'tpl': ['fixture', 'client_mutator', 'server_mutator'],
51 'dyn': ['request_size'],
52 },
53 'BM_PumpStreamServerToClient_Trickle': {
54 'tpl': [],
55 'dyn': ['request_size', 'bandwidth_kilobits'],
56 },
ncteisendf319602017-05-17 16:48:26 -070057 'BM_PumpUnbalancedUnary_Trickle': {
58 'tpl': [],
59 'dyn': ['request_size', 'bandwidth_kilobits'],
60 },
Craig Tillerb6996402017-03-06 16:10:20 -080061 'BM_ErrorStringOnNewError': {
62 'tpl': ['fixture'],
63 'dyn': [],
64 },
65 'BM_ErrorStringRepeatedly': {
66 'tpl': ['fixture'],
67 'dyn': [],
68 },
69 'BM_ErrorGetStatus': {
70 'tpl': ['fixture'],
71 'dyn': [],
72 },
73 'BM_ErrorGetStatusCode': {
74 'tpl': ['fixture'],
75 'dyn': [],
76 },
77 'BM_ErrorHttpError': {
78 'tpl': ['fixture'],
79 'dyn': [],
80 },
81 'BM_HasClearGrpcStatus': {
82 'tpl': ['fixture'],
83 'dyn': [],
84 },
Craig Tillere736b702017-03-10 09:52:25 -080085 'BM_IsolatedFilter': {
Craig Tillerb6996402017-03-06 16:10:20 -080086 'tpl': ['fixture', 'client_mutator'],
87 'dyn': [],
88 },
Craig Tillere736b702017-03-10 09:52:25 -080089 'BM_HpackEncoderEncodeHeader': {
Craig Tillerb6996402017-03-06 16:10:20 -080090 'tpl': ['fixture'],
91 'dyn': ['end_of_stream', 'request_size'],
92 },
Craig Tillere736b702017-03-10 09:52:25 -080093 'BM_HpackParserParseHeader': {
Craig Tillerb6996402017-03-06 16:10:20 -080094 'tpl': ['fixture'],
95 'dyn': [],
96 },
Craig Tillere736b702017-03-10 09:52:25 -080097 'BM_CallCreateDestroy': {
Craig Tiller77bcd5a2017-03-06 16:15:10 -080098 'tpl': ['fixture'],
99 'dyn': [],
100 },
Craig Tillere736b702017-03-10 09:52:25 -0800101 'BM_Zalloc': {
102 'tpl': [],
103 'dyn': ['request_size'],
104 },
Craig Tiller6a4c1a32017-03-10 14:18:00 -0800105 'BM_PollEmptyPollset_SpeedOfLight': {
106 'tpl': [],
107 'dyn': ['request_size', 'request_count'],
Craig Tiller9fb31312017-03-22 09:09:16 -0700108 },
109 'BM_StreamCreateSendInitialMetadataDestroy': {
110 'tpl': ['fixture'],
111 'dyn': [],
112 },
113 'BM_TransportStreamSend': {
114 'tpl': [],
115 'dyn': ['request_size'],
116 },
117 'BM_TransportStreamRecv': {
118 'tpl': [],
119 'dyn': ['request_size'],
Craig Tiller123724f2017-03-29 16:16:59 -0700120 },
121 'BM_StreamingPingPongWithCoalescingApi': {
122 'tpl': ['fixture', 'client_mutator', 'server_mutator'],
123 'dyn': ['request_size', 'request_count', 'end_of_stream'],
Craig Tillerb8839992017-03-30 10:54:14 -0700124 },
125 'BM_Base16SomeStuff': {
126 'tpl': [],
127 'dyn': ['request_size'],
Craig Tiller6a4c1a32017-03-10 14:18:00 -0800128 }
Craig Tillerb6996402017-03-06 16:10:20 -0800129}
130
131def numericalize(s):
132 if not s: return ''
133 if s[-1] == 'k':
Craig Tiller34887802017-03-10 13:39:01 -0800134 return float(s[:-1]) * 1024
Craig Tillerb6996402017-03-06 16:10:20 -0800135 if s[-1] == 'M':
Craig Tiller34887802017-03-10 13:39:01 -0800136 return float(s[:-1]) * 1024 * 1024
Craig Tillerb6996402017-03-06 16:10:20 -0800137 if 0 <= (ord(s[-1]) - ord('0')) <= 9:
Craig Tiller34887802017-03-10 13:39:01 -0800138 return float(s)
Craig Tillerb6996402017-03-06 16:10:20 -0800139 assert 'not a number: %s' % s
140
141def parse_name(name):
142 cpp_name = name
143 if '<' not in name and '/' not in name and name not in _BM_SPECS:
144 return {'name': name, 'cpp_name': name}
145 rest = name
146 out = {}
147 tpl_args = []
148 dyn_args = []
149 if '<' in rest:
150 tpl_bit = rest[rest.find('<') + 1 : rest.rfind('>')]
151 arg = ''
152 nesting = 0
153 for c in tpl_bit:
154 if c == '<':
155 nesting += 1
156 arg += c
157 elif c == '>':
158 nesting -= 1
159 arg += c
160 elif c == ',':
161 if nesting == 0:
162 tpl_args.append(arg.strip())
163 arg = ''
164 else:
165 arg += c
166 else:
167 arg += c
168 tpl_args.append(arg.strip())
169 rest = rest[:rest.find('<')] + rest[rest.rfind('>') + 1:]
170 if '/' in rest:
171 s = rest.split('/')
172 rest = s[0]
173 dyn_args = s[1:]
174 name = rest
175 assert name in _BM_SPECS, '_BM_SPECS needs to be expanded for %s' % name
176 assert len(dyn_args) == len(_BM_SPECS[name]['dyn'])
177 assert len(tpl_args) == len(_BM_SPECS[name]['tpl'])
178 out['name'] = name
179 out['cpp_name'] = cpp_name
180 out.update(dict((k, numericalize(v)) for k, v in zip(_BM_SPECS[name]['dyn'], dyn_args)))
181 out.update(dict(zip(_BM_SPECS[name]['tpl'], tpl_args)))
182 return out
183
Craig Tilleradade612017-03-06 16:13:04 -0800184def expand_json(js, js2 = None):
Craig Tillerb6996402017-03-06 16:10:20 -0800185 for bm in js['benchmarks']:
Craig Tiller9a212df2017-03-30 13:19:45 -0700186 if bm['name'].endswith('_stddev') or bm['name'].endswith('_mean'): continue
Craig Tillerb6996402017-03-06 16:10:20 -0800187 context = js['context']
188 if 'label' in bm:
189 labels_list = [s.split(':') for s in bm['label'].strip().split(' ') if len(s) and s[0] != '#']
190 for el in labels_list:
191 el[0] = el[0].replace('/iter', '_per_iteration')
192 labels = dict(labels_list)
193 else:
194 labels = {}
195 row = {
196 'jenkins_build': os.environ.get('BUILD_NUMBER', ''),
197 'jenkins_job': os.environ.get('JOB_NAME', ''),
198 }
199 row.update(context)
200 row.update(bm)
201 row.update(parse_name(row['name']))
202 row.update(labels)
Craig Tilleradade612017-03-06 16:13:04 -0800203 if js2:
204 for bm2 in js2['benchmarks']:
Craig Tillerc78c9152017-03-30 13:29:02 -0700205 if bm['name'] == bm2['name'] and 'already_used' not in bm2:
Craig Tilleradade612017-03-06 16:13:04 -0800206 row['cpu_time'] = bm2['cpu_time']
207 row['real_time'] = bm2['real_time']
208 row['iterations'] = bm2['iterations']
Craig Tillerc78c9152017-03-30 13:29:02 -0700209 bm2['already_used'] = True
Craig Tillerdc3806c2017-04-12 09:08:31 -0700210 break
Craig Tillerb6996402017-03-06 16:10:20 -0800211 yield row