Exemple #1
0
def main():
    parser = _CreateOptionParser()
    options, args = parser.parse_args()
    if len(args) != 1:
        parser.error("Incorrect number of arguments.")
    devil_chromium.Initialize()
    devices = device_utils.DeviceUtils.HealthyDevices()
    device = devices[0]
    if len(devices) != 1 and options.device is None:
        logging.error(
            'Several devices attached, must specify one with --device.')
        sys.exit(0)
    if options.device is not None:
        matching_devices = [d for d in devices if str(d) == options.device]
        if not matching_devices:
            logging.error('Device not found.')
            sys.exit(0)
        device = matching_devices[0]

    with device_setup.RemoteWprHost(device,
                                    args[0],
                                    options.record,
                                    options.network_condition,
                                    out_log_path=options.wpr_log) as wpr_attr:
        RunChrome(device, options.cold,
                  chrome_setup.CHROME_ARGS + wpr_attr.chrome_args,
                  chrome.PACKAGE_INFO[options.chrome_package_name])
Exemple #2
0
def _RunOnce(device, database_filename, url, prefetch_delay_ms,
             output_filename, wpr_archive, network_condition):
    _Setup(device, database_filename)

    disable_prefetch = prefetch_delay_ms == -1
    # Startup tracing to ease debugging.
    chrome_args = (customtabs_benchmark.CHROME_ARGS +
                   ['--trace-startup', '--trace-startup-duration=20'])

    chrome_controller = controller.RemoteChromeController(device)
    device.ForceStop(OPTIONS.ChromePackage().package)
    chrome_controller.AddChromeArguments(chrome_args)

    with device_setup.RemoteWprHost(
            device,
            wpr_archive,
            record=False,
            network_condition_name=network_condition) as wpr:
        logging.info('WPR arguments: ' + ' '.join(wpr.chrome_args))
        chrome_args += wpr.chrome_args
        prefetch_mode = 'disabled' if disable_prefetch else 'speculative_prefetch'
        result = customtabs_benchmark.RunOnce(
            device,
            url,
            warmup=True,
            speculation_mode=prefetch_mode,
            delay_to_may_launch_url=2000,
            delay_to_launch_url=prefetch_delay_ms,
            cold=False,
            chrome_args=chrome_args,
            reset_chrome_state=False)
    data_point = customtabs_benchmark.ParseResult(result)

    with open(output_filename, 'a') as f:
        f.write(','.join(str(x) for x in data_point) + '\n')
Exemple #3
0
def _GenerateWprArchive(device, url, archive_path):
  with device_setup.RemoteWprHost(device, archive_path, record=True) as wpr:
    chrome_controller = prefetch_predictor_common.Setup(
        device, wpr.chrome_args)
    with chrome_controller.Open() as connection:
      page_track.PageTrack(connection)  # Registers the listeners.
      connection.MonitorUrl(url, timeout_seconds=_PAGE_LOAD_TIMEOUT,
                            stop_delay_multiplier=1.5)
Exemple #4
0
def SetupWpr(device, wpr_archive_path, record, network_condition_name,
             out_log_path):
    """Sets up the WebPageReplay server if needed."""
    if wpr_archive_path or record or network_condition_name or out_log_path:
        return device_setup.RemoteWprHost(device,
                                          wpr_archive_path,
                                          record,
                                          network_condition_name,
                                          out_log_path=out_log_path)
    # WebPageReplay disabled.
    return DummyWprHost()
Exemple #5
0
 def OpenWprHost(self, wpr_archive_path, record=False,
                 network_condition_name=None,
                 disable_script_injection=False,
                 out_log_path=None):
   """Starts a WPR host, overrides Chrome flags until contextmanager exit."""
   assert not self._wpr_attributes, 'WPR is already running.'
   with device_setup.RemoteWprHost(self._device, wpr_archive_path,
       record=record,
       network_condition_name=network_condition_name,
       disable_script_injection=disable_script_injection,
       out_log_path=out_log_path) as wpr_attributes:
     self._wpr_attributes = wpr_attributes
     yield
   self._wpr_attributes = None
Exemple #6
0
 def OpenWprHost(self,
                 wpr_archive_path,
                 record=False,
                 network_condition_name=None,
                 disable_script_injection=False):
     """Starts a WPR host, overrides Chrome flags until contextmanager exit."""
     assert not self._chrome_wpr_specific_args, 'WPR is already running.'
     with device_setup.RemoteWprHost(
             self._device,
             wpr_archive_path,
             record=record,
             network_condition_name=network_condition_name,
             disable_script_injection=disable_script_injection
     ) as additional_flags:
         self._chrome_wpr_specific_args = additional_flags
         yield
     self._chrome_wpr_specific_args = []