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