blob: e856c988e370d5f71a2239c756bd222d69c416fe [file] [log] [blame]
Kevin Lubick49688432018-10-08 13:58:47 -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
21 results = {
Kevin Lubick915b80b2018-10-09 09:22:23 -040022 'key': { },
Kevin Lubick49688432018-10-08 13:58:47 -040023 'results': { }
24 }
25
26 props = propstr.split(' ')
27 for i in range(0, len(props), 2):
28 results[props[i]] = props[i+1]
29
30 keys = keystr.split(' ')
31 for i in range(0, len(keys), 2):
Kevin Lubick915b80b2018-10-09 09:22:23 -040032 results['key'][keys[i]] = keys[i+1]
Kevin Lubick49688432018-10-08 13:58:47 -040033
34 r = {
35 'total_size_bytes': os.path.getsize(input_file)
36 }
37
38 # Make a copy to avoid destroying the hardlinked file.
39 # Swarming hardlinks in the builds from isolated cache.
40 temp_file = input_file + '_tmp'
41 subprocess.check_call(['cp', input_file, temp_file])
42 subprocess.check_call(['gzip', temp_file])
43
44 r['gzip_size_bytes'] = os.path.getsize(temp_file + '.gz')
45
46 name = os.path.basename(input_file)
47
48 results['results'][name] = {
49 # We need this top level layer 'config'/slice
50 # Other analysis methods (e.g. libskia) might have
51 # slices for data on the 'code' section, etc.
52 'default' : r,
53 }
54
55 # Make debugging easier
56 print json.dumps(results, indent=2)
57
58 with open(os.path.join(out_dir, name+'.json'), 'w') as output:
59 output.write(json.dumps(results, indent=2))
60
61
Kevin Lubick402bf742019-02-12 08:28:12 -050062if __name__ == '__main__':
Kevin Lubick49688432018-10-08 13:58:47 -040063 main()