| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Collect, archive, and analyze Chrome's binary size.""" | 6 """Collect, archive, and analyze Chrome's binary size.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import atexit | 9 import atexit |
| 10 import collections | 10 import collections |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 def _AddCommonArguments(parser): | 29 def _AddCommonArguments(parser): |
| 30 parser.add_argument('--no-pypy', action='store_true', | 30 parser.add_argument('--no-pypy', action='store_true', |
| 31 help='Do not automatically switch to pypy when available') | 31 help='Do not automatically switch to pypy when available') |
| 32 parser.add_argument('-v', | 32 parser.add_argument('-v', |
| 33 '--verbose', | 33 '--verbose', |
| 34 default=0, | 34 default=0, |
| 35 action='count', | 35 action='count', |
| 36 help='Verbose level (multiple times for more)') | 36 help='Verbose level (multiple times for more)') |
| 37 | 37 |
| 38 | 38 |
| 39 class _DiffAction(object): |
| 40 @staticmethod |
| 41 def AddArguments(parser): |
| 42 parser.add_argument('before', help='Before-patch .size file.') |
| 43 parser.add_argument('after', help='After-patch .size file.') |
| 44 parser.add_argument('--all', action='store_true', help='Verbose diff') |
| 45 |
| 46 @staticmethod |
| 47 def Run(args, parser): |
| 48 args.output_directory = None |
| 49 args.tool_prefix = None |
| 50 args.inputs = [args.before, args.after] |
| 51 args.query = ('Print(Diff(size_info1, size_info2), verbose=%s)' % |
| 52 bool(args.all)) |
| 53 console.Run(args, parser) |
| 54 |
| 55 |
| 39 def main(): | 56 def main(): |
| 40 parser = argparse.ArgumentParser(description=__doc__) | 57 parser = argparse.ArgumentParser(description=__doc__) |
| 41 sub_parsers = parser.add_subparsers() | 58 sub_parsers = parser.add_subparsers() |
| 42 actions = collections.OrderedDict() | 59 actions = collections.OrderedDict() |
| 43 actions['archive'] = (archive, 'Create a .size file') | 60 actions['archive'] = (archive, 'Create a .size file') |
| 44 actions['html_report'] = ( | 61 actions['html_report'] = ( |
| 45 html_report, 'Create a stand-alone html report from a .size file.') | 62 html_report, 'Create a stand-alone html report from a .size file.') |
| 46 actions['console'] = ( | 63 actions['console'] = ( |
| 47 console, | 64 console, |
| 48 'Starts an interactive Python console for analyzing .size files.') | 65 'Starts an interactive Python console for analyzing .size files.') |
| 66 actions['diff'] = ( |
| 67 _DiffAction(), |
| 68 'Shorthand for console --query "Print(Diff(size_info1, size_info2))"') |
| 49 | 69 |
| 50 for name, tup in actions.iteritems(): | 70 for name, tup in actions.iteritems(): |
| 51 sub_parser = sub_parsers.add_parser(name, help=tup[1]) | 71 sub_parser = sub_parsers.add_parser(name, help=tup[1]) |
| 52 _AddCommonArguments(sub_parser) | 72 _AddCommonArguments(sub_parser) |
| 53 tup[0].AddArguments(sub_parser) | 73 tup[0].AddArguments(sub_parser) |
| 54 sub_parser.set_defaults(func=tup[0].Run) | 74 sub_parser.set_defaults(func=tup[0].Run) |
| 55 | 75 |
| 56 if len(sys.argv) == 1: | 76 if len(sys.argv) == 1: |
| 57 parser.print_help() | 77 parser.print_help() |
| 58 sys.exit(1) | 78 sys.exit(1) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 74 logging.warning('This script runs more than 2x faster if you install pypy.') | 94 logging.warning('This script runs more than 2x faster if you install pypy.') |
| 75 | 95 |
| 76 if logging.getLogger().isEnabledFor(logging.DEBUG): | 96 if logging.getLogger().isEnabledFor(logging.DEBUG): |
| 77 atexit.register(_LogPeakRamUsage) | 97 atexit.register(_LogPeakRamUsage) |
| 78 | 98 |
| 79 args.func(args, parser) | 99 args.func(args, parser) |
| 80 | 100 |
| 81 | 101 |
| 82 if __name__ == '__main__': | 102 if __name__ == '__main__': |
| 83 sys.exit(main()) | 103 sys.exit(main()) |
| OLD | NEW |