Kevin Lubick | 2626104 | 2018-10-10 09:38:14 -0400 | [diff] [blame^] | 1 | # Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | |
| 6 | """Writes a Perf-formated json file with stats about Skia's size in flutter.""" |
| 7 | |
| 8 | |
| 9 | import json |
| 10 | import os |
| 11 | import subprocess |
| 12 | import sys |
| 13 | |
| 14 | |
| 15 | def main(): |
| 16 | input_file = sys.argv[1] |
| 17 | out_dir = sys.argv[2] |
| 18 | keystr = sys.argv[3] |
| 19 | propstr = sys.argv[4] |
| 20 | bloaty_path = sys.argv[5] |
| 21 | |
| 22 | results = { |
| 23 | 'key': { }, |
| 24 | 'results': { } |
| 25 | } |
| 26 | |
| 27 | props = propstr.split(' ') |
| 28 | for i in range(0, len(props), 2): |
| 29 | results[props[i]] = props[i+1] |
| 30 | |
| 31 | keys = keystr.split(' ') |
| 32 | for i in range(0, len(keys), 2): |
| 33 | results['key'][keys[i]] = keys[i+1] |
| 34 | |
| 35 | magic_seperator = '#$%^&*' |
| 36 | |
| 37 | # Human "readable" reports as an FYI. |
| 38 | print magic_seperator |
| 39 | print 'Report by file, then by symbol with ellided/combined templates' |
| 40 | lines = subprocess.check_output([bloaty_path, input_file, |
| 41 | '-d', 'compileunits,symbols', '-s', 'file', |
| 42 | '-n', '0', '--tsv', '--demangle=short']) |
| 43 | grand_total = print_skia_lines_file_symbol(lines) |
| 44 | print magic_seperator |
| 45 | print 'Report by file, then by symbol with full templates' |
| 46 | lines = subprocess.check_output([bloaty_path, input_file, |
| 47 | '-d', 'compileunits,symbols', '-s', 'file', |
| 48 | '-n', '0', '--tsv', '--demangle=full']) |
| 49 | print_skia_lines_file_symbol(lines) |
| 50 | print magic_seperator |
| 51 | |
| 52 | print 'Report by symbol, then by file with ellided/combined templates' |
| 53 | lines = subprocess.check_output([bloaty_path, input_file, |
| 54 | '-d', 'symbols,compileunits', '-s', 'file', |
| 55 | '-n', '0', '--tsv', '--demangle=short']) |
| 56 | print_skia_lines_symbol_file(lines) |
| 57 | print magic_seperator |
| 58 | |
| 59 | print 'Report by symbol, then by file with full templates' |
| 60 | lines = subprocess.check_output([bloaty_path, input_file, |
| 61 | '-d', 'symbols,compileunits', '-s', 'file', |
| 62 | '-n', '0', '--tsv', '--demangle=full']) |
| 63 | print_skia_lines_symbol_file(lines) |
| 64 | print magic_seperator |
| 65 | |
| 66 | r = { |
| 67 | # Use the default config as stats about the whole binary |
| 68 | 'skia_in_flutter' : { |
| 69 | 'total_size_bytes': grand_total |
| 70 | }, |
| 71 | } |
| 72 | |
| 73 | name = os.path.basename(input_file) |
| 74 | results['results'][name] = r |
| 75 | |
| 76 | # Make debugging easier |
| 77 | print json.dumps(results, indent=2) |
| 78 | |
| 79 | with open(os.path.join(out_dir, name+'.json'), 'w') as output: |
| 80 | output.write(json.dumps(results, indent=2)) |
| 81 | |
| 82 | |
| 83 | def bytes_or_kb(num): |
| 84 | if num < 1024: |
| 85 | return '%d bytes' % num |
| 86 | else: |
| 87 | return '%1.1f KiB' % (num / 1024.0) |
| 88 | |
| 89 | |
| 90 | def print_skia_lines_file_symbol(lines): |
| 91 | lines = lines.split('\n') |
| 92 | grand_total = 0 |
| 93 | sub_total = 0 |
| 94 | cur_file = '' |
| 95 | |
| 96 | for line in lines: |
| 97 | # Line looks like: |
| 98 | # ../../third_party/skia/src/file.cpp\tSkTSect<>::intersects()\t1224\t1348 |
| 99 | parts = line.split('\t') |
| 100 | if len(parts) != 4: |
| 101 | continue |
| 102 | this_file = parts[0] |
| 103 | if 'third_party/skia' not in this_file: |
| 104 | continue |
| 105 | symbol = parts[1] |
| 106 | if '.debug' in symbol: |
| 107 | continue |
| 108 | # vmsize = parts[2] Not needed |
| 109 | filesize = int(parts[3]) |
| 110 | |
| 111 | if this_file != cur_file: |
| 112 | if cur_file != '': |
| 113 | print '\t%-100s: %s' % ('Total File Size', bytes_or_kb(sub_total)) |
| 114 | sub_total = 0 |
| 115 | cur_file = this_file |
| 116 | print this_file.replace('../../third_party/skia', 'skia') |
| 117 | |
| 118 | print '\t%-100s: %s' % (symbol, bytes_or_kb(filesize)) |
| 119 | sub_total += filesize |
| 120 | grand_total += filesize |
| 121 | |
| 122 | print '\t%-100s: %s' % ('Total File Size', bytes_or_kb(sub_total)) |
| 123 | print '=======================================' |
| 124 | print 'Grand Total File Size: %s' % bytes_or_kb(grand_total) |
| 125 | return grand_total |
| 126 | |
| 127 | |
| 128 | def print_skia_lines_symbol_file(lines): |
| 129 | lines = lines.split('\n') |
| 130 | |
| 131 | for line in lines: |
| 132 | # Line looks like: |
| 133 | # SkTSect<>::intersects()\t../../third_party/skia/src/file.cpp\t1224\t1348 |
| 134 | parts = line.split('\t') |
| 135 | if len(parts) != 4: |
| 136 | continue |
| 137 | symbol = parts[0] |
| 138 | if 'section' in symbol: |
| 139 | continue |
| 140 | this_file = parts[1] |
| 141 | if 'third_party/skia' not in this_file: |
| 142 | continue |
| 143 | this_file = this_file.replace('../../third_party/skia', 'skia') |
| 144 | # vmsize = parts[2] Not needed |
| 145 | filesize = int(parts[3]) |
| 146 | |
| 147 | print '%-10s: %-80s in %s' % (bytes_or_kb(filesize), symbol, this_file) |
| 148 | |
| 149 | |
| 150 | if '__main__' == __name__: |
| 151 | main() |