Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: tools/binary_size/libsupersize/console.py

Issue 2859383003: FREEZE.unindexed (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/binary_size/libsupersize/archive.py ('k') | tools/binary_size/libsupersize/describe.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/binary_size/libsupersize/console.py
diff --git a/tools/binary_size/libsupersize/console.py b/tools/binary_size/libsupersize/console.py
index 40a8746a186fa1efcc2038d0f7d398bb1c7073ba..f898399489c5045711982576f1bce4a77545eecb 100644
--- a/tools/binary_size/libsupersize/console.py
+++ b/tools/binary_size/libsupersize/console.py
@@ -22,6 +22,7 @@ import file_format
import match_util
import models
import paths
+import precanned_queries
# Number of lines before using less for Print().
@@ -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(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]
+ 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()
print '\n'.join([
'# Show pydoc for main types:',
'import models',
@@ -150,12 +191,12 @@ 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',
- 'generated_syms = size_info.symbols.WhereIsGenerated()',
- 'Print(generated_syms.WhereNameMatches(r"vtable").Inverted())',
+ 'generated_syms = size_info.symbols.WhereGeneratedByToolchain()',
+ 'Print(generated_syms.WhereNameMatches(r"vtable").Inverted().Sorted())',
'',
'# Show all symbols that have "print" in their name or path, except',
'# those within components/.',
@@ -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))',
])
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),
« no previous file with comments | « tools/binary_size/libsupersize/archive.py ('k') | tools/binary_size/libsupersize/describe.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698