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