Home | History | Annotate | Download | only in measurements
      1 # Copyright 2013 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 from measurements import timeline_controller
      5 from metrics import loading
      6 from metrics import timeline
      7 from telemetry.page import page_measurement
      8 from telemetry.web_perf import timeline_interaction_record as tir_module
      9 
     10 class LoadingTrace(page_measurement.PageMeasurement):
     11   def __init__(self, *args, **kwargs):
     12     super(LoadingTrace, self).__init__(*args, **kwargs)
     13     self._timeline_controller = timeline_controller.TimelineController()
     14 
     15   @property
     16   def results_are_the_same_on_every_page(self):
     17     return False
     18 
     19   def WillNavigateToPage(self, page, tab):
     20     self._timeline_controller.Start(page, tab)
     21 
     22   def MeasurePage(self, page, tab, results):
     23     # In current telemetry tests, all tests wait for DocumentComplete state,
     24     # but we need to wait for the load event.
     25     tab.WaitForJavaScriptExpression('performance.timing.loadEventStart', 300)
     26 
     27     # TODO(nduca): when crbug.com/168431 is fixed, modify the page sets to
     28     # recognize loading as a toplevel action.
     29     self._timeline_controller.Stop(tab)
     30 
     31     loading.LoadingMetric().AddResults(tab, results)
     32     timeline_metric = timeline.LoadTimesTimelineMetric()
     33     renderer_thread = \
     34         self._timeline_controller.model.GetRendererThreadFromTabId(tab.id)
     35     record = tir_module.TimelineInteractionRecord(
     36       "loading_trace_interaction", 0, float('inf'))
     37     timeline_metric.AddResults(
     38       self._timeline_controller.model,
     39       renderer_thread,
     40       [record],
     41       results)
     42 
     43   def CleanUpAfterPage(self, _, tab):
     44     self._timeline_controller.CleanUp(tab)
     45