Ejemplo n.º 1
0
    def Run(self):
        """SandwichRunner main entry point meant to be called once configured."""
        assert self.output_dir is not None
        assert self._chrome_ctl == None
        assert self._local_cache_directory_path == None
        self._CleanTraceOutputDirectory()

        if self.android_device:
            self._chrome_ctl = controller.RemoteChromeController(
                self.android_device)
        else:
            self._chrome_ctl = controller.LocalChromeController()
        self._chrome_ctl.AddChromeArguments(self.chrome_args)
        if self.cache_operation == CacheOperation.SAVE:
            self._chrome_ctl.SetSlowDeath()
        try:
            if self.cache_operation == CacheOperation.PUSH:
                assert os.path.isfile(self.cache_archive_path)
                self._local_cache_directory_path = tempfile.mkdtemp(
                    suffix='.cache')
                chrome_cache.UnzipDirectoryContent(
                    self.cache_archive_path, self._local_cache_directory_path)
            times_repeated = self._RunWithWpr(0, False)
            if times_repeated < self.repeat:
                self._chrome_ctl.RebootDevice()
                self._RunWithWpr(times_repeated, True)
        finally:
            if self._local_cache_directory_path:
                shutil.rmtree(self._local_cache_directory_path)
                self._local_cache_directory_path = None
        if self.cache_operation == CacheOperation.SAVE:
            self._PullCacheFromDevice()

        self._chrome_ctl = None
Ejemplo n.º 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')
Ejemplo n.º 3
0
def _LogRequests(url, clear_cache_override=None):
  """Logs requests for a web page.

  Args:
    url: url to log as string.
    clear_cache_override: if not None, set clear_cache different from OPTIONS.

  Returns:
    JSON dict of logged information (ie, a dict that describes JSON).
  """
  if OPTIONS.local:
    chrome_ctl = controller.LocalChromeController()
    chrome_ctl.SetHeadless(OPTIONS.headless)
  else:
    chrome_ctl = controller.RemoteChromeController(
        device_setup.GetFirstDevice())

  clear_cache = (clear_cache_override if clear_cache_override is not None
                 else OPTIONS.clear_cache)
  if OPTIONS.emulate_device:
    chrome_ctl.SetDeviceEmulation(OPTIONS.emulate_device)
  if OPTIONS.emulate_network:
    chrome_ctl.SetNetworkEmulation(OPTIONS.emulate_network)
  with chrome_ctl.Open() as connection:
    if clear_cache:
      connection.ClearCache()
    trace = loading_trace.LoadingTrace.RecordUrlNavigation(
        url, connection, chrome_ctl.ChromeMetadata())
  return trace.ToJsonDict()
Ejemplo n.º 4
0
def _Setup(device):
    """Sets up a device and returns an instance of RemoteChromeController."""
    chrome_controller = controller.RemoteChromeController(device)
    device.ForceStop(OPTIONS.ChromePackage().package)
    chrome_controller.AddChromeArguments(
        ['--speculative-resource-prefetching=learning'])
    chrome_controller.ResetBrowserState()
    return chrome_controller
def Setup(device, additional_flags=None):
  """Sets up a |device| and returns an instance of RemoteChromeController.

  Args:
    device: (Device) As returned by FindDevice().
    additional_flags: ([str] or None) Chrome flags to add.
  """
  if not device.HasRoot():
    device.EnableRoot()
  chrome_controller = controller.RemoteChromeController(device)
  device.ForceStop(OPTIONS.ChromePackage().package)
  if additional_flags is not None:
    chrome_controller.AddChromeArguments(additional_flags)
  chrome_controller.ResetBrowserState()
  return chrome_controller
    def Run(self):
        """SandwichRunner main entry point meant to be called once configured."""
        assert self._chrome_ctl == None
        assert self._local_cache_directory_path == None
        if self.trace_output_directory:
            self._CleanTraceOutputDirectory()

        if self.android_device:
            self._chrome_ctl = controller.RemoteChromeController(
                self.android_device)
        else:
            self._chrome_ctl = controller.LocalChromeController()
        self._chrome_ctl.AddChromeArgument('--disable-infobars')
        if self.cache_operation == 'save':
            self._chrome_ctl.SetSlowDeath()

        if self.cache_operation == 'push':
            assert os.path.isfile(self.cache_archive_path)
            self._local_cache_directory_path = tempfile.mkdtemp(
                suffix='.cache')
            chrome_cache.UnzipDirectoryContent(
                self.cache_archive_path, self._local_cache_directory_path)

        out_log_path = None
        if self.trace_output_directory:
            out_log_path = os.path.join(self.trace_output_directory,
                                        WPR_LOG_FILENAME)

        ran_urls = []
        with self._chrome_ctl.OpenWprHost(
                self.wpr_archive_path,
                record=self.wpr_record,
                network_condition_name=self._GetEmulatorNetworkCondition(
                    'wpr'),
                disable_script_injection=self.disable_wpr_script_injection,
                out_log_path=out_log_path):
            for _ in xrange(self.job_repeat):
                for url in self.urls:
                    self._RunUrl(url, run_id=len(ran_urls))
                    ran_urls.append(url)

        if self._local_cache_directory_path:
            shutil.rmtree(self._local_cache_directory_path)
            self._local_cache_directory_path = None
        if self.cache_operation == 'save':
            self._PullCacheFromDevice()

        self._chrome_ctl = None
Ejemplo n.º 7
0
def _LogRequests(url, clear_cache_override=None):
    """Logs requests for a web page.

  Args:
    url: url to log as string.
    clear_cache_override: if not None, set clear_cache different from OPTIONS.

  Returns:
    JSON dict of logged information (ie, a dict that describes JSON).
  """
    xvfb_process = None
    if OPTIONS.local:
        chrome_ctl = controller.LocalChromeController()
        if OPTIONS.headless:
            xvfb_process = xvfb_helper.LaunchXvfb()
            chrome_ctl.SetChromeEnvOverride(xvfb_helper.GetChromeEnvironment())
    else:
        chrome_ctl = controller.RemoteChromeController(
            device_setup.GetFirstDevice())

    clear_cache = (clear_cache_override if clear_cache_override is not None
                   else OPTIONS.clear_cache)
    if OPTIONS.emulate_device:
        chrome_ctl.SetDeviceEmulation(OPTIONS.emulate_device)
    if OPTIONS.emulate_network:
        chrome_ctl.SetNetworkEmulation(OPTIONS.emulate_network)
    try:
        with chrome_ctl.Open() as connection:
            if clear_cache:
                connection.ClearCache()
            trace = loading_trace.LoadingTrace.RecordUrlNavigation(
                url,
                connection,
                chrome_ctl.ChromeMetadata(),
                categories=clovis_constants.DEFAULT_CATEGORIES)
    except controller.ChromeControllerError as e:
        e.Dump(sys.stderr)
        raise

    if xvfb_process:
        xvfb_process.terminate()

    return trace.ToJsonDict()
Ejemplo n.º 8
0
    def Run(self):
        """SandwichRunner main entry point meant to be called once configured."""
        assert self._chrome_ctl == None
        assert self._local_cache_directory_path == None
        if self.trace_output_directory:
            self._CleanTraceOutputDirectory()

        # TODO(gabadie): Make sandwich working on desktop.
        device = device_utils.DeviceUtils.HealthyDevices()[0]
        self._chrome_ctl = controller.RemoteChromeController(device)
        self._chrome_ctl.AddChromeArgument('--disable-infobars')
        if self.cache_operation == 'save':
            self._chrome_ctl.SetSlowDeath()

        if self.cache_operation == 'push':
            assert os.path.isfile(self.cache_archive_path)
            self._local_cache_directory_path = tempfile.mkdtemp(
                suffix='.cache')
            chrome_cache.UnzipDirectoryContent(
                self.cache_archive_path, self._local_cache_directory_path)

        ran_urls = []
        with self._chrome_ctl.OpenWprHost(
                self.wpr_archive_path,
                record=self.wpr_record,
                network_condition_name=self._GetEmulatorNetworkCondition(
                    'wpr'),
                disable_script_injection=self.disable_wpr_script_injection):
            for _ in xrange(self.job_repeat):
                for url in self.urls:
                    self._RunUrl(url, run_id=len(ran_urls))
                    ran_urls.append(url)

        if self._local_cache_directory_path:
            shutil.rmtree(self._local_cache_directory_path)
            self._local_cache_directory_path = None
        if self.cache_operation == 'save':
            self._PullCacheFromDevice()
        if self.trace_output_directory:
            self._SaveRunInfos(ran_urls)

        self._chrome_ctl = None