Skip to content

Commit

Permalink
milestone_apk_sizes.py: Use .aab files rather than .apks
Browse files Browse the repository at this point in the history
The stored .apks files no longer contain language splits.

Bug: None
Change-Id: Ia7a21f3e19510080e95926b960a8e0be46f5295d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459697
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815165}
  • Loading branch information
agrieve authored and Commit Bot committed Oct 8, 2020
1 parent d9dbef3 commit e6ea2b4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
5 changes: 5 additions & 0 deletions build/android/gyp/util/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ def CheckOutput(args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, env=env)
stdout, stderr = child.communicate()

# For Python3:
if isinstance(stdout, bytes):
stdout = stdout.decode('utf-8')
stderr = stderr.decode('utf-8')

if stdout_filter is not None:
stdout = stdout_filter(stdout)

Expand Down
2 changes: 1 addition & 1 deletion build/android/gyp/util/md5_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def _ComputeInlineMd5(iterable):
"""Computes the md5 of the concatenated parameters."""
md5 = hashlib.md5()
for item in iterable:
md5.update(str(item))
md5.update(str(item).encode('ascii'))
return md5.hexdigest()


Expand Down
2 changes: 1 addition & 1 deletion build/android/pylib/utils/app_bundle_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def rebuild():
(mode, OPTIMIZE_FOR_OPTIONS))
cmd_args += ['--optimize-for=' + optimize_for]

with tempfile.NamedTemporaryFile(suffix='.json') as spec_file:
with tempfile.NamedTemporaryFile(mode='w', suffix='.json') as spec_file:
if device_spec:
json.dump(device_spec, spec_file)
spec_file.flush()
Expand Down
74 changes: 55 additions & 19 deletions tools/binary_size/milestone_apk_sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

"""Prints the large commits given a .csv file from a telemetry size graph."""

# Our version of pylint doesn't know about python3 yet.
# pylint: disable=unexpected-keyword-arg
import argparse
import collections
import csv
Expand All @@ -19,33 +21,56 @@
import zipfile

_DIR_SOURCE_ROOT = os.path.normpath(
os.path.join(os.path.dirname(__file__), '..', '..'))
os.path.join(os.path.dirname(__file__), '../..'))

_GSUTIL = os.path.join(_DIR_SOURCE_ROOT, 'third_party', 'depot_tools',
'gsutil.py')
_RESOURCE_SIZES = os.path.join(_DIR_SOURCE_ROOT, 'build', 'android',
'resource_sizes.py')
sys.path.insert(1, os.path.join(_DIR_SOURCE_ROOT, 'build/android/pylib'))
from utils import app_bundle_utils

_GSUTIL = os.path.join(_DIR_SOURCE_ROOT, 'third_party/depot_tools/gsutil.py')
_RESOURCE_SIZES = os.path.join(_DIR_SOURCE_ROOT,
'build/android/resource_sizes.py')
_AAPT2 = os.path.join(_DIR_SOURCE_ROOT,
'third_party/android_build_tools/aapt2/aapt2')
_KEYSTORE = os.path.join(_DIR_SOURCE_ROOT,
'build/android/chromium-debug.keystore')
_KEYSTORE_PASSWORD = 'chromium'
_KEYSTORE_ALIAS = 'chromiumdebugkey'


class _Artifact(object):
def __init__(self, prefix, name):
def __init__(self, prefix, name, staging_dir):
self.name = name
self._gs_url = posixpath.join(prefix, name)
self._temp = tempfile.NamedTemporaryFile(suffix=posixpath.basename(name))
self._path = self._temp.name
self._path = os.path.join(staging_dir, name)
self._resource_sizes_json = None

os.makedirs(os.path.dirname(self._path), exist_ok=True)

def FetchAndMeasure(self):
args = [_GSUTIL, 'cp', self._gs_url, self._path]
logging.warning(' '.join(args))
subprocess.check_call(args)
if not os.path.exists(self._path):
subprocess.check_call(args)

path_to_measure = self._path

if self.name.endswith('.aab'):
path_to_measure += '.apks'
app_bundle_utils.GenerateBundleApks(self._path,
path_to_measure,
_AAPT2,
_KEYSTORE,
_KEYSTORE_PASSWORD,
_KEYSTORE_ALIAS,
minimal=True)

args = [
_RESOURCE_SIZES,
'--output-format',
'chartjson',
'--output-file',
'-',
self._path,
path_to_measure,
]
logging.warning(' '.join(args))
self._resource_sizes_json = json.loads(subprocess.check_output(args))
Expand Down Expand Up @@ -90,23 +115,23 @@ def _DumpCsv(metrics):
csv_writer.writerow(metrics)


def _DownloadAndAnalyze(signed_prefix, unsigned_prefix):
def _DownloadAndAnalyze(signed_prefix, unsigned_prefix, staging_dir):
artifacts = []

def make_artifact(name, prefix=signed_prefix):
artifacts.append(_Artifact(prefix, name))
artifacts.append(_Artifact(prefix, name, staging_dir))
return artifacts[-1]

webview = make_artifact('arm/AndroidWebview.apk')
webview64 = make_artifact('arm_64/AndroidWebview.apk')
chrome_modern = make_artifact('arm/ChromeModernStable.apks')
chrome_modern64 = make_artifact('arm_64/ChromeModernStable.apks')
monochrome = make_artifact('arm/MonochromeStable.apks')
monochrome64 = make_artifact('arm_64/MonochromeStable.apks')
trichrome_chrome = make_artifact('arm/TrichromeChromeGoogleStable.apks')
chrome_modern = make_artifact('arm/ChromeModernStable.aab')
chrome_modern64 = make_artifact('arm_64/ChromeModernStable.aab')
monochrome = make_artifact('arm/MonochromeStable.aab')
monochrome64 = make_artifact('arm_64/MonochromeStable.aab')
trichrome_chrome = make_artifact('arm/TrichromeChromeGoogleStable.aab')
trichrome_webview = make_artifact('arm/TrichromeWebViewGoogleStable.apk')
trichrome_library = make_artifact('arm/TrichromeLibraryGoogleStable.apk')
trichrome64_chrome = make_artifact('arm_64/TrichromeChromeGoogleStable.apks')
trichrome64_chrome = make_artifact('arm_64/TrichromeChromeGoogleStable.aab')
trichrome64_webview = make_artifact('arm_64/TrichromeWebViewGoogleStable.apk')
trichrome64_library = make_artifact('arm_64/TrichromeLibraryGoogleStable.apk')

Expand Down Expand Up @@ -182,11 +207,22 @@ def main():
'--signed-bucket',
required=True,
help='GCS bucket to find files in. (e.g. "gs://bucket/subdir")')
parser.add_argument('--keep-files',
action='store_true',
help='Do not delete downloaded files.')
options = parser.parse_args()

signed_prefix = posixpath.join(options.signed_bucket, options.version)
unsigned_prefix = signed_prefix.replace('signed', 'unsigned')
_DownloadAndAnalyze(signed_prefix, unsigned_prefix)
with tempfile.TemporaryDirectory() as staging_dir:
if options.keep_files:
staging_dir = 'milestone_apk_sizes-staging'
os.makedirs(staging_dir, exist_ok=True)

_DownloadAndAnalyze(signed_prefix, unsigned_prefix, staging_dir)

if options.keep_files:
print('Saved files to', staging_dir)


if __name__ == '__main__':
Expand Down

0 comments on commit e6ea2b4

Please sign in to comment.