summaryrefslogtreecommitdiff
path: root/startop/scripts
diff options
context:
space:
mode:
authorYan Wang <yawanng@google.com>2019-06-28 14:56:41 -0700
committerYan Wang <yawanng@google.com>2019-07-10 16:20:51 -0700
commit90bc5ac1e03c4c99e417e65dca4bcfcd7374757a (patch)
tree4d31cf44c911142f9462504aab4aa1719ba1c21b /startop/scripts
parent7cd8b3fd67ee0639cf801441e62bb6bb67d2052a (diff)
startop: Update to toggle iorapd.readahead.enable.
Test: python run_app_with_prefetch.py -p com.android.settings -a com.android.settings.Settings -r fadvise -i input --debug --simulate Test: python run_app_with_prefetch.py -p com.android.settings -a com.android.settings.Settings -r fadvise -i input Test: pytest run_app_with_prefetch_test.py Bug: 135286022 Change-Id: I4576ebb66bc41124e419681a296a47591f1f3d09
Diffstat (limited to 'startop/scripts')
-rw-r--r--startop/scripts/app_startup/run_app_with_prefetch.py12
-rw-r--r--startop/scripts/app_startup/run_app_with_prefetch_test.py4
-rw-r--r--startop/scripts/iorap/lib/iorapd_utils.py25
-rw-r--r--startop/scripts/lib/cmd_utils.py14
4 files changed, 49 insertions, 6 deletions
diff --git a/startop/scripts/app_startup/run_app_with_prefetch.py b/startop/scripts/app_startup/run_app_with_prefetch.py
index c7970f5c4a67..41cbb2a5571c 100644
--- a/startop/scripts/app_startup/run_app_with_prefetch.py
+++ b/startop/scripts/app_startup/run_app_with_prefetch.py
@@ -228,6 +228,9 @@ def run(readahead: str,
# Drop all caches to get cold starts.
adb_utils.vm_drop_cache()
+ if readahead != 'warm' and readahead != 'cold':
+ iorapd_utils.enable_iorapd_readahead()
+
print_utils.debug_print('Running with timeout {}'.format(timeout))
pre_launch_timestamp = adb_utils.logcat_save_timestamp()
@@ -272,12 +275,17 @@ def perform_post_launch_cleanup(readahead: str,
A bool indicates whether the cleanup succeeds or not.
"""
if readahead != 'warm' and readahead != 'cold':
- return iorapd_utils.wait_for_iorapd_finish(package,
+ passed = iorapd_utils.wait_for_iorapd_finish(package,
activity,
timeout,
debug,
logcat_timestamp)
- return passed
+
+ if not passed:
+ return passed
+
+ return iorapd_utils.disable_iorapd_readahead()
+
# Don't need to do anything for warm or cold.
return True
diff --git a/startop/scripts/app_startup/run_app_with_prefetch_test.py b/startop/scripts/app_startup/run_app_with_prefetch_test.py
index 241aea4943ef..32c39118eeed 100644
--- a/startop/scripts/app_startup/run_app_with_prefetch_test.py
+++ b/startop/scripts/app_startup/run_app_with_prefetch_test.py
@@ -243,6 +243,8 @@ def test_run_with_vm_cache_drop_and_post_launch_cleanup():
debug=False)
calls = [call('adb shell "echo 3 > /proc/sys/vm/drop_caches"'),
+ call('bash -c "source {}; iorapd_readahead_enable"'.
+ format(run.IORAP_COMMON_BASH_SCRIPT)),
call('adb shell "date -u +\'%Y-%m-%d %H:%M:%S.%N\'"'),
call(
'timeout {timeout} "{DIR}/launch_application" "{package}" "{activity}" | '
@@ -262,6 +264,8 @@ def test_run_with_vm_cache_drop_and_post_launch_cleanup():
activity='MainActivity',
timestamp='123:123',
script_path=run.IORAP_COMMON_BASH_SCRIPT)),
+ call('bash -c "source {}; iorapd_readahead_disable"'.
+ format(run.IORAP_COMMON_BASH_SCRIPT)),
call('adb shell ps | grep "music" | awk \'{print $2;}\''),
call('adb shell "kill 9999"')]
mock_run_shell_command.assert_has_calls(calls)
diff --git a/startop/scripts/iorap/lib/iorapd_utils.py b/startop/scripts/iorap/lib/iorapd_utils.py
index f907305f5c61..c03e9b0ae04d 100644
--- a/startop/scripts/iorap/lib/iorapd_utils.py
+++ b/startop/scripts/iorap/lib/iorapd_utils.py
@@ -86,3 +86,28 @@ def wait_for_iorapd_finish(package: str,
[package, activity, logcat_timestamp,
str(timeout)])
return passed
+
+
+def enable_iorapd_readahead() -> bool:
+ """
+ Disable readahead. Subsequent launches of an application will be sped up
+ by iorapd readahead prefetching.
+
+ Returns:
+ A bool indicates whether the enabling is done successfully or not.
+ """
+ passed, _ = cmd_utils.run_shell_func(IORAP_COMMON_BASH_SCRIPT,
+ 'iorapd_readahead_enable', [])
+ return passed
+
+def disable_iorapd_readahead() -> bool:
+ """
+ Disable readahead. Subsequent launches of an application will be not be sped
+ up by iorapd readahead prefetching.
+
+ Returns:
+ A bool indicates whether the disabling is done successfully or not.
+ """
+ passed, _ = cmd_utils.run_shell_func(IORAP_COMMON_BASH_SCRIPT,
+ 'iorapd_readahead_disable', [])
+ return passed
diff --git a/startop/scripts/lib/cmd_utils.py b/startop/scripts/lib/cmd_utils.py
index c3d96059c91c..bc5ca3140d3d 100644
--- a/startop/scripts/lib/cmd_utils.py
+++ b/startop/scripts/lib/cmd_utils.py
@@ -44,10 +44,16 @@ def run_shell_func(script_path: str,
A tuple of running status (True=succeeded, False=failed or timed out) and
std output (string contents of stdout with trailing whitespace removed) .
"""
- cmd = 'bash -c "source {script_path}; {func} {args}"'.format(
- script_path=script_path,
- func=func,
- args=' '.join("'{}'".format(arg) for arg in args))
+ if args:
+ cmd = 'bash -c "source {script_path}; {func} {args}"'.format(
+ script_path=script_path,
+ func=func,
+ args=' '.join("'{}'".format(arg) for arg in args))
+ else:
+ cmd = 'bash -c "source {script_path}; {func}"'.format(
+ script_path=script_path,
+ func=func)
+
print_utils.debug_print(cmd)
return run_shell_command(cmd)