| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """An interactive console for looking analyzing .size files.""" | 5 """An interactive console for looking analyzing .size files.""" |
| 6 | 6 |
| 7 import argparse | 7 import argparse |
| 8 import atexit | 8 import atexit |
| 9 import code | 9 import code |
| 10 import contextlib | 10 import contextlib |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 else: | 83 else: |
| 84 for i, size_info in enumerate(size_infos): | 84 for i, size_info in enumerate(size_infos): |
| 85 self._variables['size_info%d' % (i + 1)] = size_info | 85 self._variables['size_info%d' % (i + 1)] = size_info |
| 86 | 86 |
| 87 def _DiffFunc(self, before=None, after=None, cluster=True, sort=True): | 87 def _DiffFunc(self, before=None, after=None, cluster=True, sort=True): |
| 88 """Diffs two SizeInfo objects. Returns a SizeInfoDiff. | 88 """Diffs two SizeInfo objects. Returns a SizeInfoDiff. |
| 89 | 89 |
| 90 Args: | 90 Args: |
| 91 before: Defaults to first size_infos[0]. | 91 before: Defaults to first size_infos[0]. |
| 92 after: Defaults to second size_infos[1]. | 92 after: Defaults to second size_infos[1]. |
| 93 cluster: When True (default), calls SymbolGroup.Cluster() after diffing. | 93 cluster: When True (default), calls SymbolGroup.Clustered() after diffing. |
| 94 Generally reduces noise. | 94 Generally reduces noise. |
| 95 sort: When True (default), calls SymbolGroup.Sorted() after diffing. | 95 sort: When True (default), calls SymbolGroup.Sorted() after diffing. |
| 96 """ | 96 """ |
| 97 before = before if before is not None else self._size_infos[0] | 97 before = before if before is not None else self._size_infos[0] |
| 98 after = after if after is not None else self._size_infos[1] | 98 after = after if after is not None else self._size_infos[1] |
| 99 ret = diff.Diff(before, after) | 99 ret = diff.Diff(before, after) |
| 100 if cluster: | 100 if cluster: |
| 101 ret.symbols = ret.symbols.Cluster() | 101 ret.symbols = ret.symbols.Clustered() |
| 102 if sort: | 102 if sort: |
| 103 ret.symbols = ret.symbols.Sorted() | 103 ret.symbols = ret.symbols.Sorted() |
| 104 return ret | 104 return ret |
| 105 | 105 |
| 106 def _PrintFunc(self, obj=None, verbose=False, recursive=False, use_pager=None, | 106 def _PrintFunc(self, obj=None, verbose=False, recursive=False, use_pager=None, |
| 107 to_file=None): | 107 to_file=None): |
| 108 """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. | 108 """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. |
| 109 | 109 |
| 110 Args: | 110 Args: |
| 111 obj: The object to be printed. Defaults to size_infos[-1]. | 111 obj: The object to be printed. Defaults to size_infos[-1]. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 print '\n'.join([ | 166 print '\n'.join([ |
| 167 '# Show pydoc for main types:', | 167 '# Show pydoc for main types:', |
| 168 'import models', | 168 'import models', |
| 169 'help(models)', | 169 'help(models)', |
| 170 '', | 170 '', |
| 171 '# Show all attributes of all symbols & per-section totals:', | 171 '# Show all attributes of all symbols & per-section totals:', |
| 172 'Print(size_info, verbose=True)', | 172 'Print(size_info, verbose=True)', |
| 173 '', | 173 '', |
| 174 '# Show two levels of .text, grouped by first two subdirectories', | 174 '# Show two levels of .text, grouped by first two subdirectories', |
| 175 'text_syms = size_info.symbols.WhereInSection("t")', | 175 'text_syms = size_info.symbols.WhereInSection("t")', |
| 176 'by_path = text_syms.GroupByPath(depth=2)', | 176 'by_path = text_syms.GroupedByPath(depth=2)', |
| 177 'Print(by_path.WhereBiggerThan(1024))', | 177 'Print(by_path.WhereBiggerThan(1024))', |
| 178 '', | 178 '', |
| 179 '# Show all non-vtable generated symbols', | 179 '# Show all non-vtable generated symbols', |
| 180 'generated_syms = size_info.symbols.WhereGeneratedByToolchain()', | 180 'generated_syms = size_info.symbols.WhereGeneratedByToolchain()', |
| 181 'Print(generated_syms.WhereNameMatches(r"vtable").Inverted().Sorted())', | 181 'Print(generated_syms.WhereNameMatches(r"vtable").Inverted().Sorted())', |
| 182 '', | 182 '', |
| 183 '# Show all symbols that have "print" in their name or path, except', | 183 '# Show all symbols that have "print" in their name or path, except', |
| 184 '# those within components/.', | 184 '# those within components/.', |
| 185 '# Note: Could have also used Inverted(), as above.', | 185 '# Note: Could have also used Inverted(), as above.', |
| 186 '# Note: Use "help(ExpandRegex)" for more about what {{_print_}} does.', | 186 '# Note: Use "help(ExpandRegex)" for more about what {{_print_}} does.', |
| 187 'print_syms = size_info.symbols.WhereMatches(r"{{_print_}}")', | 187 'print_syms = size_info.symbols.WhereMatches(r"{{_print_}}")', |
| 188 'Print(print_syms - print_syms.WherePathMatches(r"^components/"))', | 188 'Print(print_syms - print_syms.WherePathMatches(r"^components/"))', |
| 189 '', | 189 '', |
| 190 '# Diff two .size files and save result to a file:', | 190 '# Diff two .size files and save result to a file:', |
| 191 'Print(Diff(size_info1, size_info2), to_file="output.txt")', | 191 'Print(Diff(size_info1, size_info2), to_file="output.txt")', |
| 192 '', | 192 '', |
| 193 '# View per-component breakdowns, then drill into the last entry.', | 193 '# View per-component breakdowns, then drill into the last entry.', |
| 194 'c = canned_queries.CategorizeByChromeComponent()', | 194 'c = canned_queries.CategorizeByChromeComponent()', |
| 195 'Print(c)', | 195 'Print(c)', |
| 196 'Print(c[-1].GroupByPath(depth=2).Sorted())', | 196 'Print(c[-1].GroupedByPath(depth=2).Clustered().Sorted())', |
| 197 '', | 197 '', |
| 198 '# For even more inspiration, look at canned_queries.py', | 198 '# For even more inspiration, look at canned_queries.py', |
| 199 '# (and feel free to add your own!).', | 199 '# (and feel free to add your own!).', |
| 200 ]) | 200 ]) |
| 201 | 201 |
| 202 def _CreateBanner(self): | 202 def _CreateBanner(self): |
| 203 symbol_info_keys = sorted(m for m in dir(models.SizeInfo) if m[0] != '_') | 203 symbol_info_keys = sorted(m for m in dir(models.SizeInfo) if m[0] != '_') |
| 204 symbol_keys = sorted(m for m in dir(models.Symbol) if m[0] != '_') | 204 symbol_keys = sorted(m for m in dir(models.Symbol) if m[0] != '_') |
| 205 symbol_group_keys = [m for m in dir(models.SymbolGroup) if m[0] != '_'] | 205 symbol_group_keys = [m for m in dir(models.SymbolGroup) if m[0] != '_'] |
| 206 symbol_diff_keys = sorted(m for m in dir(models.SymbolDiff) | 206 symbol_diff_keys = sorted(m for m in dir(models.SymbolDiff) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 output_directory=args.output_directory, | 277 output_directory=args.output_directory, |
| 278 any_path_within_output_directory=args.inputs[0]) | 278 any_path_within_output_directory=args.inputs[0]) |
| 279 session = _Session(size_infos, lazy_paths) | 279 session = _Session(size_infos, lazy_paths) |
| 280 | 280 |
| 281 if args.query: | 281 if args.query: |
| 282 logging.info('Running query from command-line.') | 282 logging.info('Running query from command-line.') |
| 283 session.Eval(args.query) | 283 session.Eval(args.query) |
| 284 else: | 284 else: |
| 285 logging.info('Entering interactive console.') | 285 logging.info('Entering interactive console.') |
| 286 session.GoInteractive() | 286 session.GoInteractive() |
| OLD | NEW |