| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 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 """Tool for analyzing binary size of executables using nm or linker map files. | 6 """Tool for analyzing binary size of executables using nm or linker map files. |
| 7 | 7 |
| 8 Map files can be created by passing "-Map Foo.map" to the linker. If a map file | 8 Map files can be created by passing "-Map Foo.map" to the linker. If a map file |
| 9 is unavailable, this tool can also be pointed at an unstripped executable, but | 9 is unavailable, this tool can also be pointed at an unstripped executable, but |
| 10 the information does not seem to be as accurate in this case. | 10 the information does not seem to be as accurate in this case. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 self._size_infos = size_infos | 86 self._size_infos = size_infos |
| 87 | 87 |
| 88 if len(size_infos) == 1: | 88 if len(size_infos) == 1: |
| 89 self._variables['size_info'] = size_infos[0] | 89 self._variables['size_info'] = size_infos[0] |
| 90 self._variables['symbols'] = size_infos[0].symbols | 90 self._variables['symbols'] = size_infos[0].symbols |
| 91 else: | 91 else: |
| 92 for i, size_info in enumerate(size_infos): | 92 for i, size_info in enumerate(size_infos): |
| 93 self._variables['size_info%d' % (i + 1)] = size_info | 93 self._variables['size_info%d' % (i + 1)] = size_info |
| 94 self._variables['symbols%d' % (i + 1)] = size_info.symbols | 94 self._variables['symbols%d' % (i + 1)] = size_info.symbols |
| 95 | 95 |
| 96 def _PrintFunc(self, obj, verbose=False, use_pager=None, to_file=None): | 96 def _PrintFunc(self, obj, verbose=False, recursive=False, use_pager=None, |
| 97 to_file=None): |
| 97 """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. | 98 """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. |
| 98 | 99 |
| 99 Args: | 100 Args: |
| 100 obj: The object to be printed. | 101 obj: The object to be printed. |
| 101 verbose: Show more detailed output. | 102 verbose: Show more detailed output. |
| 103 recursive: Print children of nested SymbolGroups. |
| 102 use_pager: Pipe output through `less`. Ignored when |obj| is a Symbol. | 104 use_pager: Pipe output through `less`. Ignored when |obj| is a Symbol. |
| 103 default is to automatically pipe when output is long. | 105 default is to automatically pipe when output is long. |
| 104 to_file: Rather than print to stdio, write to the given file. | 106 to_file: Rather than print to stdio, write to the given file. |
| 105 """ | 107 """ |
| 106 lines = describe.GenerateLines(obj, verbose=verbose) | 108 lines = describe.GenerateLines(obj, verbose=verbose, recursive=recursive) |
| 107 _WriteToStream(lines, use_pager=use_pager, to_file=to_file) | 109 _WriteToStream(lines, use_pager=use_pager, to_file=to_file) |
| 108 | 110 |
| 109 def _ElfPathForSymbol(self, symbol): | 111 def _ElfPathForSymbol(self, symbol): |
| 110 size_info = None | 112 size_info = None |
| 111 for size_info in self._size_infos: | 113 for size_info in self._size_infos: |
| 112 if symbol in size_info.symbols: | 114 if symbol in size_info.symbols: |
| 113 break | 115 break |
| 114 else: | 116 else: |
| 115 assert False, 'Symbol does not belong to a size_info.' | 117 assert False, 'Symbol does not belong to a size_info.' |
| 116 | 118 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 help='Print the result of the given snippet. Example: ' | 240 help='Print the result of the given snippet. Example: ' |
| 239 'symbols.WhereInSection("d").' | 241 'symbols.WhereInSection("d").' |
| 240 'WhereBiggerThan(100)') | 242 'WhereBiggerThan(100)') |
| 241 paths.AddOptions(parser) | 243 paths.AddOptions(parser) |
| 242 args = helpers.AddCommonOptionsAndParseArgs(parser, argv) | 244 args = helpers.AddCommonOptionsAndParseArgs(parser, argv) |
| 243 | 245 |
| 244 for path in args.inputs: | 246 for path in args.inputs: |
| 245 if not path.endswith('.size'): | 247 if not path.endswith('.size'): |
| 246 parser.error('All inputs must end with ".size"') | 248 parser.error('All inputs must end with ".size"') |
| 247 | 249 |
| 248 size_infos = [map2size.Analyze(p) for p in args.inputs] | 250 size_infos = [map2size.LoadAndPostProcessSizeInfo(p) for p in args.inputs] |
| 249 lazy_paths = paths.LazyPaths(args=args, input_file=args.inputs[0]) | 251 lazy_paths = paths.LazyPaths(args=args, input_file=args.inputs[0]) |
| 250 session = _Session(size_infos, lazy_paths) | 252 session = _Session(size_infos, lazy_paths) |
| 251 | 253 |
| 252 if args.query: | 254 if args.query: |
| 253 logging.info('Running query from command-line.') | 255 logging.info('Running query from command-line.') |
| 254 session.Eval(args.query) | 256 session.Eval(args.query) |
| 255 else: | 257 else: |
| 256 logging.info('Entering interactive console.') | 258 logging.info('Entering interactive console.') |
| 257 session.GoInteractive() | 259 session.GoInteractive() |
| 258 | 260 |
| 259 | 261 |
| 260 if __name__ == '__main__': | 262 if __name__ == '__main__': |
| 261 sys.exit(main(sys.argv)) | 263 sys.exit(main(sys.argv)) |
| OLD | NEW |