| OLD | NEW |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 5 | 4 |
| 6 """Creates an html report that allows you to view binary size by component.""" | 5 """Creates an html report that allows you to view binary size by component.""" |
| 7 | 6 |
| 8 import argparse | 7 import argparse |
| 9 import json | 8 import json |
| 10 import logging | 9 import logging |
| 11 import os | 10 import os |
| 12 import shutil | 11 import shutil |
| 13 import sys | 12 import sys |
| 14 | 13 |
| 14 import archive |
| 15 import helpers | 15 import helpers |
| 16 import map2size | |
| 17 | 16 |
| 18 | 17 |
| 19 # Node dictionary keys. These are output in json read by the webapp so | 18 # Node dictionary keys. These are output in json read by the webapp so |
| 20 # keep them short to save file size. | 19 # keep them short to save file size. |
| 21 # Note: If these change, the webapp must also change. | 20 # Note: If these change, the webapp must also change. |
| 22 _NODE_TYPE_KEY = 'k' | 21 _NODE_TYPE_KEY = 'k' |
| 23 _NODE_TYPE_BUCKET = 'b' | 22 _NODE_TYPE_BUCKET = 'b' |
| 24 _NODE_TYPE_PATH = 'p' | 23 _NODE_TYPE_PATH = 'p' |
| 25 _NODE_TYPE_SYMBOL = 's' | 24 _NODE_TYPE_SYMBOL = 's' |
| 26 _NODE_NAME_KEY = 'n' | 25 _NODE_NAME_KEY = 'n' |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if not os.path.exists(d3_out): | 155 if not os.path.exists(d3_out): |
| 157 os.makedirs(d3_out, 0755) | 156 os.makedirs(d3_out, 0755) |
| 158 d3_src = os.path.join(helpers.SRC_ROOT, 'third_party', 'd3', 'src') | 157 d3_src = os.path.join(helpers.SRC_ROOT, 'third_party', 'd3', 'src') |
| 159 template_src = os.path.join(os.path.dirname(__file__), 'template') | 158 template_src = os.path.join(os.path.dirname(__file__), 'template') |
| 160 shutil.copy(os.path.join(d3_src, 'LICENSE'), d3_out) | 159 shutil.copy(os.path.join(d3_src, 'LICENSE'), d3_out) |
| 161 shutil.copy(os.path.join(d3_src, 'd3.js'), d3_out) | 160 shutil.copy(os.path.join(d3_src, 'd3.js'), d3_out) |
| 162 shutil.copy(os.path.join(template_src, 'index.html'), dest_dir) | 161 shutil.copy(os.path.join(template_src, 'index.html'), dest_dir) |
| 163 shutil.copy(os.path.join(template_src, 'D3SymbolTreeMap.js'), dest_dir) | 162 shutil.copy(os.path.join(template_src, 'D3SymbolTreeMap.js'), dest_dir) |
| 164 | 163 |
| 165 | 164 |
| 166 def main(argv): | 165 def AddArguments(parser): |
| 167 parser = argparse.ArgumentParser() | |
| 168 parser.add_argument('input_file', | 166 parser.add_argument('input_file', |
| 169 help='Path to input .size file.') | 167 help='Path to input .size file.') |
| 170 parser.add_argument('--report-dir', metavar='PATH', required=True, | 168 parser.add_argument('--report-dir', metavar='PATH', required=True, |
| 171 help='Write output to the specified directory. An HTML ' | 169 help='Write output to the specified directory. An HTML ' |
| 172 'report is generated here.') | 170 'report is generated here.') |
| 173 parser.add_argument('--include-bss', action='store_true', | 171 parser.add_argument('--include-bss', action='store_true', |
| 174 help='Include symbols from .bss (which consume no real ' | 172 help='Include symbols from .bss (which consume no real ' |
| 175 'space)') | 173 'space)') |
| 176 parser.add_argument('--include-symbols', action='store_true', | 174 parser.add_argument('--include-symbols', action='store_true', |
| 177 help='Use per-symbol granularity rather than per-file.') | 175 help='Use per-symbol granularity rather than per-file.') |
| 178 args = helpers.AddCommonOptionsAndParseArgs(parser, argv) | |
| 179 | 176 |
| 180 size_info = map2size.LoadAndPostProcessSizeInfo(args.input_file) | 177 |
| 178 def Run(args, parser): |
| 179 if not args.input_file.endswith('.size'): |
| 180 parser.error('Input must end with ".size"') |
| 181 |
| 182 logging.info('Reading .size file') |
| 183 size_info = archive.LoadAndPostProcessSizeInfo(args.input_file) |
| 181 symbols = size_info.symbols | 184 symbols = size_info.symbols |
| 182 if not args.include_bss: | 185 if not args.include_bss: |
| 183 symbols = symbols.WhereInSection('b').Inverted() | 186 symbols = symbols.WhereInSection('b').Inverted() |
| 184 symbols = symbols.WhereBiggerThan(0) | 187 symbols = symbols.WhereBiggerThan(0) |
| 185 | 188 |
| 186 # Copy report boilerplate into output directory. This also proves that the | 189 # Copy report boilerplate into output directory. This also proves that the |
| 187 # output directory is safe for writing, so there should be no problems writing | 190 # output directory is safe for writing, so there should be no problems writing |
| 188 # the nm.out file later. | 191 # the nm.out file later. |
| 189 _CopyTemplateFiles(args.report_dir) | 192 _CopyTemplateFiles(args.report_dir) |
| 190 | 193 |
| 191 logging.info('Creating JSON objects') | 194 logging.info('Creating JSON objects') |
| 192 tree_root = _MakeCompactTree(symbols, args.include_symbols) | 195 tree_root = _MakeCompactTree(symbols, args.include_symbols) |
| 193 | 196 |
| 194 logging.info('Serializing') | 197 logging.info('Serializing JSON') |
| 195 with open(os.path.join(args.report_dir, 'data.js'), 'w') as out_file: | 198 with open(os.path.join(args.report_dir, 'data.js'), 'w') as out_file: |
| 196 out_file.write('var tree_data=') | 199 out_file.write('var tree_data=') |
| 197 # Use separators without whitespace to get a smaller file. | 200 # Use separators without whitespace to get a smaller file. |
| 198 json.dump(tree_root, out_file, ensure_ascii=False, check_circular=False, | 201 json.dump(tree_root, out_file, ensure_ascii=False, check_circular=False, |
| 199 separators=(',', ':')) | 202 separators=(',', ':')) |
| 200 | 203 |
| 201 print 'Report saved to ' + args.report_dir + '/index.html' | 204 logging.warning('Report saved to %s/index.html', args.report_dir) |
| 202 | |
| 203 | |
| 204 if __name__ == '__main__': | |
| 205 sys.exit(main(sys.argv)) | |
| OLD | NEW |