| Index: tools/binary_size/libsupersize/main.py
|
| diff --git a/tools/binary_size/helpers.py b/tools/binary_size/libsupersize/main.py
|
| old mode 100644
|
| new mode 100755
|
| similarity index 52%
|
| rename from tools/binary_size/helpers.py
|
| rename to tools/binary_size/libsupersize/main.py
|
| index c82a6ba161947969f8ad128038b34271803fbfc5..4eeb89497332b35b96a7104dff0ca83a317a7e79
|
| --- a/tools/binary_size/helpers.py
|
| +++ b/tools/binary_size/libsupersize/main.py
|
| @@ -1,10 +1,13 @@
|
| +#!/usr/bin/env python
|
| # Copyright 2017 The Chromium Authors. All rights reserved.
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| -"""Utility methods."""
|
| +"""Collect, archive, and analyze Chrome's binary size."""
|
|
|
| +import argparse
|
| import atexit
|
| +import collections
|
| import distutils.spawn
|
| import logging
|
| import os
|
| @@ -12,11 +15,18 @@ import platform
|
| import resource
|
| import sys
|
|
|
| +import archive
|
| +import console
|
| +import html_report
|
|
|
| -SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
|
|
| +def _LogPeakRamUsage():
|
| + peak_ram_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
| + peak_ram_usage += resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
|
| + logging.info('Peak RAM usage was %d MB.', peak_ram_usage / 1024)
|
|
|
| -def AddCommonOptionsAndParseArgs(parser, argv, pypy_warn=True):
|
| +
|
| +def _AddCommonArguments(parser):
|
| parser.add_argument('--no-pypy', action='store_true',
|
| help='Do not automatically switch to pypy when available')
|
| parser.add_argument('-v',
|
| @@ -24,8 +34,33 @@ def AddCommonOptionsAndParseArgs(parser, argv, pypy_warn=True):
|
| default=0,
|
| action='count',
|
| help='Verbose level (multiple times for more)')
|
| - args = parser.parse_args(argv[1:])
|
|
|
| +
|
| +def main():
|
| + parser = argparse.ArgumentParser(description=__doc__)
|
| + sub_parsers = parser.add_subparsers()
|
| + actions = collections.OrderedDict()
|
| + actions['archive'] = (archive, 'Create a .size file')
|
| + actions['html_report'] = (
|
| + html_report, 'Create a stand-alone html report from a .size file.')
|
| + actions['console'] = (
|
| + console,
|
| + 'Starts an interactive Python console for analyzing .size files.')
|
| +
|
| + for name, tup in actions.iteritems():
|
| + sub_parser = sub_parsers.add_parser(name, help=tup[1])
|
| + _AddCommonArguments(sub_parser)
|
| + tup[0].AddArguments(sub_parser)
|
| + sub_parser.set_defaults(func=tup[0].Run)
|
| +
|
| + if len(sys.argv) == 1:
|
| + parser.print_help()
|
| + sys.exit(1)
|
| + elif len(sys.argv) == 2 and sys.argv[1] in actions:
|
| + parser.parse_args(sys.argv[1:] + ['-h'])
|
| + sys.exit(1)
|
| +
|
| + args = parser.parse_args()
|
| logging.basicConfig(level=logging.WARNING - args.verbose * 10,
|
| format='%(levelname).1s %(relativeCreated)6d %(message)s')
|
|
|
| @@ -35,17 +70,14 @@ def AddCommonOptionsAndParseArgs(parser, argv, pypy_warn=True):
|
| if pypy_path:
|
| logging.debug('Switching to pypy.')
|
| os.execv(pypy_path, [pypy_path] + sys.argv)
|
| - # NOTE! Running with python: 6s. Running with pypy: 3s
|
| - if pypy_warn:
|
| - logging.warning(
|
| - 'This script runs more than 2x faster if you install pypy.')
|
| + # Running with python: 6s. Running with pypy: 3s
|
| + logging.warning('This script runs more than 2x faster if you install pypy.')
|
|
|
| if logging.getLogger().isEnabledFor(logging.DEBUG):
|
| atexit.register(_LogPeakRamUsage)
|
| - return args
|
|
|
| + args.func(args, parser)
|
|
|
| -def _LogPeakRamUsage():
|
| - peak_ram_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
| - peak_ram_usage += resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
|
| - logging.info('Peak RAM usage was %d MB.', peak_ram_usage / 1024)
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(main())
|
|
|