Chromium Code Reviews| Index: build/android/resource_sizes.py |
| diff --git a/build/android/resource_sizes.py b/build/android/resource_sizes.py |
| index 976f888a6e877c4133088e783eb1f9f33d4f87f7..467c1a83b19fe1b320cc27499ab89d7caab2c04e 100755 |
| --- a/build/android/resource_sizes.py |
| +++ b/build/android/resource_sizes.py |
| @@ -23,6 +23,7 @@ import tempfile |
| import zipfile |
| import zlib |
| +from binary_size import apk_downloader |
| import devil_chromium |
| from devil.android.sdk import build_tools |
| from devil.utils import cmd_helper |
| @@ -35,6 +36,8 @@ _AAPT_PATH = lazy.WeakConstant(lambda: build_tools.GetPath('aapt')) |
| _GRIT_PATH = os.path.join(host_paths.DIR_SOURCE_ROOT, 'tools', 'grit') |
| _BUILD_UTILS_PATH = os.path.join( |
| host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'gyp') |
| +_APK_PATCH_SIZE_ESTIMATOR_PATH = os.path.join( |
| + host_paths.DIR_SOURCE_ROOT, 'third_party', 'apk-patch-size-estimator') |
| # Prepend the grit module from the source tree so it takes precedence over other |
| # grit versions that might present in the search path. |
| @@ -47,6 +50,9 @@ with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
| with host_paths.SysPath(_BUILD_UTILS_PATH, 1): |
| from util import build_utils # pylint: disable=import-error |
| +with host_paths.SysPath(_APK_PATCH_SIZE_ESTIMATOR_PATH): |
| + import apk_patch_size_estimator as patch_size # pylint: disable=import-error |
|
agrieve
2017/03/20 17:53:40
nit: you have a double space in here, although eve
estevenson
2017/03/20 18:02:37
Done.
|
| + |
| # Python had a bug in zipinfo parsing that triggers on ChromeModern.apk |
| # https://bugs.python.org/issue14315 |
| @@ -674,6 +680,24 @@ def _PrintDexAnalysis(apk_filename, chartjson=None): |
| 'bytes') |
| +def _PrintPatchSizeEstimate(new_apk, builder, bucket, chartjson=None): |
| + apk_name = os.path.basename(new_apk) |
| + title = apk_name + '_PatchSizeEstimate' |
| + # Reference APK paths have spaces replaced by underscores. |
| + builder = builder.replace(' ', '_') |
| + old_apk = apk_downloader.MaybeDownloadApk( |
| + builder, apk_downloader.CURRENT_MILESTONE, apk_name, |
| + apk_downloader.DEFAULT_DOWNLOAD_PATH, bucket) |
| + if old_apk: |
| + # Use a temp dir in case patch size functions fail to clean up temp files. |
| + with build_utils.TempDir() as tmp: |
| + tmp_name = os.path.join(tmp, 'patch.tmp') |
| + bsdiff = patch_size.calculate_bsdiff(old_apk, new_apk, None, tmp_name) |
| + ReportPerfResult(chartjson, title, 'BSDiff (gzipped)', bsdiff, 'bytes') |
| + fbf = patch_size.calculate_filebyfile(old_apk, new_apk, None, tmp_name) |
| + ReportPerfResult(chartjson, title, 'FileByFile (gzipped)', fbf, 'bytes') |
| + |
| + |
| @contextmanager |
| def Unzip(zip_file, filename=None): |
| """Utility for temporary use of a single file in a zip archive.""" |
| @@ -712,6 +736,15 @@ def main(): |
| 'output-dir') |
| argparser.add_argument('-d', '--device', |
| help='Dummy option for perf runner.') |
| + argparser.add_argument('--estimate-patch-size', action='store_true', |
| + help='Include patch size estimates. Useful for perf ' |
| + 'builders where a reference APK is available but adds ' |
| + '~3 mins to run time.') |
| + argparser.add_argument('--builder', default=apk_downloader.DEFAULT_BUILDER, |
| + help='Builder name to use for reference APK for patch ' |
| + 'size estimates.') |
| + argparser.add_argument('--bucket', default=apk_downloader.DEFAULT_BUCKET, |
|
agrieve
2017/03/20 17:53:40
name bikeshed: how about --reference-apk-bucket an
estevenson
2017/03/20 18:02:36
Done.
|
| + help='Storage bucket holding reference APKs.') |
| argparser.add_argument('apk', help='APK file path.') |
| args = argparser.parse_args() |
| @@ -729,6 +762,9 @@ def main(): |
| PrintApkAnalysis(args.apk, tools_prefix, chartjson=chartjson) |
| _PrintDexAnalysis(args.apk, chartjson=chartjson) |
| + if args.estimate_patch_size: |
| + _PrintPatchSizeEstimate( |
| + args.apk, args.builder, args.bucket, chartjson=chartjson) |
| if not args.no_output_dir: |
| PrintPakAnalysis(args.apk, args.min_pak_resource_size) |
| _PrintStaticInitializersCountFromApk( |