tools/android/customtabs_benchmark/scripts/run_benchmark.py
def _ParseConfiguration(filename):
  """Reads a JSON file and returns a list of configurations.

  Each valid value in the JSON file can be either a scalar or a list of
  values. This function expands the scalar values to be lists. All list must
  have the same length.

  Sample configuration:
  {
    "url": "https://www.android.com",
    "warmup": [false, true],
    "skip_launcher_activity": true,
    "speculation_mode": "speculative_prefetch",
    "delay_to_may_launch_url": [-1, 1000],
    "delay_to_launch_url": [-1, 1000],
    "cold": true
  }
  See sample_config.json in this directory as well.

  Args:
    filename: (str) Point to a file containins a JSON dictionnary of config
              values.

  Returns:
    A list of configurations, where each value is specified.
  """
  config = json.load(open(filename, 'r'))

  # Set defaults for optional keys.
  config.setdefault('pinning_benchmark', False)
  config.setdefault('pin_filename', '')
  config.setdefault('pin_offset', -1)
  config.setdefault('pin_length', -1)
  config.setdefault('extra_brief_memory_mb', 0)

  has_all_values = all(k in config for k in _KEYS)
  assert has_all_values
  config['url'] = str(config['url'])  # Intents don't like unicode.
  has_list = any(isinstance(config[k], list) for k in _KEYS)
  if not has_list:
    return [config]
  list_keys = [k for k in _KEYS if isinstance(config[k], list)]
  list_length = len(config[list_keys[0]])
  assert all(len(config[k]) == list_length for k in list_keys)
  result = []
  for i in range(list_length):
    result.append(copy.deepcopy(config))
    for k in list_keys:
      result[-1][k] = result[-1][k][i]
  return result
Reads a JSON file and returns a list of configurations.

  Each valid value in the JSON file can be either a scalar or a list of
  values. This function expands the scalar values to be lists. All list must
  have the same length.

  Sample configuration:
  {
    "url": "https://www.android.com",
    "warmup": [false, true],
    "skip_launcher_activity": true,
    "speculation_mode": "speculative_prefetch",
    "delay_to_may_launch_url": [-1, 1000],
    "delay_to_launch_url": [-1, 1000],
    "cold": true
  }
  See sample_config.json in this directory as well.

  Args:
    filename: (str) Point to a file containins a JSON dictionnary of config
              values.

  Returns:
    A list of configurations, where each value is specified.
  
Reads a JSON file and returns a list of configurations.
Each valid value in the JSON file can be either a scalar or a list of
values. This function expands the scalar values to be lists. All list must
have the same length.


Reads a JSON file and returns a list of configurations . Each valid value in the JSON file can be either a scalar or a list of values . This function expands the scalar values to be lists . All list must have the same length .
def _ParseConfiguration(filename):
  config = json.load(open(filename, 'r'))
  config.setdefault('pinning_benchmark', False)
  config.setdefault('pin_filename', '')
  config.setdefault('pin_offset', -1)
  config.setdefault('pin_length', -1)
  config.setdefault('extra_brief_memory_mb', 0)
  has_all_values = all(k in config for k in _KEYS)
  assert has_all_values
  config['url'] = str(config['url'])  
  has_list = any(isinstance(config[k], list) for k in _KEYS)
  if not has_list:
    return [config]
  list_keys = [k for k in _KEYS if isinstance(config[k], list)]
  list_length = len(config[list_keys[0]])
  assert all(len(config[k]) == list_length for k in list_keys)
  result = []
  for i in range(list_length):
    result.append(copy.deepcopy(config))
    for k in list_keys:
      result[-1][k] = result[-1][k][i]
  return result
def _ParseConfiguration ( filename ) : config = json . load ( open ( filename , 'r' ) ) config . setdefault ( 'pinning_benchmark' , False ) config . setdefault ( 'pin_filename' , '' ) config . setdefault ( 'pin_offset' , - 1 ) config . setdefault ( 'pin_length' , - 1 ) config . setdefault ( 'extra_brief_memory_mb' , 0 ) has_all_values = all ( k in config for k in _KEYS ) assert has_all_values config [ 'url' ] = str ( config [ 'url' ] ) has_list = any ( isinstance ( config [ k ] , list ) for k in _KEYS ) if not has_list : return [ config ] list_keys = [ k for k in _KEYS if isinstance ( config [ k ] , list ) ] list_length = len ( config [ list_keys [ 0 ] ] ) assert all ( len ( config [ k ] ) == list_length for k in list_keys ) result = [ ] for i in range ( list_length ) : result . append ( copy . deepcopy ( config ) ) for k in list_keys : result [ - 1 ] [ k ] = result [ - 1 ] [ k ] [ i ] return result
Reads a JSON file and returns a list of configurations.
Reads a JSON file and returns a list of configurations .
"""Reads a JSON file and returns a list of configurations.

  Each valid value in the JSON file can be either a scalar or a list of
  values. This function expands the scalar values to be lists. All list must
  have the same length.

  Sample configuration:
  {
    "url": "https://www.android.com",
    "warmup": [false, true],
    "skip_launcher_activity": true,
    "speculation_mode": "speculative_prefetch",
    "delay_to_may_launch_url": [-1, 1000],
    "delay_to_launch_url": [-1, 1000],
    "cold": true
  }
  See sample_config.json in this directory as well.

  Args:
    filename: (str) Point to a file containins a JSON dictionnary of config
              values.

  Returns:
    A list of configurations, where each value is specified.
  """ # Set defaults for optional keys. # Intents don't like unicode.
A list of configurations, where each value is specified.
A list of configurations where each value is specified .
filename
(str) Point to a file containins a JSON dictionnary of config
values.
( str ) Point to a file containins a JSON dictionnary of config values .