def testEnsureHotAfterColdAndWarmRun(self):
        with self.CaptureTrace():
            story_set = story.StorySet()
            page = page_module.Page(_TEST_URL,
                                    page_set=story_set,
                                    cache_temperature=cache_temperature.COLD,
                                    name=_TEST_URL)
            cache_temperature.EnsurePageCacheTemperature(page, self._browser)

            previous_page = page
            page = page_module.Page(_TEST_URL,
                                    page_set=story_set,
                                    cache_temperature=cache_temperature.WARM,
                                    name=_TEST_URL)
            cache_temperature.EnsurePageCacheTemperature(
                page, self._browser, previous_page)

            previous_page = page
            page = page_module.Page(_TEST_URL,
                                    page_set=story_set,
                                    cache_temperature=cache_temperature.HOT,
                                    name=_TEST_URL)
            cache_temperature.EnsurePageCacheTemperature(
                page, self._browser, previous_page)

        markers = self.CollectTraceMarkers()
        self.assertNotIn('telemetry.internal.warm_cache.warm.start', markers)
        self.assertNotIn('telemetry.internal.warm_cache.warm.end', markers)
        self.assertNotIn('telemetry.internal.warm_cache.hot.start', markers)
        self.assertNotIn('telemetry.internal.warm_cache.hot.end', markers)
  def testEnsurePCv1WarmAfterPCv1ColdRun(self):
    with self.captureTrace():
      story_set = story.StorySet()
      page = page_module.Page('http://google.com', page_set=story_set,
          cache_temperature=cache_temperature.PCV1_COLD, name='http://google.com')
      cache_temperature.EnsurePageCacheTemperature(page, self._browser)

      previous_page = page
      page = page_module.Page('http://google.com', page_set=story_set,
          cache_temperature=cache_temperature.PCV1_WARM, name='http://google.com')
      cache_temperature.EnsurePageCacheTemperature(page, self._browser,
          previous_page)

    markers = self.traceMarkers()
    self.assertNotIn('telemetry.internal.warmCache.start', markers)
Ejemplo n.º 3
0
  def WillRunStory(self, page):
    if not self.platform.tracing_controller.is_tracing_running:
      # For TimelineBasedMeasurement benchmarks, tracing has already started.
      # For PageTest benchmarks, tracing has not yet started. We need to make
      # sure no tracing state is left before starting the browser for PageTest
      # benchmarks.
      self.platform.tracing_controller.ClearStateIfNeeded()

    page_set = page.page_set
    self._current_page = page

    started_browser = not self.browser

    archive_path = page_set.WprFilePathForStory(page, self.platform.GetOSName())
    # TODO(nednguyen, perezju): Ideally we should just let the network
    # controller raise an exception when the archive_path is not found.
    if archive_path is not None and not os.path.isfile(archive_path):
      logging.warning('WPR archive missing: %s', archive_path)
      archive_path = None
    self.platform.network_controller.StartReplay(
        archive_path, page.make_javascript_deterministic, self._extra_wpr_args)

    if not self.browser:
      self._StartBrowser(page)
    if self.browser.supports_tab_control:
      # Create a tab if there's none.
      if len(self.browser.tabs) == 0:
        self.browser.tabs.New()

      # Ensure only one tab is open.
      while len(self.browser.tabs) > 1:
        self.browser.tabs[-1].Close()

      # If we didn't start the browser, then there is a single tab left from the
      # previous story. The tab may have some state that may effect the next
      # story. Close it to reset the state. Tab.Close(), when there is only one
      # tab left, creates a new tab and closes the old tab.
      if not started_browser:
        self.browser.tabs[-1].Close()

      # Must wait for tab to commit otherwise it can commit after the next
      # navigation has begun and RenderFrameHostManager::DidNavigateMainFrame()
      # will cancel the next navigation because it's pending. This manifests as
      # the first navigation in a PageSet freezing indefinitely because the
      # navigation was silently canceled when |self.browser.tabs[0]| was
      # committed.
      self.browser.tabs[0].WaitForDocumentReadyStateToBeComplete()

    # Reset traffic shaping to speed up cache temperature setup.
    self.platform.network_controller.UpdateTrafficSettings(0, 0, 0)
    cache_temperature.EnsurePageCacheTemperature(
        self._current_page, self.browser, self._previous_page)
    if self._current_page.traffic_setting != traffic_setting.NONE:
      s = traffic_setting.NETWORK_CONFIGS[self._current_page.traffic_setting]
      self.platform.network_controller.UpdateTrafficSettings(
          round_trip_latency_ms=s.round_trip_latency_ms,
          download_bandwidth_kbps=s.download_bandwidth_kbps,
          upload_bandwidth_kbps=s.upload_bandwidth_kbps)

    self._AllowInteractionForStage('before-run-story')
Ejemplo n.º 4
0
    def WillRunStory(self, page):
        if not self.platform.tracing_controller.is_tracing_running:
            # For TimelineBasedMeasurement benchmarks, tracing has already started.
            # For PageTest benchmarks, tracing has not yet started. We need to make
            # sure no tracing state is left before starting the browser for PageTest
            # benchmarks.
            self.platform.tracing_controller.ClearStateIfNeeded()

        self._current_page = page

        archive_path = page.story_set.WprFilePathForStory(
            page, self.platform.GetOSName())
        # TODO(crbug.com/1029785): Ideally we should just let the network
        # controller raise an exception when the archive_path is not found.
        if archive_path is not None and not os.path.isfile(archive_path):
            logging.warning('WPR archive missing: %s', archive_path)
            archive_path = None
        self.platform.network_controller.StartReplay(
            archive_path, page.make_javascript_deterministic,
            self._extra_wpr_args)

        reusing_browser = self.browser is not None
        if not reusing_browser:
            self._StartBrowser(page)

        if self.browser.supports_tab_control:
            if reusing_browser:
                # Try to close all previous tabs to maintain some independence between
                # individual story runs. Note that the final tab.Close(keep_one=True)
                # will create a fresh new tab before the last one is closed.
                while len(self.browser.tabs) > 1:
                    self.browser.tabs[-1].Close()
                self.browser.tabs[-1].Close(keep_one=True)
            else:
                # Create a tab if there's none.
                if len(self.browser.tabs) == 0:
                    self.browser.tabs.New()

            # Must wait for tab to commit otherwise it can commit after the next
            # navigation has begun and RenderFrameHostManager::DidNavigateMainFrame()
            # will cancel the next navigation because it's pending. This manifests as
            # the first navigation in a PageSet freezing indefinitely because the
            # navigation was silently canceled when |self.browser.tabs[0]| was
            # committed.
            self.browser.tabs[0].WaitForDocumentReadyStateToBeComplete()

        # Reset traffic shaping to speed up cache temperature setup.
        self.platform.network_controller.UpdateTrafficSettings(0, 0, 0)
        cache_temperature.EnsurePageCacheTemperature(self._current_page,
                                                     self.browser)
        if self._current_page.traffic_setting != traffic_setting.NONE:
            s = traffic_setting.NETWORK_CONFIGS[
                self._current_page.traffic_setting]
            self.platform.network_controller.UpdateTrafficSettings(
                round_trip_latency_ms=s.round_trip_latency_ms,
                download_bandwidth_kbps=s.download_bandwidth_kbps,
                upload_bandwidth_kbps=s.upload_bandwidth_kbps)

        self._AllowInteractionForStage('before-run-story')
  def testEnsurePCv1WarmFromScratch(self):
    with self.captureTrace():
      story_set = story.StorySet()
      page = page_module.Page('http://google.com', page_set=story_set,
          cache_temperature=cache_temperature.PCV1_WARM, name='http://google.com')
      cache_temperature.EnsurePageCacheTemperature(page, self._browser)

    markers = self.traceMarkers()
    self.assertIn('telemetry.internal.warmCache.start', markers)
    self.assertIn('telemetry.internal.warmCache.end', markers)
  def testEnsureAny(self):
    with self.captureTrace():
      story_set = story.StorySet()
      page = page_module.Page('http://google.com', page_set=story_set,
          cache_temperature=cache_temperature.ANY, name='http://google.com')
      cache_temperature.EnsurePageCacheTemperature(page, self._browser)

    markers = self.traceMarkers()
    self.assertNotIn('telemetry.internal.ensure_diskcache.start', markers)
    self.assertNotIn('telemetry.internal.warmCache.start', markers)
Ejemplo n.º 7
0
    def testEnsureWarmFromScratch(self):
        with self.CaptureTraceMarkers():
            story_set = story.StorySet()
            page = page_module.Page(_TEST_URL,
                                    page_set=story_set,
                                    cache_temperature=cache_temperature.WARM,
                                    name=_TEST_URL)
            cache_temperature.EnsurePageCacheTemperature(page, self._browser)

        self.assertIn('telemetry.internal.warm_cache.warm.start', self.markers)
        self.assertIn('telemetry.internal.warm_cache.warm.end', self.markers)
  def testEnsureCold(self):
    with self.CaptureTrace():
      story_set = story.StorySet()
      page = page_module.Page(
          _TEST_URL, page_set=story_set,
          cache_temperature=cache_temperature.COLD, name=_TEST_URL)
      cache_temperature.EnsurePageCacheTemperature(page, self._browser)

    markers = self.CollectTraceMarkers()
    self.assertIn('telemetry.internal.ensure_diskcache.start', markers)
    self.assertIn('telemetry.internal.ensure_diskcache.end', markers)
  def testEnsureHotAfterColdRun(self):
    with self.CaptureTrace():
      story_set = story.StorySet()
      page = page_module.Page(
          _TEST_URL, page_set=story_set,
          cache_temperature=cache_temperature.COLD, name=_TEST_URL)
      cache_temperature.EnsurePageCacheTemperature(page, self._browser)

      previous_page = page
      page = page_module.Page(
          _TEST_URL, page_set=story_set,
          cache_temperature=cache_temperature.HOT, name=_TEST_URL)
      cache_temperature.EnsurePageCacheTemperature(
          page, self._browser, previous_page)

    markers = self.CollectTraceMarkers()
    # After navigation for another origin url, traces in previous origin page
    # does not appear in |markers|, so we can not check this:
    # self.assertIn('telemetry.internal.warm_cache.hot.start', markers)
    # TODO: Ensure all traces are in |markers|
    self.assertIn('telemetry.internal.warm_cache.hot.end', markers)
    def testEnsureHotBrowser(self):
        with self.CaptureTrace():
            story_set = story.StorySet()
            page = page_module.Page(
                _TEST_URL,
                page_set=story_set,
                cache_temperature=cache_temperature.HOT_BROWSER,
                name=_TEST_URL)
            cache_temperature.EnsurePageCacheTemperature(page, self._browser)

        markers = self.CollectTraceMarkers()
        # Browser cache warming happens in a different tab so markers shouldn't
        # appear.
        self.assertNotIn('telemetry.internal.warm_cache.warm.start', markers)
        self.assertNotIn('telemetry.internal.warm_cache.warm.end', markers)
        self.assertNotIn('telemetry.internal.warm_cache.hot.start', markers)
        self.assertNotIn('telemetry.internal.warm_cache.hot.end', markers)
Ejemplo n.º 11
0
    def testEnsureAny(self):
        with self.CaptureTraceMarkers():
            story_set = story.StorySet()
            page = page_module.Page(_TEST_URL,
                                    page_set=story_set,
                                    cache_temperature=cache_temperature.ANY,
                                    name=_TEST_URL)
            cache_temperature.EnsurePageCacheTemperature(page, self._browser)

        self.assertNotIn('telemetry.internal.ensure_diskcache.start',
                         self.markers)
        self.assertNotIn('telemetry.internal.warm_cache.warm.start',
                         self.markers)
        self.assertNotIn('telemetry.internal.warm_cache.warm.end',
                         self.markers)
        self.assertNotIn('telemetry.internal.warm_cache.hot.start',
                         self.markers)
        self.assertNotIn('telemetry.internal.warm_cache.hot.end', self.markers)
Ejemplo n.º 12
0
    def WillRunStory(self, page):
        if not self.platform.tracing_controller.is_tracing_running:
            # For TimelineBasedMeasurement benchmarks, tracing has already started.
            # For PageTest benchmarks, tracing has not yet started. We need to make
            # sure no tracing state is left before starting the browser for PageTest
            # benchmarks.
            self.platform.tracing_controller.ClearStateIfNeeded()

        page_set = page.page_set
        self._current_page = page
        if self._browser and page.startup_url:
            assert not self.platform.tracing_controller.is_tracing_running, (
                'Should not restart browser when tracing is already running. For '
                'TimelineBasedMeasurement (TBM) benchmarks, you should not use '
                'startup_url.')
            self._StopBrowser()
        started_browser = not self.browser

        archive_path = page_set.WprFilePathForStory(page,
                                                    self.platform.GetOSName())
        # TODO(nednguyen, perezju): Ideally we should just let the network
        # controller raise an exception when the archive_path is not found.
        if archive_path is not None and not os.path.isfile(archive_path):
            logging.warning('WPR archive missing: %s', archive_path)
            archive_path = None
        self.platform.network_controller.StartReplay(
            archive_path, page.make_javascript_deterministic)

        if self.browser:
            # Set new credential path for browser.
            self.browser.credentials.credentials_path = page.credentials_path
        else:
            self._StartBrowser(page)
        if self.browser.supports_tab_control and self._test.close_tabs_before_run:
            # Create a tab if there's none.
            if len(self.browser.tabs) == 0:
                self.browser.tabs.New()

            # Ensure only one tab is open.
            while len(self.browser.tabs) > 1:
                self.browser.tabs[-1].Close()

            # Must wait for tab to commit otherwise it can commit after the next
            # navigation has begun and RenderFrameHostManager::DidNavigateMainFrame()
            # will cancel the next navigation because it's pending. This manifests as
            # the first navigation in a PageSet freezing indefinitely because the
            # navigation was silently canceled when |self.browser.tabs[0]| was
            # committed. Only do this when we just started the browser, otherwise
            # there are cases where previous pages in a PageSet never complete
            # loading so we'll wait forever.
            if started_browser:
                self.browser.tabs[0].WaitForDocumentReadyStateToBeComplete()

        # Reset traffic shaping to speed up cache temperature setup.
        self.platform.network_controller.UpdateTrafficSettings(0, 0, 0)
        cache_temperature.EnsurePageCacheTemperature(self._current_page,
                                                     self.browser,
                                                     self._previous_page)
        if self._current_page.traffic_setting != traffic_setting.NONE:
            s = traffic_setting.NETWORK_CONFIGS[
                self._current_page.traffic_setting]
            self.platform.network_controller.UpdateTrafficSettings(
                round_trip_latency_ms=s.round_trip_latency_ms,
                download_bandwidth_kbps=s.download_bandwidth_kbps,
                upload_bandwidth_kbps=s.upload_bandwidth_kbps)

        self._AllowInteractionForStage('before-run-story')
        # Start profiling if needed.
        if self._finder_options.profiler:
            self._StartProfiling(self._current_page)