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

Unified Diff: tools/binary_size/helpers.py

Issue 2724253002: V1 of //tools/binary_size rewrite (Closed)
Patch Set: README tweaks, more cases for function parsing Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: tools/binary_size/helpers.py
diff --git a/tools/binary_size/helpers.py b/tools/binary_size/helpers.py
new file mode 100644
index 0000000000000000000000000000000000000000..b0521333d93614fd3bc5c738edcb928de7b592c6
--- /dev/null
+++ b/tools/binary_size/helpers.py
@@ -0,0 +1,45 @@
+# 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."""
+
+import distutils.spawn
+import logging
+import os
+import platform
+import resource
+import sys
+
+
+SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+
+
+def AddCommonOptions(parser):
estevenson 2017/03/20 14:13:03 Could make another helper: args = helper.AddCommon
agrieve 2017/03/20 19:58:09 Like it. Done.
+ parser.add_argument('--no-pypy', action='store_true',
+ help='Do not automatically switch to pypy when available')
+ parser.add_argument('-v',
+ '--verbose',
+ default=0,
+ action='count',
+ help='Verbose level (multiple times for more)')
+
+
+def HandleCommonOptions(args):
+ logging.basicConfig(level=logging.WARNING - args.verbose * 10,
+ format='%(levelname).1s %(relativeCreated)6d %(message)s')
+
+ if not args.no_pypy and platform.python_implementation() == 'CPython':
+ # Switch to pypy if it's available.
+ pypy_path = distutils.spawn.find_executable('pypy')
+ 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
+ logging.warning('This script will run more than 2x as fast if you install '
+ 'pypy.')
+
+def GetPeakRamUsage():
+ peak_ram_usage = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
+ peak_ram_usage += resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss
+ return peak_ram_usage / 1024

Powered by Google App Engine
This is Rietveld 408576698