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 the given web file.""" 7 8 9from __future__ import print_function 10import json 11import os 12import subprocess 13import sys 14 15 16def main(): 17 input_file = sys.argv[1] 18 out_dir = sys.argv[2] 19 keystr = sys.argv[3] 20 propstr = sys.argv[4] 21 bloaty_path = sys.argv[5] 22 total_size_bytes_key = sys.argv[6] 23 magic_seperator = sys.argv[7] 24 25 results = { 26 'key': { }, 27 'results': { } 28 } 29 30 print(magic_seperator) 31 print('If you see lots of func[19] and such, go check out the debug build') 32 print('Note that template instantiations are grouped together, ' 33 'thus the elided types.') 34 print('If you notice an unsymbolized "duplicate" entry, it is simply how ' 35 'many bytes the function name itself takes up') 36 print(subprocess.check_output([bloaty_path, input_file, 37 '-d', 'shortsymbols', '-n', '0'])) 38 39 print(magic_seperator) 40 print('If you see lots of func[19] and such, go check out the debug build') 41 print(subprocess.check_output([bloaty_path, input_file, 42 '-d', 'fullsymbols', '-n', '0'])) 43 44 props = propstr.split(' ') 45 for i in range(0, len(props), 2): 46 results[props[i]] = props[i+1] 47 48 keys = keystr.split(' ') 49 for i in range(0, len(keys), 2): 50 results['key'][keys[i]] = keys[i+1] 51 52 r = { 53 total_size_bytes_key: os.path.getsize(input_file) 54 } 55 56 # Make a copy to avoid destroying the hardlinked file. 57 # Swarming hardlinks in the builds from isolated cache. 58 temp_file = input_file + '_tmp' 59 subprocess.check_call(['cp', input_file, temp_file]) 60 subprocess.check_call(['gzip', temp_file]) 61 62 r['gzip_size_bytes'] = os.path.getsize(temp_file + '.gz') 63 64 name = os.path.basename(input_file) 65 66 results['results'][name] = { 67 # We need this top level layer 'config'/slice 68 # Other analysis methods (e.g. libskia) might have 69 # slices for data on the 'code' section, etc. 70 'default' : r, 71 } 72 73 print(magic_seperator) 74 print(json.dumps(results, indent=2)) 75 76 with open(os.path.join(out_dir, name+'.json'), 'w') as output: 77 output.write(json.dumps(results, indent=2)) 78 79 80if __name__ == '__main__': 81 main() 82