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 """Generate a spatial analysis against an arbitrary library. | 6 """Generate a spatial analysis against an arbitrary library. |
7 | 7 |
8 To use, build the 'binary_size_tool' target. Then run this tool, passing | 8 To use, build the 'binary_size_tool' target. Then run this tool, passing |
9 in the location of the library to be analyzed along with any other options | 9 in the location of the library to be analyzed along with any other options |
10 you desire. | 10 you desire. |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 return 2 # Depth of the added subtree. | 162 return 2 # Depth of the added subtree. |
163 | 163 |
164 | 164 |
165 def MakeCompactTree(symbols, symbol_path_origin_dir): | 165 def MakeCompactTree(symbols, symbol_path_origin_dir): |
166 result = {NODE_NAME_KEY: '/', | 166 result = {NODE_NAME_KEY: '/', |
167 NODE_CHILDREN_KEY: {}, | 167 NODE_CHILDREN_KEY: {}, |
168 NODE_TYPE_KEY: 'p', | 168 NODE_TYPE_KEY: 'p', |
169 NODE_MAX_DEPTH_KEY: 0} | 169 NODE_MAX_DEPTH_KEY: 0} |
170 seen_symbol_with_path = False | 170 seen_symbol_with_path = False |
171 cwd = os.path.abspath(os.getcwd()) | 171 cwd = os.path.abspath(os.getcwd()) |
172 for symbol_name, symbol_type, symbol_size, file_path in symbols: | 172 for symbol_name, symbol_type, symbol_size, file_path, _address in symbols: |
173 | 173 |
174 if 'vtable for ' in symbol_name: | 174 if 'vtable for ' in symbol_name: |
175 symbol_type = '@' # hack to categorize these separately | 175 symbol_type = '@' # hack to categorize these separately |
176 # Take path like '/foo/bar/baz', convert to ['foo', 'bar', 'baz'] | 176 # Take path like '/foo/bar/baz', convert to ['foo', 'bar', 'baz'] |
177 if file_path and file_path != "??": | 177 if file_path and file_path != "??": |
178 file_path = os.path.abspath(os.path.join(symbol_path_origin_dir, | 178 file_path = os.path.abspath(os.path.join(symbol_path_origin_dir, |
179 file_path)) | 179 file_path)) |
180 # Let the output structure be relative to $CWD if inside $CWD, | 180 # Let the output structure be relative to $CWD if inside $CWD, |
181 # otherwise relative to the disk root. This is to avoid | 181 # otherwise relative to the disk root. This is to avoid |
182 # unnecessary click-through levels in the output. | 182 # unnecessary click-through levels in the output. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 tree_root = MakeCompactTree(symbols, symbol_path_origin_dir) | 224 tree_root = MakeCompactTree(symbols, symbol_path_origin_dir) |
225 with open(outfile, 'w') as out: | 225 with open(outfile, 'w') as out: |
226 out.write('var tree_data=') | 226 out.write('var tree_data=') |
227 # Use separators without whitespace to get a smaller file. | 227 # Use separators without whitespace to get a smaller file. |
228 json.dump(tree_root, out, separators=(',', ':')) | 228 json.dump(tree_root, out, separators=(',', ':')) |
229 print('Writing %d bytes json' % os.path.getsize(outfile)) | 229 print('Writing %d bytes json' % os.path.getsize(outfile)) |
230 | 230 |
231 | 231 |
232 def MakeSourceMap(symbols): | 232 def MakeSourceMap(symbols): |
233 sources = {} | 233 sources = {} |
234 for _sym, _symbol_type, size, path in symbols: | 234 for _sym, _symbol_type, size, path, _address in symbols: |
235 key = None | 235 key = None |
236 if path: | 236 if path: |
237 key = os.path.normpath(path) | 237 key = os.path.normpath(path) |
238 else: | 238 else: |
239 key = '[no path]' | 239 key = '[no path]' |
240 if key not in sources: | 240 if key not in sources: |
241 sources[key] = {'path': path, 'symbol_count': 0, 'size': 0} | 241 sources[key] = {'path': path, 'symbol_count': 0, 'size': 0} |
242 record = sources[key] | 242 record = sources[key] |
243 record['size'] += size | 243 record['size'] += size |
244 record['symbol_count'] += 1 | 244 record['symbol_count'] += 1 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 shutil.copy(os.path.join(d3_src, 'LICENSE'), d3_out) | 683 shutil.copy(os.path.join(d3_src, 'LICENSE'), d3_out) |
684 shutil.copy(os.path.join(d3_src, 'd3.js'), d3_out) | 684 shutil.copy(os.path.join(d3_src, 'd3.js'), d3_out) |
685 shutil.copy(os.path.join(template_src, 'index.html'), opts.destdir) | 685 shutil.copy(os.path.join(template_src, 'index.html'), opts.destdir) |
686 shutil.copy(os.path.join(template_src, 'D3SymbolTreeMap.js'), opts.destdir) | 686 shutil.copy(os.path.join(template_src, 'D3SymbolTreeMap.js'), opts.destdir) |
687 | 687 |
688 print 'Report saved to ' + opts.destdir + '/index.html' | 688 print 'Report saved to ' + opts.destdir + '/index.html' |
689 | 689 |
690 | 690 |
691 if __name__ == '__main__': | 691 if __name__ == '__main__': |
692 sys.exit(main()) | 692 sys.exit(main()) |
OLD | NEW |