tools/android/customtabs_benchmark/scripts/customtabs_benchmark.py
def LoopOnDevice(device, configs, output_filename, once=False,
                 should_stop=None):
  """Loops the tests on a device.

  Args:
    device: (DeviceUtils) device to run the tests on.
    configs: ([dict])
    output_filename: (str) Output filename. '-' for stdout.
    once: (bool) Run only once.
    should_stop: (threading.Event or None) When the event is set, stop looping.
  """
  to_stdout = output_filename == '-'
  out = sys.stdout if to_stdout else open(output_filename, 'a')
  try:
    while should_stop is None or not should_stop.is_set():
      config = configs[random.randint(0, len(configs) - 1)]
      chrome_args = chrome_setup.CHROME_ARGS
      if config['speculation_mode'] == 'no_state_prefetch':
        # NoStatePrefetch is enabled through an experiment.
        chrome_args.extend([
            '--force-fieldtrials=trial/group',
            '--force-fieldtrial-params=trial.group:mode/no_state_prefetch',
            '--enable-features=NoStatePrefetch<trial'])
      elif config['speculation_mode'] == 'speculative_prefetch':
        # Speculative Prefetch is enabled through an experiment.
        chrome_args.extend([
            '--force-fieldtrials=trial/group',
            '--force-fieldtrial-params=trial.group:mode/external-prefetching',
            '--enable-features=SpeculativeResourcePrefetching<trial'])

      result = RunOnce(device,
                       config['url'],
                       config.get('speculated_url', config['url']),
                       config.get('parallel_url', ''),
                       config['warmup'],
                       config['skip_launcher_activity'],
                       config['speculation_mode'],
                       config['delay_to_may_launch_url'],
                       config['delay_to_launch_url'],
                       config['cold'],
                       config['pinning_benchmark'],
                       config['pin_filename'],
                       config['pin_offset'],
                       config['pin_length'],
                       config['extra_brief_memory_mb'],
                       chrome_args,
                       reset_chrome_state=True)
      if result is not None:
        out.write(result + '\n')
        out.flush()
      if once:
        return
      if should_stop is not None:
        should_stop.wait(10.)
      else:
        time.sleep(10)
  finally:
    if not to_stdout:
      out.close()
Loops the tests on a device.

  Args:
    device: (DeviceUtils) device to run the tests on.
    configs: ([dict])
    output_filename: (str) Output filename. '-' for stdout.
    once: (bool) Run only once.
    should_stop: (threading.Event or None) When the event is set, stop looping.
  
Loops the tests on a device.
Loops the tests on a device .
def LoopOnDevice(device, configs, output_filename, once=False,
                 should_stop=None):
  to_stdout = output_filename == '-'
  out = sys.stdout if to_stdout else open(output_filename, 'a')
  try:
    while should_stop is None or not should_stop.is_set():
      config = configs[random.randint(0, len(configs) - 1)]
      chrome_args = chrome_setup.CHROME_ARGS
      if config['speculation_mode'] == 'no_state_prefetch':
        chrome_args.extend([
            '--force-fieldtrials=trial/group',
            '--force-fieldtrial-params=trial.group:mode/no_state_prefetch',
            '--enable-features=NoStatePrefetch<trial'])
      elif config['speculation_mode'] == 'speculative_prefetch':
        chrome_args.extend([
            '--force-fieldtrials=trial/group',
            '--force-fieldtrial-params=trial.group:mode/external-prefetching',
            '--enable-features=SpeculativeResourcePrefetching<trial'])
      result = RunOnce(device,
                       config['url'],
                       config.get('speculated_url', config['url']),
                       config.get('parallel_url', ''),
                       config['warmup'],
                       config['skip_launcher_activity'],
                       config['speculation_mode'],
                       config['delay_to_may_launch_url'],
                       config['delay_to_launch_url'],
                       config['cold'],
                       config['pinning_benchmark'],
                       config['pin_filename'],
                       config['pin_offset'],
                       config['pin_length'],
                       config['extra_brief_memory_mb'],
                       chrome_args,
                       reset_chrome_state=True)
      if result is not None:
        out.write(result + '\n')
        out.flush()
      if once:
        return
      if should_stop is not None:
        should_stop.wait(10.)
      else:
        time.sleep(10)
  finally:
    if not to_stdout:
      out.close()
def LoopOnDevice ( device , configs , output_filename , once = False , should_stop = None ) : to_stdout = output_filename == '-' out = sys . stdout if to_stdout else open ( output_filename , 'a' ) try : while should_stop is None or not should_stop . is_set ( ) : config = configs [ random . randint ( 0 , len ( configs ) - 1 ) ] chrome_args = chrome_setup . CHROME_ARGS if config [ 'speculation_mode' ] == 'no_state_prefetch' : chrome_args . extend ( [ '--force-fieldtrials=trial/group' , '--force-fieldtrial-params=trial.group:mode/no_state_prefetch' , '--enable-features=NoStatePrefetch<trial' ] ) elif config [ 'speculation_mode' ] == 'speculative_prefetch' : chrome_args . extend ( [ '--force-fieldtrials=trial/group' , '--force-fieldtrial-params=trial.group:mode/external-prefetching' , '--enable-features=SpeculativeResourcePrefetching<trial' ] ) result = RunOnce ( device , config [ 'url' ] , config . get ( 'speculated_url' , config [ 'url' ] ) , config . get ( 'parallel_url' , '' ) , config [ 'warmup' ] , config [ 'skip_launcher_activity' ] , config [ 'speculation_mode' ] , config [ 'delay_to_may_launch_url' ] , config [ 'delay_to_launch_url' ] , config [ 'cold' ] , config [ 'pinning_benchmark' ] , config [ 'pin_filename' ] , config [ 'pin_offset' ] , config [ 'pin_length' ] , config [ 'extra_brief_memory_mb' ] , chrome_args , reset_chrome_state = True ) if result is not None : out . write ( result + '\n' ) out . flush ( ) if once : return if should_stop is not None : should_stop . wait ( 10. ) else : time . sleep ( 10 ) finally : if not to_stdout : out . close ( )
Loops the tests on a device.
Loops the tests on a device .
"""Loops the tests on a device.

  Args:
    device: (DeviceUtils) device to run the tests on.
    configs: ([dict])
    output_filename: (str) Output filename. '-' for stdout.
    once: (bool) Run only once.
    should_stop: (threading.Event or None) When the event is set, stop looping.
  """ # NoStatePrefetch is enabled through an experiment. # Speculative Prefetch is enabled through an experiment.
device
(DeviceUtils) device to run the tests on.
( DeviceUtils ) device to run the tests on .
configs
None
output_filename
(str) Output filename. '-' for stdout.
( str ) Output filename . ' - ' for stdout .
once
(bool) Run only once.
( bool ) Run only once .
should_stop
(threading.Event or None) When the event is set, stop looping.
( threading . Event or None ) When the event is set stop looping .