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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 'Diff': models.Diff, | 70 'Diff': models.Diff, |
71 'Disassemble': self._DisassembleFunc, | 71 'Disassemble': self._DisassembleFunc, |
72 'ExpandRegex': match_util.ExpandRegexIdentifierPlaceholder, | 72 'ExpandRegex': match_util.ExpandRegexIdentifierPlaceholder, |
73 'ShowExamples': self._ShowExamplesFunc, | 73 'ShowExamples': self._ShowExamplesFunc, |
74 } | 74 } |
75 self._lazy_paths = lazy_paths | 75 self._lazy_paths = lazy_paths |
76 self._size_infos = size_infos | 76 self._size_infos = size_infos |
77 | 77 |
78 if len(size_infos) == 1: | 78 if len(size_infos) == 1: |
79 self._variables['size_info'] = size_infos[0] | 79 self._variables['size_info'] = size_infos[0] |
80 self._variables['symbols'] = size_infos[0].symbols | |
81 else: | 80 else: |
82 for i, size_info in enumerate(size_infos): | 81 for i, size_info in enumerate(size_infos): |
83 self._variables['size_info%d' % (i + 1)] = size_info | 82 self._variables['size_info%d' % (i + 1)] = size_info |
84 self._variables['symbols%d' % (i + 1)] = size_info.symbols | |
85 | 83 |
86 def _PrintFunc(self, obj, verbose=False, recursive=False, use_pager=None, | 84 def _PrintFunc(self, obj, verbose=False, recursive=False, use_pager=None, |
87 to_file=None): | 85 to_file=None): |
88 """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. | 86 """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. |
89 | 87 |
90 Args: | 88 Args: |
91 obj: The object to be printed. | 89 obj: The object to be printed. |
92 verbose: Show more detailed output. | 90 verbose: Show more detailed output. |
93 recursive: Print children of nested SymbolGroups. | 91 recursive: Print children of nested SymbolGroups. |
94 use_pager: Pipe output through `less`. Ignored when |obj| is a Symbol. | 92 use_pager: Pipe output through `less`. Ignored when |obj| is a Symbol. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 def _ShowExamplesFunc(self): | 141 def _ShowExamplesFunc(self): |
144 print '\n'.join([ | 142 print '\n'.join([ |
145 '# Show pydoc for main types:', | 143 '# Show pydoc for main types:', |
146 'import models', | 144 'import models', |
147 'help(models)', | 145 'help(models)', |
148 '', | 146 '', |
149 '# Show all attributes of all symbols & per-section totals:', | 147 '# Show all attributes of all symbols & per-section totals:', |
150 'Print(size_info, verbose=True)', | 148 'Print(size_info, verbose=True)', |
151 '', | 149 '', |
152 '# Show two levels of .text, grouped by first two subdirectories', | 150 '# Show two levels of .text, grouped by first two subdirectories', |
153 'text_syms = symbols.WhereInSection("t")', | 151 'text_syms = size_info.symbols.WhereInSection("t")', |
154 'by_path = text_syms.GroupBySourcePath(depth=2)', | 152 'by_path = text_syms.GroupBySourcePath(depth=2)', |
155 'Print(by_path.WhereBiggerThan(1024))', | 153 'Print(by_path.WhereBiggerThan(1024))', |
156 '', | 154 '', |
157 '# Show all non-vtable generated symbols', | 155 '# Show all non-vtable generated symbols', |
158 'generated_syms = symbols.WhereIsGenerated()', | 156 'generated_syms = size_info.symbols.WhereIsGenerated()', |
159 'Print(generated_syms.WhereNameMatches(r"vtable").Inverted())', | 157 'Print(generated_syms.WhereNameMatches(r"vtable").Inverted())', |
160 '', | 158 '', |
161 '# Show all symbols that have "print" in their name or path, except', | 159 '# Show all symbols that have "print" in their name or path, except', |
162 '# those within components/.', | 160 '# those within components/.', |
163 '# Note: Could have also used Inverted(), as above.', | 161 '# Note: Could have also used Inverted(), as above.', |
164 '# Note: Use "help(ExpandRegex)" for more about what {{_print_}} does.', | 162 '# Note: Use "help(ExpandRegex)" for more about what {{_print_}} does.', |
165 'print_syms = symbols.WhereMatches(r"{{_print_}}")', | 163 'print_syms = size_info.symbols.WhereMatches(r"{{_print_}}")', |
166 'Print(print_syms - print_syms.WherePathMatches(r"^components/"))', | 164 'Print(print_syms - print_syms.WherePathMatches(r"^components/"))', |
167 '', | 165 '', |
168 '# Diff two .size files and save result to a file:', | 166 '# Diff two .size files and save result to a file:', |
169 'Print(Diff(size_info1, size_info2), to_file="output.txt")', | 167 'Print(Diff(size_info1, size_info2), to_file="output.txt")', |
170 '', | 168 '', |
171 ]) | 169 ]) |
172 | 170 |
173 def _CreateBanner(self): | 171 def _CreateBanner(self): |
174 symbol_info_keys = sorted(m for m in dir(models.SizeInfo) if m[0] != '_') | 172 symbol_info_keys = sorted(m for m in dir(models.SizeInfo) if m[0] != '_') |
175 symbol_keys = sorted(m for m in dir(models.Symbol) if m[0] != '_') | 173 symbol_keys = sorted(m for m in dir(models.Symbol) if m[0] != '_') |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 size_infos = [archive.LoadAndPostProcessSizeInfo(p) for p in args.inputs] | 241 size_infos = [archive.LoadAndPostProcessSizeInfo(p) for p in args.inputs] |
244 lazy_paths = paths.LazyPaths(args=args, input_file=args.inputs[0]) | 242 lazy_paths = paths.LazyPaths(args=args, input_file=args.inputs[0]) |
245 session = _Session(size_infos, lazy_paths) | 243 session = _Session(size_infos, lazy_paths) |
246 | 244 |
247 if args.query: | 245 if args.query: |
248 logging.info('Running query from command-line.') | 246 logging.info('Running query from command-line.') |
249 session.Eval(args.query) | 247 session.Eval(args.query) |
250 else: | 248 else: |
251 logging.info('Entering interactive console.') | 249 logging.info('Entering interactive console.') |
252 session.GoInteractive() | 250 session.GoInteractive() |
OLD | NEW |