tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py
def RunOnce(device, url, speculated_url, parallel_url, warmup,
            skip_launcher_activity, speculation_mode, delay_to_may_launch_url,
            delay_to_launch_url, cold, pinning_benchmark, pin_filename,
            pin_offset, pin_length, extra_brief_memory_mb, chrome_args,
            reset_chrome_state):
  """Runs a test on a device once.

  Args:
    device: (DeviceUtils) device to run the tests on.
    url: (str) URL to load. End of the redirect chain when using a
        parallel request.
    speculated_url: (str) Speculated URL.
    parallel_url: ([str]) URL to load in parallel, typically
        the start of the redirect chain.
    warmup: (bool) Whether to call warmup.
    skip_launcher_activity: (bool) Whether to skip the launcher activity.
    speculation_mode: (str) Speculation Mode.
    delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms.
    delay_to_launch_url: (int) Delay to launchUrl() in ms.
    cold: (bool) Whether the page cache should be dropped.
    pinning_benchmark: (bool) Whether to perform the 'pinning benchmark'.
    pin_filename: (str) The file to pin on the device.
    pin_offset: (int) Start offset of the range to pin.
    pin_length: (int) Number of bytes to pin.
    extra_brief_memory_mb: (int) Number of MiB to consume before starting
        Chrome. Applies only to the 'pinning benchmark' scenario.
    chrome_args: ([str]) List of arguments to pass to Chrome.
    reset_chrome_state: (bool) Whether to reset the Chrome local state before
        the run.

  Returns:
    The output line (str), like this (one line only):
    <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>,
      <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>,
      <first_contentful_paint>
    or None on error.
  """
  if not device.HasRoot():
    device.EnableRoot()

  timeout_s = 64
  logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000.
                       + delay_to_launch_url / 1000.);

  with flag_changer.CustomCommandLineFlags(
      device, _COMMAND_LINE_FILE, chrome_args):
    launch_intent = intent.Intent(
        action='android.intent.action.MAIN',
        package=_TEST_APP_PACKAGE_NAME,
        activity='org.chromium.customtabs.test.MainActivity',
        extras={'url': str(url),
                'speculated_url': str(speculated_url),
                'parallel_url': str (parallel_url),
                'warmup': warmup,
                'skip_launcher_activity': skip_launcher_activity,
                'speculation_mode': str(speculation_mode),
                'delay_to_may_launch_url': delay_to_may_launch_url,
                'delay_to_launch_url': delay_to_launch_url,
                'pinning_benchmark': pinning_benchmark,
                'pin_filename': str(pin_filename),
                'pin_offset': pin_offset,
                'pin_length': pin_length,
                'extra_brief_memory_mb': extra_brief_memory_mb,
                'timeout': timeout_s})
    result_line_re = re.compile(r'CUSTOMTABSBENCHCSV.*: (.*)')
    logcat_monitor = device.GetLogcatMonitor(clear=True)
    logcat_monitor.Start()
    device.ForceStop(_CHROME_PACKAGE)
    device.ForceStop(_ZYGOTE_PACKAGE)
    device.ForceStop(_TEST_APP_PACKAGE_NAME)

    if reset_chrome_state:
      chrome_setup.ResetChromeLocalState(device, _CHROME_PACKAGE)

    if cold:
      cache_control.CacheControl(device).DropRamCaches()

    device.StartActivity(launch_intent, blocking=True)

    match = None
    try:
      match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout)
    except device_errors.CommandTimeoutError as _:
      logging.warning('Timeout waiting for the result line')
    logcat_monitor.Stop()
    logcat_monitor.Close()
    return match.group(1) if match is not None else None
Runs a test on a device once.

  Args:
    device: (DeviceUtils) device to run the tests on.
    url: (str) URL to load. End of the redirect chain when using a
        parallel request.
    speculated_url: (str) Speculated URL.
    parallel_url: ([str]) URL to load in parallel, typically
        the start of the redirect chain.
    warmup: (bool) Whether to call warmup.
    skip_launcher_activity: (bool) Whether to skip the launcher activity.
    speculation_mode: (str) Speculation Mode.
    delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms.
    delay_to_launch_url: (int) Delay to launchUrl() in ms.
    cold: (bool) Whether the page cache should be dropped.
    pinning_benchmark: (bool) Whether to perform the 'pinning benchmark'.
    pin_filename: (str) The file to pin on the device.
    pin_offset: (int) Start offset of the range to pin.
    pin_length: (int) Number of bytes to pin.
    extra_brief_memory_mb: (int) Number of MiB to consume before starting
        Chrome. Applies only to the 'pinning benchmark' scenario.
    chrome_args: ([str]) List of arguments to pass to Chrome.
    reset_chrome_state: (bool) Whether to reset the Chrome local state before
        the run.

  Returns:
    The output line (str), like this (one line only):
    <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>,
      <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>,
      <first_contentful_paint>
    or None on error.
  
Runs a test on a device once.
Runs a test on a device once .
def RunOnce(device, url, speculated_url, parallel_url, warmup,
            skip_launcher_activity, speculation_mode, delay_to_may_launch_url,
            delay_to_launch_url, cold, pinning_benchmark, pin_filename,
            pin_offset, pin_length, extra_brief_memory_mb, chrome_args,
            reset_chrome_state):
  if not device.HasRoot():
    device.EnableRoot()
  timeout_s = 64
  logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000.
                       + delay_to_launch_url / 1000.);
  with flag_changer.CustomCommandLineFlags(
      device, _COMMAND_LINE_FILE, chrome_args):
    launch_intent = intent.Intent(
        action='android.intent.action.MAIN',
        package=_TEST_APP_PACKAGE_NAME,
        activity='org.chromium.customtabs.test.MainActivity',
        extras={'url': str(url),
                'speculated_url': str(speculated_url),
                'parallel_url': str (parallel_url),
                'warmup': warmup,
                'skip_launcher_activity': skip_launcher_activity,
                'speculation_mode': str(speculation_mode),
                'delay_to_may_launch_url': delay_to_may_launch_url,
                'delay_to_launch_url': delay_to_launch_url,
                'pinning_benchmark': pinning_benchmark,
                'pin_filename': str(pin_filename),
                'pin_offset': pin_offset,
                'pin_length': pin_length,
                'extra_brief_memory_mb': extra_brief_memory_mb,
                'timeout': timeout_s})
    result_line_re = re.compile(r'CUSTOMTABSBENCHCSV.*: (.*)')
    logcat_monitor = device.GetLogcatMonitor(clear=True)
    logcat_monitor.Start()
    device.ForceStop(_CHROME_PACKAGE)
    device.ForceStop(_ZYGOTE_PACKAGE)
    device.ForceStop(_TEST_APP_PACKAGE_NAME)
    if reset_chrome_state:
      chrome_setup.ResetChromeLocalState(device, _CHROME_PACKAGE)
    if cold:
      cache_control.CacheControl(device).DropRamCaches()
    device.StartActivity(launch_intent, blocking=True)
    match = None
    try:
      match = logcat_monitor.WaitFor(result_line_re, timeout=logcat_timeout)
    except device_errors.CommandTimeoutError as _:
      logging.warning('Timeout waiting for the result line')
    logcat_monitor.Stop()
    logcat_monitor.Close()
    return match.group(1) if match is not None else None
def RunOnce ( device , url , speculated_url , parallel_url , warmup , skip_launcher_activity , speculation_mode , delay_to_may_launch_url , delay_to_launch_url , cold , pinning_benchmark , pin_filename , pin_offset , pin_length , extra_brief_memory_mb , chrome_args , reset_chrome_state ) : if not device . HasRoot ( ) : device . EnableRoot ( ) timeout_s = 64 logcat_timeout = int ( timeout_s + delay_to_may_launch_url / 1000. + delay_to_launch_url / 1000. ) ; with flag_changer . CustomCommandLineFlags ( device , _COMMAND_LINE_FILE , chrome_args ) : launch_intent = intent . Intent ( action = 'android.intent.action.MAIN' , package = _TEST_APP_PACKAGE_NAME , activity = 'org.chromium.customtabs.test.MainActivity' , extras = { 'url' : str ( url ) , 'speculated_url' : str ( speculated_url ) , 'parallel_url' : str ( parallel_url ) , 'warmup' : warmup , 'skip_launcher_activity' : skip_launcher_activity , 'speculation_mode' : str ( speculation_mode ) , 'delay_to_may_launch_url' : delay_to_may_launch_url , 'delay_to_launch_url' : delay_to_launch_url , 'pinning_benchmark' : pinning_benchmark , 'pin_filename' : str ( pin_filename ) , 'pin_offset' : pin_offset , 'pin_length' : pin_length , 'extra_brief_memory_mb' : extra_brief_memory_mb , 'timeout' : timeout_s } ) result_line_re = re . compile ( r'CUSTOMTABSBENCHCSV.*: (.*)' ) logcat_monitor = device . GetLogcatMonitor ( clear = True ) logcat_monitor . Start ( ) device . ForceStop ( _CHROME_PACKAGE ) device . ForceStop ( _ZYGOTE_PACKAGE ) device . ForceStop ( _TEST_APP_PACKAGE_NAME ) if reset_chrome_state : chrome_setup . ResetChromeLocalState ( device , _CHROME_PACKAGE ) if cold : cache_control . CacheControl ( device ) . DropRamCaches ( ) device . StartActivity ( launch_intent , blocking = True ) match = None try : match = logcat_monitor . WaitFor ( result_line_re , timeout = logcat_timeout ) except device_errors . CommandTimeoutError as _ : logging . warning ( 'Timeout waiting for the result line' ) logcat_monitor . Stop ( ) logcat_monitor . Close ( ) return match . group ( 1 ) if match is not None else None
Runs a test on a device once.
Runs a test on a device once .
"""Runs a test on a device once.

  Args:
    device: (DeviceUtils) device to run the tests on.
    url: (str) URL to load. End of the redirect chain when using a
        parallel request.
    speculated_url: (str) Speculated URL.
    parallel_url: ([str]) URL to load in parallel, typically
        the start of the redirect chain.
    warmup: (bool) Whether to call warmup.
    skip_launcher_activity: (bool) Whether to skip the launcher activity.
    speculation_mode: (str) Speculation Mode.
    delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms.
    delay_to_launch_url: (int) Delay to launchUrl() in ms.
    cold: (bool) Whether the page cache should be dropped.
    pinning_benchmark: (bool) Whether to perform the 'pinning benchmark'.
    pin_filename: (str) The file to pin on the device.
    pin_offset: (int) Start offset of the range to pin.
    pin_length: (int) Number of bytes to pin.
    extra_brief_memory_mb: (int) Number of MiB to consume before starting
        Chrome. Applies only to the 'pinning benchmark' scenario.
    chrome_args: ([str]) List of arguments to pass to Chrome.
    reset_chrome_state: (bool) Whether to reset the Chrome local state before
        the run.

  Returns:
    The output line (str), like this (one line only):
    <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>,
      <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>,
      <first_contentful_paint>
    or None on error.
  """
The output line (str), like this (one line only):
,,,,
,,,

or None on error.
The output line ( str ) like this ( one line only ) : or None on error .
device
(DeviceUtils) device to run the tests on.
( DeviceUtils ) device to run the tests on .
url
(str) URL to load. End of the redirect chain when using a
parallel request.
( str ) URL to load . End of the redirect chain when using a parallel request .
speculated_url
(str) Speculated URL.
( str ) Speculated URL .
parallel_url
([str]) URL to load in parallel, typically
the start of the redirect chain.
( [ str ] ) URL to load in parallel typically the start of the redirect chain .
warmup
(bool) Whether to call warmup.
( bool ) Whether to call warmup .
skip_launcher_activity
(bool) Whether to skip the launcher activity.
( bool ) Whether to skip the launcher activity .
speculation_mode
(str) Speculation Mode.
( str ) Speculation Mode .
delay_to_may_launch_url
(int) Delay to mayLaunchUrl() in ms.
( int ) Delay to mayLaunchUrl () in ms .
delay_to_launch_url
(int) Delay to launchUrl() in ms.
( int ) Delay to launchUrl () in ms .
cold
(bool) Whether the page cache should be dropped.
( bool ) Whether the page cache should be dropped .
pinning_benchmark
(bool) Whether to perform the 'pinning benchmark'.
( bool ) Whether to perform the ' pinning benchmark ' .
pin_filename
(str) The file to pin on the device.
( str ) The file to pin on the device .
pin_offset
(int) Start offset of the range to pin.
( int ) Start offset of the range to pin .
pin_length
(int) Number of bytes to pin.
( int ) Number of bytes to pin .
extra_brief_memory_mb
(int) Number of MiB to consume before starting
Chrome. Applies only to the 'pinning benchmark' scenario.
( int ) Number of MiB to consume before starting Chrome . Applies only to the ' pinning benchmark ' scenario .
chrome_args
([str]) List of arguments to pass to Chrome.
( [ str ] ) List of arguments to pass to Chrome .
reset_chrome_state
(bool) Whether to reset the Chrome local state before
the run.
( bool ) Whether to reset the Chrome local state before the run .