Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: tools/binary_size/helpers.py

Issue 2810813003: Add resource_sizes diffs to diagnose_apk_bloat.py. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Utility methods.""" 5 """Utility methods."""
6 6
7 import atexit 7 import atexit
8 import distutils.spawn 8 import distutils.spawn
9 import logging 9 import logging
10 import os 10 import os
11 import platform 11 import platform
12 import resource 12 import resource
13 import sys 13 import sys
14 14
15 15
16 SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) 16 SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
17 17
18 18
19 def AddCommonOptionsAndParseArgs(parser, argv, pypy_warn=True): 19 def AddCommonOptionsAndParseArgs(parser, argv):
20 parser.add_argument('--no-pypy', action='store_true', 20 parser.add_argument('--no-pypy', action='store_true',
21 help='Do not automatically switch to pypy when available') 21 help='Do not automatically switch to pypy when available')
22 parser.add_argument('-v', 22 parser.add_argument('-v',
23 '--verbose', 23 '--verbose',
24 default=0, 24 default=0,
25 action='count', 25 action='count',
26 help='Verbose level (multiple times for more)') 26 help='Verbose level (multiple times for more)')
27 args = parser.parse_args(argv[1:]) 27 args = parser.parse_args(argv[1:])
28 28
29 logging.basicConfig(level=logging.WARNING - args.verbose * 10, 29 logging.basicConfig(level=logging.WARNING - args.verbose * 10,
30 format='%(levelname).1s %(relativeCreated)6d %(message)s') 30 format='%(levelname).1s %(relativeCreated)6d %(message)s')
31 31
32 if not args.no_pypy and platform.python_implementation() == 'CPython': 32 if not args.no_pypy and platform.python_implementation() == 'CPython':
33 # Switch to pypy if it's available. 33 # Switch to pypy if it's available.
34 pypy_path = distutils.spawn.find_executable('pypy') 34 pypy_path = distutils.spawn.find_executable('pypy')
35 if pypy_path: 35 if pypy_path:
36 logging.debug('Switching to pypy.') 36 logging.debug('Switching to pypy.')
37 os.execv(pypy_path, [pypy_path] + sys.argv) 37 os.execv(pypy_path, [pypy_path] + sys.argv)
38 # NOTE! Running with python: 6s. Running with pypy: 3s 38 # NOTE! Running with python: 6s. Running with pypy: 3s
39 if pypy_warn: 39 logging.warning('This script runs more than 2x faster if you install pypy.')
40 logging.warning(
41 'This script runs more than 2x faster if you install pypy.')
42 40
43 if logging.getLogger().isEnabledFor(logging.DEBUG): 41 if logging.getLogger().isEnabledFor(logging.DEBUG):
44 atexit.register(_LogPeakRamUsage) 42 atexit.register(_LogPeakRamUsage)
45 return args 43 return args
46 44
47 45
48 def _LogPeakRamUsage(): 46 def _LogPeakRamUsage():
49 peak_ram_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss 47 peak_ram_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
50 peak_ram_usage += resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss 48 peak_ram_usage += resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
51 logging.info('Peak RAM usage was %d MB.', peak_ram_usage / 1024) 49 logging.info('Peak RAM usage was %d MB.', peak_ram_usage / 1024)
OLDNEW
« tools/binary_size/diagnose_apk_bloat.py ('K') | « tools/binary_size/diagnose_apk_bloat.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698