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 total_size_bytes_key = sys.argv[5] 22 magic_seperator = sys.argv[6] 23 24 results = { 25 'key': { }, 26 'results': { } 27 } 28 29 props = propstr.split(' ') 30 for i in range(0, len(props), 2): 31 results[props[i]] = props[i+1] 32 33 keys = keystr.split(' ') 34 for i in range(0, len(keys), 2): 35 results['key'][keys[i]] = keys[i+1] 36 37 r = { 38 total_size_bytes_key: os.path.getsize(input_file) 39 } 40 41 # Make a copy to avoid destroying the hardlinked file. 42 # Swarming hardlinks in the builds from isolated cache. 43 temp_file = input_file + '_tmp' 44 subprocess.check_call(['cp', input_file, temp_file]) 45 subprocess.check_call(['gzip', temp_file]) 46 47 r['gzip_size_bytes'] = os.path.getsize(temp_file + '.gz') 48 49 name = os.path.basename(input_file) 50 51 print(magic_seperator) 52 results['results'][name] = { 53 # We need this top level layer 'config'/slice 54 # Other analysis methods (e.g. libskia) might have 55 # slices for data on the 'code' section, etc. 56 'default' : r, 57 } 58 59 # Make debugging easier 60 print(json.dumps(results, indent=2)) 61 62 with open(os.path.join(out_dir, name+'.json'), 'w') as output: 63 output.write(json.dumps(results, indent=2)) 64 65 66if __name__ == '__main__': 67 main() 68