Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 90bc5ac1 authored by Yan Wang's avatar Yan Wang
Browse files

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
parent 7cd8b3fd
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -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)

    if not passed:
      return passed

    return iorapd_utils.disable_iorapd_readahead()

  # Don't need to do anything for warm or cold.
  return True

+4 −0
Original line number Diff line number Diff line
@@ -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)
+25 −0
Original line number Diff line number Diff line
@@ -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
+10 −4
Original line number Diff line number Diff line
@@ -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) .
  """
  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)