summaryrefslogtreecommitdiff
path: root/simpleperf
diff options
context:
space:
mode:
authorChris Craik <ccraik@google.com>2017-01-23 16:49:46 -0800
committerChris Craik <ccraik@google.com>2017-01-23 16:50:11 -0800
commit35c99d9ae1d0a602d35a52a76a28fba1964f6dc7 (patch)
tree52e50fc0e932eafe41a4595f9798bc557dbf6937 /simpleperf
parentea69a18cd42bf757d49d733401f4ca6aa3994dc2 (diff)
downloadextras-35c99d9ae1d0a602d35a52a76a28fba1964f6dc7.tar.gz
Add instrumentation test support to app_profiler.py
Bug: 32834638 Test: manual runs of app_profiler.py Change-Id: I9bd3741ffed4f765ddc4cdb7cf56f0772f87ffcb
Diffstat (limited to 'simpleperf')
-rw-r--r--simpleperf/scripts/app_profiler.config18
-rw-r--r--simpleperf/scripts/app_profiler.py26
2 files changed, 28 insertions, 16 deletions
diff --git a/simpleperf/scripts/app_profiler.config b/simpleperf/scripts/app_profiler.config
index f3aebded..4b61edbe 100644
--- a/simpleperf/scripts/app_profiler.config
+++ b/simpleperf/scripts/app_profiler.config
@@ -34,16 +34,18 @@ apk_file_path = ""
recompile_app = True
-# Set to true if we want to restart the app before profiling. Otherwise, set to False.
-restart_app = True
+# If launch_activity is specified, we use `am start -n [app_package_name]/[launch_activity]` to start the app.
+launch_activity = '.MainActivity'
+# If launch_activity is not set, and launch_inst_test is, we launch an instrumentation test:
+# `am instrument -e class [launch_inst_test] [app_package_name]/android.support.test.runner.AndroidJUnitRunner`
+# Generally, will be of the form 'com.example.MyTestClass#myTestMethod'
+launch_inst_test = ''
-if recompile_app and not restart_app:
- raise Exception('[restart_app] is needed for [recompile_app] to take effect.')
-
-# We use `am start -n [app_package_name]/[main_activity]` to start the app.
-main_activity = '.MainActivity'
+if recompile_app and not launch_activity and not launch_inst_test:
+ raise Exception('one of [launch_activity or launch_inst_test] is'
+ + 'needed for [recompile_app] to take effect.')
# Profiling record options that will be passed directly to `simpleperf record` command on device.
@@ -66,4 +68,4 @@ readelf_path = "readelf"
# binary_cache_dir is used to cache binaries pulled from device. To report precisely, we pull each
# binary hit by perf.data on host.
-binary_cache_dir = "binary_cache" \ No newline at end of file
+binary_cache_dir = "binary_cache"
diff --git a/simpleperf/scripts/app_profiler.py b/simpleperf/scripts/app_profiler.py
index e681ecdb..a47f1aaf 100644
--- a/simpleperf/scripts/app_profiler.py
+++ b/simpleperf/scripts/app_profiler.py
@@ -45,7 +45,7 @@ class AppProfiler(object):
def __init__(self, config):
# check config variables
config_names = ['app_package_name', 'native_lib_dir', 'apk_file_path',
- 'recompile_app', 'restart_app', 'main_activity',
+ 'recompile_app', 'launch_activity', 'launch_inst_test',
'record_options', 'perf_data_path', 'adb_path', 'readelf_path',
'binary_cache_dir']
for name in config_names:
@@ -147,20 +147,30 @@ class AppProfiler(object):
def _restart_app(self):
- if not self.config['restart_app']:
+ if not self.config['launch_activity'] and not self.config['launch_inst_test']:
return
+
pid = self._find_app_process()
if pid is not None:
self.run_in_app_dir(['kill', '-9', str(pid)])
time.sleep(1)
- activity = self.config['app_package_name'] + '/' + self.config['main_activity']
- result = self.adb.run(['shell', 'am', 'start', '-n', activity])
- if not result:
- log_fatal("Can't start activity %s" % activity)
+
+ if self.config['launch_activity']:
+ activity = self.config['app_package_name'] + '/' + self.config['launch_activity']
+ result = self.adb.run(['shell', 'am', 'start', '-n', activity])
+ if not result:
+ log_fatal("Can't start activity %s" % activity)
+ else:
+ runner = self.config['app_package_name'] + '/android.support.test.runner.AndroidJUnitRunner'
+ result = self.adb.run(['shell', 'am', 'instrument', '-e', 'class',
+ self.config['launch_inst_test'], runner])
+ if not result:
+ log_fatal("Can't start instrumentation test %s" % self.config['launch_inst_test'])
+
for i in range(10):
pid = self._find_app_process()
if pid is not None:
- return pid
+ return
time.sleep(1)
log_info('Wait for the app process for %d seconds' % (i + 1))
log_fatal("Can't find the app process")
@@ -289,4 +299,4 @@ if __name__ == '__main__':
args = parser.parse_args()
config = load_config(args.config)
profiler = AppProfiler(config)
- profiler.profile() \ No newline at end of file
+ profiler.profile()