Make moderate binding testable by command line switches
[chromium-blink-merge.git] / build / android / method_count.py
blob93250b5c542fb28d60574b3ed4ba2e615a53c29b
1 #! /usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import argparse
7 import os
8 import re
9 import sys
11 from pylib import constants
12 from pylib.sdk import dexdump
14 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib',
15 'common'))
16 import perf_tests_results_helper
19 _METHOD_IDS_SIZE_RE = re.compile(r'^method_ids_size +: +(\d+)$')
21 def MethodCount(dexfile):
22 for line in dexdump.DexDump(dexfile, file_summary=True):
23 m = _METHOD_IDS_SIZE_RE.match(line)
24 if m:
25 return m.group(1)
26 raise Exception('"method_ids_size" not found in dex dump of %s' % dexfile)
28 def main():
29 parser = argparse.ArgumentParser()
30 parser.add_argument(
31 '--apk-name', help='Name of the APK to which the dexfile corresponds.')
32 parser.add_argument('dexfile')
34 args = parser.parse_args()
36 if not args.apk_name:
37 dirname, basename = os.path.split(args.dexfile)
38 while basename:
39 if 'apk' in basename:
40 args.apk_name = basename
41 break
42 dirname, basename = os.path.split(dirname)
43 else:
44 parser.error(
45 'Unable to determine apk name from %s, '
46 'and --apk-name was not provided.' % args.dexfile)
48 method_count = MethodCount(args.dexfile)
49 perf_tests_results_helper.PrintPerfResult(
50 '%s_methods' % args.apk_name, 'total', [method_count], 'methods')
51 return 0
53 if __name__ == '__main__':
54 sys.exit(main())