Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 1 | # 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 | |
| 30 | import 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 | }, |
ncteisen | df31960 | 2017-05-17 16:48:26 -0700 | [diff] [blame] | 57 | 'BM_PumpUnbalancedUnary_Trickle': { |
| 58 | 'tpl': [], |
| 59 | 'dyn': ['request_size', 'bandwidth_kilobits'], |
| 60 | }, |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 61 | '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 Tiller | e736b70 | 2017-03-10 09:52:25 -0800 | [diff] [blame] | 85 | 'BM_IsolatedFilter': { |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 86 | 'tpl': ['fixture', 'client_mutator'], |
| 87 | 'dyn': [], |
| 88 | }, |
Craig Tiller | e736b70 | 2017-03-10 09:52:25 -0800 | [diff] [blame] | 89 | 'BM_HpackEncoderEncodeHeader': { |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 90 | 'tpl': ['fixture'], |
| 91 | 'dyn': ['end_of_stream', 'request_size'], |
| 92 | }, |
Craig Tiller | e736b70 | 2017-03-10 09:52:25 -0800 | [diff] [blame] | 93 | 'BM_HpackParserParseHeader': { |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 94 | 'tpl': ['fixture'], |
| 95 | 'dyn': [], |
| 96 | }, |
Craig Tiller | e736b70 | 2017-03-10 09:52:25 -0800 | [diff] [blame] | 97 | 'BM_CallCreateDestroy': { |
Craig Tiller | 77bcd5a | 2017-03-06 16:15:10 -0800 | [diff] [blame] | 98 | 'tpl': ['fixture'], |
| 99 | 'dyn': [], |
| 100 | }, |
Craig Tiller | e736b70 | 2017-03-10 09:52:25 -0800 | [diff] [blame] | 101 | 'BM_Zalloc': { |
| 102 | 'tpl': [], |
| 103 | 'dyn': ['request_size'], |
| 104 | }, |
Craig Tiller | 6a4c1a3 | 2017-03-10 14:18:00 -0800 | [diff] [blame] | 105 | 'BM_PollEmptyPollset_SpeedOfLight': { |
| 106 | 'tpl': [], |
| 107 | 'dyn': ['request_size', 'request_count'], |
Craig Tiller | 9fb3131 | 2017-03-22 09:09:16 -0700 | [diff] [blame] | 108 | }, |
| 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 Tiller | 123724f | 2017-03-29 16:16:59 -0700 | [diff] [blame] | 120 | }, |
| 121 | 'BM_StreamingPingPongWithCoalescingApi': { |
| 122 | 'tpl': ['fixture', 'client_mutator', 'server_mutator'], |
| 123 | 'dyn': ['request_size', 'request_count', 'end_of_stream'], |
Craig Tiller | b883999 | 2017-03-30 10:54:14 -0700 | [diff] [blame] | 124 | }, |
| 125 | 'BM_Base16SomeStuff': { |
| 126 | 'tpl': [], |
| 127 | 'dyn': ['request_size'], |
Craig Tiller | 6a4c1a3 | 2017-03-10 14:18:00 -0800 | [diff] [blame] | 128 | } |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | def numericalize(s): |
| 132 | if not s: return '' |
| 133 | if s[-1] == 'k': |
Craig Tiller | 3488780 | 2017-03-10 13:39:01 -0800 | [diff] [blame] | 134 | return float(s[:-1]) * 1024 |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 135 | if s[-1] == 'M': |
Craig Tiller | 3488780 | 2017-03-10 13:39:01 -0800 | [diff] [blame] | 136 | return float(s[:-1]) * 1024 * 1024 |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 137 | if 0 <= (ord(s[-1]) - ord('0')) <= 9: |
Craig Tiller | 3488780 | 2017-03-10 13:39:01 -0800 | [diff] [blame] | 138 | return float(s) |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 139 | assert 'not a number: %s' % s |
| 140 | |
| 141 | def 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 Tiller | adade61 | 2017-03-06 16:13:04 -0800 | [diff] [blame] | 184 | def expand_json(js, js2 = None): |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 185 | for bm in js['benchmarks']: |
Craig Tiller | 9a212df | 2017-03-30 13:19:45 -0700 | [diff] [blame] | 186 | if bm['name'].endswith('_stddev') or bm['name'].endswith('_mean'): continue |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 187 | 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 Tiller | adade61 | 2017-03-06 16:13:04 -0800 | [diff] [blame] | 203 | if js2: |
| 204 | for bm2 in js2['benchmarks']: |
Craig Tiller | c78c915 | 2017-03-30 13:29:02 -0700 | [diff] [blame] | 205 | if bm['name'] == bm2['name'] and 'already_used' not in bm2: |
Craig Tiller | adade61 | 2017-03-06 16:13:04 -0800 | [diff] [blame] | 206 | row['cpu_time'] = bm2['cpu_time'] |
| 207 | row['real_time'] = bm2['real_time'] |
| 208 | row['iterations'] = bm2['iterations'] |
Craig Tiller | c78c915 | 2017-03-30 13:29:02 -0700 | [diff] [blame] | 209 | bm2['already_used'] = True |
Craig Tiller | dc3806c | 2017-04-12 09:08:31 -0700 | [diff] [blame] | 210 | break |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 211 | yield row |