OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # 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 |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """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.""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import json | 8 import json |
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import shutil | 11 import shutil |
12 import sys | 12 import sys |
13 | 13 |
14 import archive | 14 import archive |
15 import helpers | 15 import paths |
16 | 16 |
17 | 17 |
18 # 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 |
19 # keep them short to save file size. | 19 # keep them short to save file size. |
20 # Note: If these change, the webapp must also change. | 20 # Note: If these change, the webapp must also change. |
21 _NODE_TYPE_KEY = 'k' | 21 _NODE_TYPE_KEY = 'k' |
22 _NODE_TYPE_BUCKET = 'b' | 22 _NODE_TYPE_BUCKET = 'b' |
23 _NODE_TYPE_PATH = 'p' | 23 _NODE_TYPE_PATH = 'p' |
24 _NODE_TYPE_SYMBOL = 's' | 24 _NODE_TYPE_SYMBOL = 's' |
25 _NODE_NAME_KEY = 'n' | 25 _NODE_NAME_KEY = 'n' |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 _MakeChildrenDictsIntoLists(result) | 148 _MakeChildrenDictsIntoLists(result) |
149 | 149 |
150 return result | 150 return result |
151 | 151 |
152 | 152 |
153 def _CopyTemplateFiles(dest_dir): | 153 def _CopyTemplateFiles(dest_dir): |
154 d3_out = os.path.join(dest_dir, 'd3') | 154 d3_out = os.path.join(dest_dir, 'd3') |
155 if not os.path.exists(d3_out): | 155 if not os.path.exists(d3_out): |
156 os.makedirs(d3_out, 0755) | 156 os.makedirs(d3_out, 0755) |
157 d3_src = os.path.join(helpers.SRC_ROOT, 'third_party', 'd3', 'src') | 157 d3_src = os.path.join(paths.SRC_ROOT, 'third_party', 'd3', 'src') |
158 template_src = os.path.join(os.path.dirname(__file__), 'template') | 158 template_src = os.path.join(os.path.dirname(__file__), 'template') |
159 shutil.copy(os.path.join(d3_src, 'LICENSE'), d3_out) | 159 shutil.copy(os.path.join(d3_src, 'LICENSE'), d3_out) |
160 shutil.copy(os.path.join(d3_src, 'd3.js'), d3_out) | 160 shutil.copy(os.path.join(d3_src, 'd3.js'), d3_out) |
161 shutil.copy(os.path.join(template_src, 'index.html'), dest_dir) | 161 shutil.copy(os.path.join(template_src, 'index.html'), dest_dir) |
162 shutil.copy(os.path.join(template_src, 'D3SymbolTreeMap.js'), dest_dir) | 162 shutil.copy(os.path.join(template_src, 'D3SymbolTreeMap.js'), dest_dir) |
163 | 163 |
164 | 164 |
165 def AddArguments(parser): | 165 def AddArguments(parser): |
166 parser.add_argument('input_file', | 166 parser.add_argument('input_file', |
167 help='Path to input .size file.') | 167 help='Path to input .size file.') |
168 parser.add_argument('--report-dir', metavar='PATH', required=True, | 168 parser.add_argument('--report-dir', metavar='PATH', required=True, |
169 help='Write output to the specified directory. An HTML ' | 169 help='Write output to the specified directory. An HTML ' |
170 'report is generated here.') | 170 'report is generated here.') |
171 parser.add_argument('--include-bss', action='store_true', | 171 parser.add_argument('--include-bss', action='store_true', |
172 help='Include symbols from .bss (which consume no real ' | 172 help='Include symbols from .bss (which consume no real ' |
173 'space)') | 173 'space)') |
174 parser.add_argument('--include-symbols', action='store_true', | 174 parser.add_argument('--include-symbols', action='store_true', |
175 help='Use per-symbol granularity rather than per-file.') | 175 help='Use per-symbol granularity rather than per-file.') |
176 | 176 |
177 | 177 |
178 def Run(args, parser): | 178 def Run(args, parser): |
179 if not args.input_file.endswith('.size'): | 179 if not args.input_file.endswith('.size'): |
180 parser.error('Input must end with ".size"') | 180 parser.error('Input must end with ".size"') |
181 | 181 |
182 logging.info('Reading .size file') | 182 logging.info('Reading .size file') |
183 size_info = archive.LoadAndPostProcessSizeInfo(args.input_file) | 183 size_info = archive.LoadAndPostProcessSizeInfo(args.input_file) |
184 symbols = size_info.symbols | 184 symbols = size_info.symbols |
185 if not args.include_bss: | 185 if not args.include_bss: |
186 symbols = symbols.WhereInSection('b').Inverted() | 186 symbols = symbols.WhereInSection('b').Inverted() |
187 symbols = symbols.WhereBiggerThan(0) | 187 symbols = symbols.WherePssBiggerThan(0) |
188 | 188 |
189 # Copy report boilerplate into output directory. This also proves that the | 189 # Copy report boilerplate into output directory. This also proves that the |
190 # 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 |
191 # the nm.out file later. | 191 # the nm.out file later. |
192 _CopyTemplateFiles(args.report_dir) | 192 _CopyTemplateFiles(args.report_dir) |
193 | 193 |
194 logging.info('Creating JSON objects') | 194 logging.info('Creating JSON objects') |
195 tree_root = _MakeCompactTree(symbols, args.include_symbols) | 195 tree_root = _MakeCompactTree(symbols, args.include_symbols) |
196 | 196 |
197 logging.info('Serializing JSON') | 197 logging.info('Serializing JSON') |
198 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: |
199 out_file.write('var tree_data=') | 199 out_file.write('var tree_data=') |
200 # Use separators without whitespace to get a smaller file. | 200 # Use separators without whitespace to get a smaller file. |
201 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, |
202 separators=(',', ':')) | 202 separators=(',', ':')) |
203 | 203 |
204 logging.warning('Report saved to %s/index.html', args.report_dir) | 204 logging.warning('Report saved to %s/index.html', args.report_dir) |
OLD | NEW |