Commit 2011d153 authored by Eric Stevenson's avatar Eric Stevenson Committed by Commit Bot

diagnose_bloat.py: Add static initializer count diff.

This CL makes it possible to verify the addition/removal of static
initializers using diagnose_bloat.py.

Also changes resource_sizes.py to not automatically skip functions
that require a proper output directory to be set when one isn't
(instead of using --no-output-dir).

BUG=None

Change-Id: I061dd3d3624550888458cc97b8d6b8324f7a6183
Reviewed-on: https://chromium-review.googlesource.com/580546
Commit-Queue: Eric Stevenson <estevenson@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488662}
parent b91fa1fd
This diff is collapsed.
......@@ -35,6 +35,8 @@ _DEFAULT_ARCHIVE_DIR = os.path.join(_SRC_ROOT, 'out', 'binary-size-results')
_DEFAULT_OUT_DIR = os.path.join(_SRC_ROOT, 'out', 'binary-size-build')
_DEFAULT_ANDROID_TARGET = 'monochrome_public_apk'
_BINARY_SIZE_DIR = os.path.join(_SRC_ROOT, 'tools', 'binary_size')
_RESOURCE_SIZES_PATH = os.path.join(
_SRC_ROOT, 'build', 'android', 'resource_sizes.py')
_DiffResult = collections.namedtuple('DiffResult', ['name', 'value', 'units'])
......@@ -110,16 +112,13 @@ class NativeDiff(BaseDiff):
class ResourceSizesDiff(BaseDiff):
_RESOURCE_SIZES_PATH = os.path.join(
_SRC_ROOT, 'build', 'android', 'resource_sizes.py')
_SUMMARY_SECTIONS = ('Breakdown', 'Specifics')
_SUMMARY_SECTIONS = ('Breakdown', 'Specifics', 'StaticInitializersCount')
# Sections where it makes sense to sum subsections into a section total.
_AGGREGATE_SECTIONS = (
'InstallBreakdown', 'Breakdown', 'MainLibInfo', 'Uncompressed')
def __init__(self, apk_name, slow_options=False):
def __init__(self, apk_name):
self._apk_name = apk_name
self._slow_options = slow_options
self._diff = None # Set by |ProduceDiff()|
super(ResourceSizesDiff, self).__init__('Resource Sizes Diff')
......@@ -140,8 +139,8 @@ class ResourceSizesDiff(BaseDiff):
include_sections=ResourceSizesDiff._SUMMARY_SECTIONS)
def ProduceDiff(self, before_dir, after_dir):
before = self._RunResourceSizes(before_dir)
after = self._RunResourceSizes(after_dir)
before = self._LoadResults(before_dir)
after = self._LoadResults(after_dir)
self._diff = collections.defaultdict(list)
for section, section_dict in after.iteritems():
for subsection, v in section_dict.iteritems():
......@@ -184,14 +183,8 @@ class ResourceSizesDiff(BaseDiff):
ret = ['Empty ' + self.name]
return ret
def _RunResourceSizes(self, archive_dir):
apk_path = os.path.join(archive_dir, self._apk_name)
def _LoadResults(self, archive_dir):
chartjson_file = os.path.join(archive_dir, 'results-chart.json')
cmd = [self._RESOURCE_SIZES_PATH, apk_path,'--output-dir', archive_dir,
'--no-output-dir', '--chartjson']
if self._slow_options:
cmd += ['--estimate-patch-size', '--dump-static-initializers']
_RunCmd(cmd)
with open(chartjson_file) as f:
chartjson = json.load(f)
return chartjson['charts']
......@@ -319,12 +312,13 @@ class _BuildHelper(object):
class _BuildArchive(object):
"""Class for managing a directory with build results and build metadata."""
def __init__(self, rev, base_archive_dir, build, subrepo):
def __init__(self, rev, base_archive_dir, build, subrepo, slow_options):
self.build = build
self.dir = os.path.join(base_archive_dir, rev)
metadata_path = os.path.join(self.dir, 'metadata.txt')
self.rev = rev
self.metadata = _Metadata([self], build, metadata_path, subrepo)
self._slow_options = slow_options
def ArchiveBuildResults(self, supersize_path):
"""Save build artifacts necessary for diffing."""
......@@ -333,12 +327,22 @@ class _BuildArchive(object):
self._ArchiveFile(self.build.abs_main_lib_path)
if self.build.IsAndroid():
self._ArchiveFile(self.build.abs_apk_path)
self._ArchiveResourceSizes()
self._ArchiveSizeFile(supersize_path)
self.metadata.Write()
def Exists(self):
return self.metadata.Exists()
def _ArchiveResourceSizes(self):
cmd = [_RESOURCE_SIZES_PATH, self.build.abs_apk_path,'--output-dir',
self.dir, '--chartjson']
if not self.build.IsCloud():
cmd += ['--chromium-output-dir', self.build.output_directory]
if self._slow_options:
cmd += ['--estimate-patch-size', '--dump-static-initializers']
_RunCmd(cmd)
def _ArchiveFile(self, filename):
if not os.path.exists(filename):
_Die('missing expected file: %s', filename)
......@@ -366,11 +370,13 @@ class _BuildArchive(object):
class _DiffArchiveManager(object):
"""Class for maintaining BuildArchives and their related diff artifacts."""
def __init__(self, revs, archive_dir, diffs, build, subrepo):
def __init__(self, revs, archive_dir, diffs, build, subrepo, slow_options):
self.archive_dir = archive_dir
self.build = build
self.build_archives = [_BuildArchive(rev, archive_dir, build, subrepo)
for rev in revs]
self.build_archives = [
_BuildArchive(rev, archive_dir, build, subrepo, slow_options)
for rev in revs
]
self.diffs = diffs
self.subrepo = subrepo
self._summary_stats = []
......@@ -811,11 +817,10 @@ def main():
diffs = [NativeDiff(build.size_name, supersize_path)]
if build.IsAndroid():
diffs += [
ResourceSizesDiff(
build.apk_name, slow_options=args.include_slow_options)
ResourceSizesDiff(build.apk_name)
]
diff_mngr = _DiffArchiveManager(
revs, args.archive_directory, diffs, build, subrepo)
diff_mngr = _DiffArchiveManager(revs, args.archive_directory, diffs, build,
subrepo, args.include_slow_options)
consecutive_failures = 0
for i, archive in enumerate(diff_mngr.IterArchives()):
if archive.Exists():
......
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