summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjbudorick <jbudorick@chromium.org>2015-06-19 11:18:48 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-19 18:19:26 +0000
commit465efd23412d344b5bf72e7dc9401016fa78f1f7 (patch)
treebcd86a9092d2e1b4adc3e237f537456925113c2e
parent0bf5d57ab4527f4046ceab216db69cca181f17cc (diff)
downloadchromium_src-465efd23412d344b5bf72e7dc9401016fa78f1f7.zip
chromium_src-465efd23412d344b5bf72e7dc9401016fa78f1f7.tar.gz
chromium_src-465efd23412d344b5bf72e7dc9401016fa78f1f7.tar.bz2
[Android] Add a java method counting script.
BUG=497911 Review URL: https://codereview.chromium.org/1188253013 Cr-Commit-Position: refs/heads/master@{#335296}
-rwxr-xr-xbuild/android/method_count.py55
-rw-r--r--build/android/pylib/sdk/__init__.py3
-rw-r--r--build/android/pylib/sdk/dexdump.py30
3 files changed, 88 insertions, 0 deletions
diff --git a/build/android/method_count.py b/build/android/method_count.py
new file mode 100755
index 0000000..93250b5
--- /dev/null
+++ b/build/android/method_count.py
@@ -0,0 +1,55 @@
+#! /usr/bin/env python
+# Copyright 2015 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.
+
+import argparse
+import os
+import re
+import sys
+
+from pylib import constants
+from pylib.sdk import dexdump
+
+sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib',
+ 'common'))
+import perf_tests_results_helper
+
+
+_METHOD_IDS_SIZE_RE = re.compile(r'^method_ids_size +: +(\d+)$')
+
+def MethodCount(dexfile):
+ for line in dexdump.DexDump(dexfile, file_summary=True):
+ m = _METHOD_IDS_SIZE_RE.match(line)
+ if m:
+ return m.group(1)
+ raise Exception('"method_ids_size" not found in dex dump of %s' % dexfile)
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ '--apk-name', help='Name of the APK to which the dexfile corresponds.')
+ parser.add_argument('dexfile')
+
+ args = parser.parse_args()
+
+ if not args.apk_name:
+ dirname, basename = os.path.split(args.dexfile)
+ while basename:
+ if 'apk' in basename:
+ args.apk_name = basename
+ break
+ dirname, basename = os.path.split(dirname)
+ else:
+ parser.error(
+ 'Unable to determine apk name from %s, '
+ 'and --apk-name was not provided.' % args.dexfile)
+
+ method_count = MethodCount(args.dexfile)
+ perf_tests_results_helper.PrintPerfResult(
+ '%s_methods' % args.apk_name, 'total', [method_count], 'methods')
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main())
+
diff --git a/build/android/pylib/sdk/__init__.py b/build/android/pylib/sdk/__init__.py
new file mode 100644
index 0000000..50b23df
--- /dev/null
+++ b/build/android/pylib/sdk/__init__.py
@@ -0,0 +1,3 @@
+# Copyright 2015 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.
diff --git a/build/android/pylib/sdk/dexdump.py b/build/android/pylib/sdk/dexdump.py
new file mode 100644
index 0000000..ec10aba
--- /dev/null
+++ b/build/android/pylib/sdk/dexdump.py
@@ -0,0 +1,30 @@
+# Copyright 2015 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.
+
+import os
+
+from pylib import cmd_helper
+from pylib import constants
+
+_DEXDUMP_PATH = os.path.join(constants.ANDROID_SDK_TOOLS, 'dexdump')
+
+def DexDump(dexfiles, file_summary=False):
+ """A wrapper around the Android SDK's dexdump tool.
+
+ Args:
+ dexfiles: The dexfile or list of dex files to dump.
+ file_summary: Display summary information from the file header. (-f)
+
+ Returns:
+ An iterable over the output lines.
+ """
+ # TODO(jbudorick): Add support for more options as necessary.
+ if isinstance(dexfiles, basestring):
+ dexfiles = [dexfiles]
+ args = [_DEXDUMP_PATH] + dexfiles
+ if file_summary:
+ args.append('-f')
+
+ return cmd_helper.IterCmdOutputLines(args)
+