0

[SuperSize] Move APK size from metadata to metrics.

As a follow-up to crrev.com/c/4526895, this CL moves the .size/.sizediff
metadata item "apk_size" to metrics item "SIZE/APK File" under each APK
file. Now sizes of APK files are listed in one table in the Viewer.

Note that in the Viewer, the .apk extension is unrecognized by
MetricsTreeModel.makeMetricNode(), so the Metrics Tree node is
Metrics -> Size -> OTHER: APK File, using the "other" fallback icon.

Bug: 1408775
Change-Id: I8fe14d2375ba4b042a0d00f424ddb817e0059b8c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4532518
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1144123}
This commit is contained in:
Samuel Huang
2023-05-15 15:30:46 +00:00
committed by Chromium LUCI CQ
parent 0ac501751e
commit d23b13fbb1
6 changed files with 12 additions and 11 deletions

@ -155,7 +155,6 @@ def CreateMetadata(apk_spec, include_file_details, shorten_path):
logging.debug('Constructing APK metadata')
apk_metadata = {}
if include_file_details:
apk_metadata[models.METADATA_APK_SIZE] = os.path.getsize(apk_spec.apk_path)
if apk_spec.mapping_path:
apk_metadata[models.METADATA_PROGUARD_MAPPING_FILENAME] = shorten_path(
apk_spec.mapping_path)
@ -172,7 +171,7 @@ def CreateApkOtherSymbols(apk_spec):
"""Creates symbols for resources / assets within the apk.
Returns:
A tuple of (section_ranges, raw_symbols, apk_metadata).
A tuple of (section_ranges, raw_symbols, apk_metadata, apk_metrics_by_file).
"""
logging.info('Creating symbols for other APK entries')
res_source_mapper = _ResourceSourceMapper(apk_spec.size_info_prefix,
@ -219,6 +218,12 @@ def CreateApkOtherSymbols(apk_spec):
models.METADATA_SIGNING_BLOCK_SIZE: signing_block_size,
}
apk_metrics_by_file = {}
apk_metrics_by_file[posixpath.basename(apk_spec.apk_path)] = {
f'{models.METRICS_SIZE}/{models.METRICS_SIZE_APK_FILE}':
os.path.getsize(apk_spec.apk_path),
}
# Overhead includes:
# * Size of all local zip headers (minus zipalign padding).
# * Size of central directory & end of central directory.
@ -234,4 +239,4 @@ def CreateApkOtherSymbols(apk_spec):
archive_util.ExtendSectionRange(section_ranges, models.SECTION_OTHER,
sum(s.size for s in raw_symbols))
file_format.SortSymbols(raw_symbols)
return section_ranges, raw_symbols, apk_metadata
return section_ranges, raw_symbols, apk_metadata, apk_metrics_by_file

@ -405,9 +405,10 @@ def _CreateContainerSymbols(container_spec, apk_file_manager,
add_syms(arsc_section_ranges, arsc_symbols)
metrics_by_file.update(arsc_metrics_by_file)
other_section_ranges, other_symbols, apk_metadata = (
other_section_ranges, other_symbols, apk_metadata, apk_metrics_by_file = (
apk.CreateApkOtherSymbols(apk_spec))
add_syms(other_section_ranges, other_symbols)
metrics_by_file.update(apk_metrics_by_file)
metadata = _CreateMetadata(container_spec, elf_info)
assert not (metadata.keys() & apk_metadata.keys())

@ -24,9 +24,9 @@ BUILD_CONFIG_OUT_DIRECTORY = 'out_directory'
METRICS_COUNT = 'COUNT'
METRICS_COUNT_RELOCATIONS = 'Relocations'
METRICS_SIZE = 'SIZE'
METRICS_SIZE_APK_FILE = 'APK File'
METADATA_APK_FILENAME = 'apk_file_name' # Path relative to output_directory.
METADATA_APK_SIZE = 'apk_size' # File size of apk in bytes.
METADATA_APK_SPLIT_NAME = 'apk_split_name' # Name of the split if applicable.
METADATA_ZIPALIGN_OVERHEAD = 'zipalign_padding' # Overhead from zipalign.
METADATA_SIGNING_BLOCK_SIZE = 'apk_signature_block_size' # Size in bytes.

@ -28,7 +28,6 @@ elf_build_id=WhatAnAmazingBuildId
Container1:
apk_file_name=test.apk
apk_signature_block_size=0
apk_size=139472373
zipalign_padding=32
Symbols:
<Container1:/test.so (armeabi-v7a)>.text@28d900(size_without_padding=16,padding=0,full_name=_GLOBAL__sub_I_page_allocator.cc,object_path=base/base/page_allocator.o,source_path=base/page_allocator.cc,flags={startup},num_aliases=1,component=Blink>Internal)
@ -450,3 +449,4 @@ elf={'COUNT/Relocations': 394087, 'SIZE/.ARM.attributes': 60, 'SIZE/.ARM.exidx':
Container1:/smalltest.so (x86)
Container1:
classes.dex={'COUNT/ANNOTATION': 1, 'COUNT/ANNOTATIONS_DIRECTORY': 1, 'COUNT/ANNOTATION_SET': 2, 'COUNT/CLASS_DATA': 2, 'COUNT/CLASS_DEF': 2, 'COUNT/CODE': 8, 'COUNT/DEBUG_INFO': 8, 'COUNT/ENCODED_ARRAY': 1, 'COUNT/FIELD_ID': 2, 'COUNT/HEADER': 1, 'COUNT/MAP': 1, 'COUNT/METHOD_ID': 14, 'COUNT/PROTO_ID': 10, 'COUNT/STRING_DATA': 40, 'COUNT/STRING_ID': 40, 'COUNT/TYPE': 6, 'COUNT/TYPE_ID': 13, 'SIZE/ANNOTATION': 8, 'SIZE/ANNOTATIONS_DIRECTORY': 24, 'SIZE/ANNOTATION_SET': 12, 'SIZE/CLASS_DATA': 48, 'SIZE/CLASS_DEF': 64, 'SIZE/CODE': 432, 'SIZE/DEBUG_INFO': 72, 'SIZE/ENCODED_ARRAY': 4, 'SIZE/FIELD_ID': 16, 'SIZE/HEADER': 112, 'SIZE/MAP': 208, 'SIZE/METHOD_ID': 112, 'SIZE/PROTO_ID': 120, 'SIZE/STRING_DATA': 522, 'SIZE/STRING_ID': 160, 'SIZE/TYPE': 50, 'SIZE/TYPE_ID': 52}
test.apk={'SIZE/APK File': 139472373}

@ -16,7 +16,6 @@ elf_arch=arm
elf_build_id=WhatAnAmazingBuildId
apk_file_name=test.apk
apk_signature_block_size=0
apk_size=139472373
zipalign_padding=32
Container <test.apk/test.so (armeabi-v7a)>
Section .arsc: 0 bytes from 0 symbols.

@ -18,22 +18,18 @@ elf_arch=arm
elf_build_id=WhatAnAmazingBuildId
apk_file_name=Bundle.minimal.apks
apk_signature_block_size=0
apk_size=696
apk_split_name=base-hi
zipalign_padding=0
apk_file_name=Bundle.minimal.apks
apk_signature_block_size=0
apk_size=139472373
apk_split_name=base
zipalign_padding=32
apk_file_name=Bundle.minimal.apks
apk_signature_block_size=0
apk_size=696
apk_split_name=not_on_demand
zipalign_padding=0
apk_file_name=Bundle.minimal.apks
apk_signature_block_size=0
apk_size=695
apk_split_name=on_demand
zipalign_padding=0
Container <Bundle.minimal.apks/base.apk/test.so (armeabi-v7a)>