Commit 6942d4fa authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

SuperSize: Add per-section symbol counts to console output

Main motivation here is to have dex method counts easy to see.

Change-Id: I51291bc77c233a0c3115b07bc99579ba2489d4eb
Reviewed-on: https://chromium-review.googlesource.com/1226525
Commit-Queue: agrieve <agrieve@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591390}
parent 0c5d1f89
...@@ -61,7 +61,7 @@ def _GetSectionSizeInfo(section_sizes): ...@@ -61,7 +61,7 @@ def _GetSectionSizeInfo(section_sizes):
max_bytes = max(abs(v) for k, v in section_sizes.iteritems() max_bytes = max(abs(v) for k, v in section_sizes.iteritems()
if _IncludeInTotals(k)) if _IncludeInTotals(k))
def is_relevant_section(name, size): def is_significant_section(name, size):
# Show all sections containing symbols, plus relocations. # Show all sections containing symbols, plus relocations.
# As a catch-all, also include any section that comprises > 4% of the # As a catch-all, also include any section that comprises > 4% of the
# largest section. Use largest section rather than total so that it still # largest section. Use largest section rather than total so that it still
...@@ -71,7 +71,7 @@ def _GetSectionSizeInfo(section_sizes): ...@@ -71,7 +71,7 @@ def _GetSectionSizeInfo(section_sizes):
_IncludeInTotals(name) and abs(_Divide(size, max_bytes)) > .04) _IncludeInTotals(name) and abs(_Divide(size, max_bytes)) > .04)
section_names = sorted(k for k, v in section_sizes.iteritems() section_names = sorted(k for k, v in section_sizes.iteritems()
if is_relevant_section(k, v)) if is_significant_section(k, v))
return (total_bytes, section_names) return (total_bytes, section_names)
...@@ -318,12 +318,24 @@ class DescriberText(Describer): ...@@ -318,12 +318,24 @@ class DescriberText(Describer):
for l in self._DescribeSymbolGroupChildren(s, indent=indent + 1): for l in self._DescribeSymbolGroupChildren(s, indent=indent + 1):
yield l yield l
@staticmethod
def _RelevantSections(section_names):
relevant_sections = [
s for s in models.SECTION_TO_SECTION_NAME.itervalues()
if s in section_names]
if models.SECTION_MULTIPLE in relevant_sections:
relevant_sections.remove(models.SECTION_MULTIPLE)
return relevant_sections
def _DescribeSymbolGroup(self, group): def _DescribeSymbolGroup(self, group):
if self.summarize: if self.summarize:
total_size = group.pss total_size = group.pss
section_sizes = collections.defaultdict(float) pss_by_section = collections.defaultdict(float)
counts_by_section = collections.defaultdict(int)
for s in group.IterLeafSymbols(): for s in group.IterLeafSymbols():
section_sizes[s.section_name] += s.pss pss_by_section[s.section_name] += s.pss
if not s.IsDelta() or s.diff_status is not models.DIFF_STATUS_UNCHANGED:
counts_by_section[s.section_name] += 1
# Apply this filter after calcualating size since an alias being removed # Apply this filter after calcualating size since an alias being removed
# causes some symbols to be UNCHANGED, yet have pss != 0. # causes some symbols to be UNCHANGED, yet have pss != 0.
...@@ -346,17 +358,16 @@ class DescriberText(Describer): ...@@ -346,17 +358,16 @@ class DescriberText(Describer):
else: else:
unique_part = '{:,} unique'.format(group.CountUniqueSymbols()) unique_part = '{:,} unique'.format(group.CountUniqueSymbols())
relevant_sections = [ relevant_sections = self._RelevantSections(pss_by_section)
s for s in models.SECTION_TO_SECTION_NAME.itervalues()
if s in section_sizes]
if models.SECTION_MULTIPLE in relevant_sections:
relevant_sections.remove(models.SECTION_MULTIPLE)
size_summary = ' '.join( size_summary = 'Sizes: ' + ' '.join(
'{}={:<10}'.format(k, _PrettySize(int(section_sizes[k]))) '{}={:<10}'.format(k, _PrettySize(int(pss_by_section[k])))
for k in relevant_sections) for k in relevant_sections)
size_summary += ' total={:<10}'.format(_PrettySize(int(total_size))) size_summary += ' total={:<10}'.format(_PrettySize(int(total_size)))
counts_summary = 'Counts: ' + ' '.join(
'{}={}'.format(k, counts_by_section[k]) for k in relevant_sections)
section_legend = ', '.join( section_legend = ', '.join(
'{}={}'.format(models.SECTION_NAME_TO_SECTION[k], k) '{}={}'.format(models.SECTION_NAME_TO_SECTION[k], k)
for k in relevant_sections if k in models.SECTION_NAME_TO_SECTION) for k in relevant_sections if k in models.SECTION_NAME_TO_SECTION)
...@@ -366,6 +377,7 @@ class DescriberText(Describer): ...@@ -366,6 +377,7 @@ class DescriberText(Describer):
len(group), unique_part, int(total_size))], len(group), unique_part, int(total_size))],
histogram.Generate(), histogram.Generate(),
[size_summary.rstrip()], [size_summary.rstrip()],
[counts_summary],
['Number of unique paths: {}'.format(len(unique_paths))], ['Number of unique paths: {}'.format(len(unique_paths))],
[''], [''],
['Section Legend: {}'.format(section_legend)], ['Section Legend: {}'.format(section_legend)],
...@@ -423,30 +435,45 @@ class DescriberText(Describer): ...@@ -423,30 +435,45 @@ class DescriberText(Describer):
def _DescribeDeltaSymbolGroup(self, delta_group): def _DescribeDeltaSymbolGroup(self, delta_group):
if self.summarize: if self.summarize:
header_template = ('{} symbols added (+), {} changed (~), ' num_inc = 0
'{} removed (-), {} unchanged (not shown)') num_dec = 0
# Apply this filter since an alias being removed causes some symbols to be counts_by_section = collections.defaultdict(int)
# UNCHANGED, yet have pss != 0. for sym in delta_group.IterLeafSymbols():
changed_delta_group = delta_group.WhereDiffStatusIs( if sym.pss > 0:
models.DIFF_STATUS_UNCHANGED).Inverted() num_inc += 1
num_inc = sum(1 for s in changed_delta_group if s.pss > 0) elif sym.pss < 0:
num_dec = sum(1 for s in changed_delta_group if s.pss < 0) num_dec += 1
status = sym.diff_status
if status == models.DIFF_STATUS_ADDED:
counts_by_section[sym.section_name] += 1
elif status == models.DIFF_STATUS_REMOVED:
counts_by_section[sym.section_name] -= 1
relevant_sections = self._RelevantSections(counts_by_section)
counts = delta_group.CountsByDiffStatus() counts = delta_group.CountsByDiffStatus()
diff_status_msg = ('{} symbols added (+), {} changed (~), '
'{} removed (-), {} unchanged (not shown)').format(
counts[models.DIFF_STATUS_ADDED],
counts[models.DIFF_STATUS_CHANGED],
counts[models.DIFF_STATUS_REMOVED],
counts[models.DIFF_STATUS_UNCHANGED])
counts_by_section_msg = 'Added/Removed by section: ' + ' '.join(
'{}: {:+}'.format(k, counts_by_section[k]) for k in relevant_sections)
num_unique_before_symbols, num_unique_after_symbols = ( num_unique_before_symbols, num_unique_after_symbols = (
delta_group.CountUniqueSymbols()) delta_group.CountUniqueSymbols())
diff_summary_desc = [ diff_summary_desc = [
header_template.format( diff_status_msg,
counts[models.DIFF_STATUS_ADDED], counts_by_section_msg,
counts[models.DIFF_STATUS_CHANGED],
counts[models.DIFF_STATUS_REMOVED],
counts[models.DIFF_STATUS_UNCHANGED]),
'Of changed symbols, {} grew, {} shrank'.format(num_inc, num_dec), 'Of changed symbols, {} grew, {} shrank'.format(num_inc, num_dec),
'Number of unique symbols {} -> {} ({:+})'.format( 'Number of unique symbols {} -> {} ({:+})'.format(
num_unique_before_symbols, num_unique_after_symbols, num_unique_before_symbols, num_unique_after_symbols,
num_unique_after_symbols - num_unique_before_symbols), num_unique_after_symbols - num_unique_before_symbols),
] ]
path_delta_desc = itertools.chain( path_delta_desc = itertools.chain(
self._DescribeDiffObjectPaths(delta_group), ('',)) self._DescribeDiffObjectPaths(delta_group),
('',))
else: else:
diff_summary_desc = () diff_summary_desc = ()
path_delta_desc = () path_delta_desc = ()
...@@ -558,18 +585,18 @@ class DescriberCsv(Describer): ...@@ -558,18 +585,18 @@ class DescriberCsv(Describer):
return self.stringio.getvalue().rstrip() return self.stringio.getvalue().rstrip()
def _DescribeSectionSizes(self, section_sizes): def _DescribeSectionSizes(self, section_sizes):
relevant_section_names = _GetSectionSizeInfo(section_sizes)[1] significant_section_names = _GetSectionSizeInfo(section_sizes)[1]
if self.verbose: if self.verbose:
relevant_set = set(relevant_section_names) significant_set = set(significant_section_names)
section_names = sorted(section_sizes.iterkeys()) section_names = sorted(section_sizes.iterkeys())
yield self._RenderCsv(['Name', 'Size', 'IsRelevant']) yield self._RenderCsv(['Name', 'Size', 'IsSignificant'])
for name in section_names: for name in section_names:
size = section_sizes[name] size = section_sizes[name]
yield self._RenderCsv([name, size, int(name in relevant_set)]) yield self._RenderCsv([name, size, int(name in significant_set)])
else: else:
yield self._RenderCsv(['Name', 'Size']) yield self._RenderCsv(['Name', 'Size'])
for name in relevant_section_names: for name in significant_section_names:
size = section_sizes[name] size = section_sizes[name]
yield self._RenderCsv([name, size]) yield self._RenderCsv([name, size])
......
...@@ -86,7 +86,8 @@ Histogram of symbols based on PSS: ...@@ -86,7 +86,8 @@ Histogram of symbols based on PSS:
[2,4): 6 [16,32): 10 [128,256): 2 [131072,262144): 2 [1048576,2097152): 2 [2,4): 6 [16,32): 10 [128,256): 2 [131072,262144): 2 [1048576,2097152): 2
[4,8): 6 [32,64): 9 [256,512): 1 [262144,524288): 1 [2097152,4194304): 1 [4,8): 6 [32,64): 9 [256,512): 1 [262144,524288): 1 [2097152,4194304): 1
[8,16): 3 [64,128): 1 [65536,131072): 2 [524288,1048576): 2 [33554432,67108864): 2 [8,16): 3 [64,128): 1 [65536,131072): 2 [524288,1048576): 2 [33554432,67108864): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
......
...@@ -40,6 +40,7 @@ Other section sizes: ...@@ -40,6 +40,7 @@ Other section sizes:
.symtab: 0 bytes (0 bytes) .symtab: 0 bytes (0 bytes)
2 symbols added (+), 2 changed (~), 3 removed (-), 241 unchanged (not shown) 2 symbols added (+), 2 changed (~), 3 removed (-), 241 unchanged (not shown)
Added/Removed by section: .data: +2 .pak.translations: -3
Of changed symbols, 3 grew, 4 shrank Of changed symbols, 3 grew, 4 shrank
Number of unique symbols 251 -> 250 (-1) Number of unique symbols 251 -> 250 (-1)
0 paths added, 0 removed, 2 changed 0 paths added, 0 removed, 2 changed
...@@ -50,7 +51,8 @@ Changed files: ...@@ -50,7 +51,8 @@ Changed files:
Showing 7 symbols (5 -> 4 unique) with total pss: -112 bytes Showing 7 symbols (5 -> 4 unique) with total pss: -112 bytes
Histogram of symbols based on PSS: Histogram of symbols based on PSS:
(-128,-64]: 1 (-32,-16]: 2 (-16,-8]: 1 [4,8): 2 [8,16): 1 (-128,-64]: 1 (-32,-16]: 2 (-16,-8]: 1 [4,8): 2 [8,16): 1
.text=0 bytes .rodata=10 bytes .data.rel.ro=0 bytes .data=8 bytes .bss=0 bytes .pak.translations=-130 bytes total=-112 bytes Sizes: .text=0 bytes .rodata=10 bytes .data.rel.ro=0 bytes .data=8 bytes .bss=0 bytes .pak.translations=-130 bytes total=-112 bytes
Counts: .text=0 .rodata=1 .data.rel.ro=0 .data=2 .bss=0 .pak.translations=4
Number of unique paths: 3 Number of unique paths: 3
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, p=.pak.translations Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, p=.pak.translations
......
...@@ -21,12 +21,14 @@ Section Sizes (Total=0 bytes (0 bytes)): ...@@ -21,12 +21,14 @@ Section Sizes (Total=0 bytes (0 bytes)):
.text: 0 bytes (0 bytes) (0.0%) .text: 0 bytes (0 bytes) (0.0%)
0 symbols added (+), 0 changed (~), 0 removed (-), 50 unchanged (not shown) 0 symbols added (+), 0 changed (~), 0 removed (-), 50 unchanged (not shown)
Added/Removed by section:
Of changed symbols, 0 grew, 0 shrank Of changed symbols, 0 grew, 0 shrank
Number of unique symbols 48 -> 48 (+0) Number of unique symbols 48 -> 48 (+0)
0 paths added, 0 removed, 0 changed 0 paths added, 0 removed, 0 changed
Showing 0 symbols (0 -> 0 unique) with total pss: 0 bytes Showing 0 symbols (0 -> 0 unique) with total pss: 0 bytes
.text=0 bytes .rodata=0 bytes .data.rel.ro=0 bytes .data=0 bytes .bss=0 bytes .other=0 bytes total=0 bytes Sizes: .text=0 bytes .rodata=0 bytes .data.rel.ro=0 bytes .data=0 bytes .bss=0 bytes .other=0 bytes total=0 bytes
Counts: .text=0 .rodata=0 .data.rel.ro=0 .data=0 .bss=0 .other=0
Number of unique paths: 0 Number of unique paths: 0
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
......
...@@ -83,7 +83,8 @@ Histogram of symbols based on PSS: ...@@ -83,7 +83,8 @@ Histogram of symbols based on PSS:
[2,4): 7 [16,32): 10 [128,256): 2 [4096,8192): 1 [262144,524288): 1 [2097152,4194304): 1 [2,4): 7 [16,32): 10 [128,256): 2 [4096,8192): 1 [262144,524288): 1 [2097152,4194304): 1
[4,8): 6 [32,64): 9 [256,512): 1 [65536,131072): 2 [524288,1048576): 2 [33554432,67108864): 2 [4,8): 6 [32,64): 9 [256,512): 1 [65536,131072): 2 [524288,1048576): 2 [33554432,67108864): 2
[8,16): 3 [64,128): 1 [2048,4096): 1 [131072,262144): 2 [1048576,2097152): 2 [8,16): 3 [64,128): 1 [2048,4096): 1 [131072,262144): 2 [1048576,2097152): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
...@@ -265,7 +266,8 @@ Histogram of symbols based on PSS: ...@@ -265,7 +266,8 @@ Histogram of symbols based on PSS:
[2,4): 6 [16,32): 10 [128,256): 2 [131072,262144): 2 [1048576,2097152): 2 [2,4): 6 [16,32): 10 [128,256): 2 [131072,262144): 2 [1048576,2097152): 2
[4,8): 6 [32,64): 9 [256,512): 1 [262144,524288): 1 [2097152,4194304): 1 [4,8): 6 [32,64): 9 [256,512): 1 [262144,524288): 1 [2097152,4194304): 1
[8,16): 3 [64,128): 1 [65536,131072): 2 [524288,1048576): 2 [33554432,67108864): 2 [8,16): 3 [64,128): 1 [65536,131072): 2 [524288,1048576): 2 [33554432,67108864): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
......
...@@ -4,7 +4,8 @@ Histogram of symbols based on PSS: ...@@ -4,7 +4,8 @@ Histogram of symbols based on PSS:
{0}: 6 [8,16): 3 [64,128): 2 [65536,131072): 1 [33554432,67108864): 2 {0}: 6 [8,16): 3 [64,128): 2 [65536,131072): 1 [33554432,67108864): 2
[2,4): 2 [16,32): 9 [128,256): 1 [524288,1048576): 2 [2,4): 2 [16,32): 9 [128,256): 1 [524288,1048576): 2
[4,8): 5 [32,64): 7 [256,512): 1 [1048576,2097152): 2 [4,8): 5 [32,64): 7 [256,512): 1 [1048576,2097152): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
...@@ -58,7 +59,8 @@ Showing 35 symbols (35 unique) with total pss: 77769551 bytes ...@@ -58,7 +59,8 @@ Showing 35 symbols (35 unique) with total pss: 77769551 bytes
Histogram of symbols based on PSS: Histogram of symbols based on PSS:
{0}: 6 [8,16): 4 [32,64): 6 [128,256): 2 [65536,131072): 1 [1048576,2097152): 2 {0}: 6 [8,16): 4 [32,64): 6 [128,256): 2 [65536,131072): 1 [1048576,2097152): 2
[2,4): 2 [16,32): 6 [64,128): 1 [256,512): 1 [524288,1048576): 2 [33554432,67108864): 2 [2,4): 2 [16,32): 6 [64,128): 1 [256,512): 1 [524288,1048576): 2 [33554432,67108864): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
...@@ -105,7 +107,8 @@ Histogram of symbols based on PSS: ...@@ -105,7 +107,8 @@ Histogram of symbols based on PSS:
{0}: 6 [8,16): 4 [64,128): 2 [65536,131072): 1 [33554432,67108864): 2 {0}: 6 [8,16): 4 [64,128): 2 [65536,131072): 1 [33554432,67108864): 2
[2,4): 2 [16,32): 6 [128,256): 1 [524288,1048576): 2 [2,4): 2 [16,32): 6 [128,256): 1 [524288,1048576): 2
[4,8): 1 [32,64): 8 [256,512): 1 [1048576,2097152): 2 [4,8): 1 [32,64): 8 [256,512): 1 [1048576,2097152): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
...@@ -155,7 +158,8 @@ Histogram of symbols based on PSS: ...@@ -155,7 +158,8 @@ Histogram of symbols based on PSS:
[2,4): 2 [16,32): 7 [128,256): 3 [131072,262144): 2 [1048576,2097152): 2 [2,4): 2 [16,32): 7 [128,256): 3 [131072,262144): 2 [1048576,2097152): 2
[4,8): 1 [32,64): 6 [256,512): 1 [262144,524288): 1 [33554432,67108864): 2 [4,8): 1 [32,64): 6 [256,512): 1 [262144,524288): 1 [33554432,67108864): 2
[8,16): 4 [64,128): 1 [65536,131072): 1 [524288,1048576): 2 [8,16): 4 [64,128): 1 [65536,131072): 1 [524288,1048576): 2
.text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb Sizes: .text=34.2mb .rodata=5.65mb .data.rel.ro=1.02mb .data=99.4kb .bss=512kb .other=32.4mb total=74.2mb
Counts: .text=19 .rodata=12 .data.rel.ro=4 .data=6 .bss=6 .other=1
Number of unique paths: 9 Number of unique paths: 9
Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other Section Legend: t=.text, r=.rodata, R=.data.rel.ro, d=.data, b=.bss, o=.other
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment