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 | }, |
| 57 | 'BM_ErrorStringOnNewError': { |
| 58 | 'tpl': ['fixture'], |
| 59 | 'dyn': [], |
| 60 | }, |
| 61 | 'BM_ErrorStringRepeatedly': { |
| 62 | 'tpl': ['fixture'], |
| 63 | 'dyn': [], |
| 64 | }, |
| 65 | 'BM_ErrorGetStatus': { |
| 66 | 'tpl': ['fixture'], |
| 67 | 'dyn': [], |
| 68 | }, |
| 69 | 'BM_ErrorGetStatusCode': { |
| 70 | 'tpl': ['fixture'], |
| 71 | 'dyn': [], |
| 72 | }, |
| 73 | 'BM_ErrorHttpError': { |
| 74 | 'tpl': ['fixture'], |
| 75 | 'dyn': [], |
| 76 | }, |
| 77 | 'BM_HasClearGrpcStatus': { |
| 78 | 'tpl': ['fixture'], |
| 79 | 'dyn': [], |
| 80 | }, |
| 81 | 'BM_IsolatedFilter' : { |
| 82 | 'tpl': ['fixture', 'client_mutator'], |
| 83 | 'dyn': [], |
| 84 | }, |
| 85 | 'BM_HpackEncoderEncodeHeader' : { |
| 86 | 'tpl': ['fixture'], |
| 87 | 'dyn': ['end_of_stream', 'request_size'], |
| 88 | }, |
| 89 | 'BM_HpackParserParseHeader' : { |
| 90 | 'tpl': ['fixture'], |
| 91 | 'dyn': [], |
| 92 | }, |
Craig Tiller | 77bcd5a | 2017-03-06 16:15:10 -0800 | [diff] [blame^] | 93 | 'BM_CallCreateDestroy' : { |
| 94 | 'tpl': ['fixture'], |
| 95 | 'dyn': [], |
| 96 | }, |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | def numericalize(s): |
| 100 | if not s: return '' |
| 101 | if s[-1] == 'k': |
| 102 | return int(s[:-1]) * 1024 |
| 103 | if s[-1] == 'M': |
| 104 | return int(s[:-1]) * 1024 * 1024 |
| 105 | if 0 <= (ord(s[-1]) - ord('0')) <= 9: |
| 106 | return int(s) |
| 107 | assert 'not a number: %s' % s |
| 108 | |
| 109 | def parse_name(name): |
| 110 | cpp_name = name |
| 111 | if '<' not in name and '/' not in name and name not in _BM_SPECS: |
| 112 | return {'name': name, 'cpp_name': name} |
| 113 | rest = name |
| 114 | out = {} |
| 115 | tpl_args = [] |
| 116 | dyn_args = [] |
| 117 | if '<' in rest: |
| 118 | tpl_bit = rest[rest.find('<') + 1 : rest.rfind('>')] |
| 119 | arg = '' |
| 120 | nesting = 0 |
| 121 | for c in tpl_bit: |
| 122 | if c == '<': |
| 123 | nesting += 1 |
| 124 | arg += c |
| 125 | elif c == '>': |
| 126 | nesting -= 1 |
| 127 | arg += c |
| 128 | elif c == ',': |
| 129 | if nesting == 0: |
| 130 | tpl_args.append(arg.strip()) |
| 131 | arg = '' |
| 132 | else: |
| 133 | arg += c |
| 134 | else: |
| 135 | arg += c |
| 136 | tpl_args.append(arg.strip()) |
| 137 | rest = rest[:rest.find('<')] + rest[rest.rfind('>') + 1:] |
| 138 | if '/' in rest: |
| 139 | s = rest.split('/') |
| 140 | rest = s[0] |
| 141 | dyn_args = s[1:] |
| 142 | name = rest |
| 143 | assert name in _BM_SPECS, '_BM_SPECS needs to be expanded for %s' % name |
| 144 | assert len(dyn_args) == len(_BM_SPECS[name]['dyn']) |
| 145 | assert len(tpl_args) == len(_BM_SPECS[name]['tpl']) |
| 146 | out['name'] = name |
| 147 | out['cpp_name'] = cpp_name |
| 148 | out.update(dict((k, numericalize(v)) for k, v in zip(_BM_SPECS[name]['dyn'], dyn_args))) |
| 149 | out.update(dict(zip(_BM_SPECS[name]['tpl'], tpl_args))) |
| 150 | return out |
| 151 | |
Craig Tiller | adade61 | 2017-03-06 16:13:04 -0800 | [diff] [blame] | 152 | def expand_json(js, js2 = None): |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 153 | for bm in js['benchmarks']: |
| 154 | context = js['context'] |
| 155 | if 'label' in bm: |
| 156 | labels_list = [s.split(':') for s in bm['label'].strip().split(' ') if len(s) and s[0] != '#'] |
| 157 | for el in labels_list: |
| 158 | el[0] = el[0].replace('/iter', '_per_iteration') |
| 159 | labels = dict(labels_list) |
| 160 | else: |
| 161 | labels = {} |
| 162 | row = { |
| 163 | 'jenkins_build': os.environ.get('BUILD_NUMBER', ''), |
| 164 | 'jenkins_job': os.environ.get('JOB_NAME', ''), |
| 165 | } |
| 166 | row.update(context) |
| 167 | row.update(bm) |
| 168 | row.update(parse_name(row['name'])) |
| 169 | row.update(labels) |
Craig Tiller | adade61 | 2017-03-06 16:13:04 -0800 | [diff] [blame] | 170 | if js2: |
| 171 | for bm2 in js2['benchmarks']: |
| 172 | if bm['name'] == bm2['name']: |
| 173 | row['cpu_time'] = bm2['cpu_time'] |
| 174 | row['real_time'] = bm2['real_time'] |
| 175 | row['iterations'] = bm2['iterations'] |
Craig Tiller | b699640 | 2017-03-06 16:10:20 -0800 | [diff] [blame] | 176 | yield row |