Chromium Code Reviews| Index: tools/binary_size/libsupersize/console.py |
| diff --git a/tools/binary_size/libsupersize/console.py b/tools/binary_size/libsupersize/console.py |
| index 40c3fdbb682e4c1d1b131b82768c1a6dd984e31a..9d6a5b1faa4f6f8046a819911d41881c9f8fa8c8 100644 |
| --- a/tools/binary_size/libsupersize/console.py |
| +++ b/tools/binary_size/libsupersize/console.py |
| @@ -22,10 +22,11 @@ import file_format |
| import match_util |
| import models |
| import paths |
| +import precanned_queries |
|
estevenson
2017/05/05 22:24:18
nit/name bikeshed: the "pre" in precanned_queries
agrieve
2017/05/06 01:18:22
true. Done.
|
| # Number of lines before using less for Print(). |
| -_THRESHOLD_FOR_PAGER = 30 |
| +_THRESHOLD_FOR_PAGER = 50 |
| @contextlib.contextmanager |
| @@ -68,7 +69,9 @@ class _Session(object): |
| def __init__(self, size_infos, lazy_paths): |
| self._variables = { |
| 'Print': self._PrintFunc, |
| - 'Diff': diff.Diff, |
| + 'Diff': self._DiffFunc, |
| + 'CategorizeByChromeComponent': self._CategorizeByChromeComponentFunc, |
| + 'CategorizeGenerated': self._CategorizeGeneratedFunc, |
| 'Disassemble': self._DisassembleFunc, |
| 'ExpandRegex': match_util.ExpandRegexIdentifierPlaceholder, |
| 'ShowExamples': self._ShowExamplesFunc, |
| @@ -82,21 +85,58 @@ class _Session(object): |
| for i, size_info in enumerate(size_infos): |
| self._variables['size_info%d' % (i + 1)] = size_info |
| - def _PrintFunc(self, obj, verbose=False, recursive=False, use_pager=None, |
| + def _DiffFunc(self, before=None, after=None, cluster=True): |
| + """Diffs two SizeInfo objects. Returns a SizeInfoDiff. |
| + |
| + Args: |
| + before: Defaults to first size_infos[0]. |
| + after: Defaults to second size_infos[1]. |
| + cluster: When True, calls SymbolGroup.Cluster() after diffing. This |
| + generally reduces noise. |
| + """ |
| + before = before if before is not None else self._size_infos[0] |
|
estevenson
2017/05/05 22:24:18
nit: before or self.size_infos[0]? (+ obj in _Prin
agrieve
2017/05/06 01:18:22
I had that before, but turns out it's wrong in the
|
| + after = after if after is not None else self._size_infos[1] |
| + return diff.Diff(before, after, cluster=cluster) |
| + |
| + def _PrintFunc(self, obj=None, verbose=False, recursive=False, use_pager=None, |
| to_file=None): |
| """Prints out the given Symbol / SymbolGroup / SymbolDiff / SizeInfo. |
| Args: |
| - obj: The object to be printed. |
| + obj: The object to be printed. Defaults to size_infos[-1]. |
| verbose: Show more detailed output. |
| recursive: Print children of nested SymbolGroups. |
| use_pager: Pipe output through `less`. Ignored when |obj| is a Symbol. |
| default is to automatically pipe when output is long. |
| to_file: Rather than print to stdio, write to the given file. |
| """ |
| + obj = obj if obj is not None else self._size_infos[-1] |
| lines = describe.GenerateLines(obj, verbose=verbose, recursive=recursive) |
| _WriteToStream(lines, use_pager=use_pager, to_file=to_file) |
| + def _CategorizeByChromeComponentFunc(self, arg=None): |
| + """Groups symbols by component using predefined queries. |
| + |
| + Args: |
| + arg: A SizeInfo or SymbolGroup. Defaults to the size_infos[-1]. |
| + """ |
| + arg = arg if arg is not None else self._size_infos[-1] |
| + if isinstance(arg, models.SizeInfo): |
| + arg = arg.symbols |
| + return precanned_queries.CategorizeByChromeComponent(arg) |
| + |
| + def _CategorizeGeneratedFunc(self, arg=None): |
| + """Categorizes symbols from generated sources. |
| + |
| + Args: |
| + arg: A SizeInfo or SymbolGroup. Defaults to the size_infos[-1]. |
| + """ |
| + arg = arg if arg is not None else self._size_infos[-1] |
| + if isinstance(arg, models.SizeInfo): |
| + arg = arg.symbols |
| + return precanned_queries.CategorizeGenerated(arg) |
| + |
| + |
| def _ElfPathForSymbol(self, symbol): |
| size_info = None |
| for size_info in self._size_infos: |
| @@ -140,6 +180,7 @@ class _Session(object): |
| proc.kill() |
| def _ShowExamplesFunc(self): |
| + print self._CreateBanner() |
|
estevenson
2017/05/05 22:24:18
Might even be worth saying "Take a look at precann
agrieve
2017/05/06 01:18:22
Done.
|
| print '\n'.join([ |
| '# Show pydoc for main types:', |
| 'import models', |
| @@ -150,7 +191,7 @@ class _Session(object): |
| '', |
| '# Show two levels of .text, grouped by first two subdirectories', |
| 'text_syms = size_info.symbols.WhereInSection("t")', |
| - 'by_path = text_syms.GroupBySourcePath(depth=2)', |
| + 'by_path = text_syms.GroupByPath(depth=2)', |
| 'Print(by_path.WhereBiggerThan(1024))', |
| '', |
| '# Show all non-vtable generated symbols', |
| @@ -167,6 +208,10 @@ class _Session(object): |
| '# Diff two .size files and save result to a file:', |
| 'Print(Diff(size_info1, size_info2), to_file="output.txt")', |
| '', |
| + '# View per-component breakdowns, then inspect the "other" subgroup.', |
| + 'c = GroupByChromeComponent()', |
| + 'Print(c)', |
| + 'Print(c[-1].GroupByPath(depth=2))', |
|
estevenson
2017/05/05 22:24:18
nit: maybe specify what "other" is here?
agrieve
2017/05/06 01:18:22
Changed to "last element"
|
| ]) |
| def _CreateBanner(self): |
| @@ -185,7 +230,9 @@ class _Session(object): |
| '', |
| 'SizeInfo: %s' % ', '.join(symbol_info_keys), |
| 'Symbol: %s' % ', '.join(symbol_keys), |
| + '', |
| 'SymbolGroup (extends Symbol): %s' % ', '.join(symbol_group_keys), |
| + '', |
| 'SymbolDiff (extends SymbolGroup): %s' % ', '.join(symbol_diff_keys), |
| '', |
| 'Functions: %s' % ', '.join('%s()' % f for f in functions), |