Exemple #1
0
 def Stop(self, tab):
     # Stop tracing for smoothness metric.
     if tab.browser.platform.IsRawDisplayFrameRateSupported():
         tab.browser.platform.StopRawDisplayFrameRateMeasurement()
     tracing_timeline_data = tab.browser.StopTracing()
     self._timeline_model = TimelineModel(
         timeline_data=tracing_timeline_data)
  def Stop(self, tab):
    # End the smooth marker for all actions.
    runner = action_runner.ActionRunner(None, tab)
    runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH])
    # Stop tracing.
    timeline_data = tab.browser.StopTracing()
    self._model = TimelineModel(timeline_data)
    self._renderer_process = self._model.GetRendererProcessFromTab(tab)
    renderer_thread = self.model.GetRendererThreadFromTab(tab)

    run_smooth_actions_record = None
    self._smooth_records = []
    for event in renderer_thread.async_slices:
      if not tir_module.IsTimelineInteractionRecord(event.name):
        continue
      r = tir_module.TimelineInteractionRecord.FromEvent(event)
      if r.logical_name == RUN_SMOOTH_ACTIONS:
        assert run_smooth_actions_record is None, (
          'TimelineController cannot issue more than 1 %s record' %
          RUN_SMOOTH_ACTIONS)
        run_smooth_actions_record = r
      elif r.is_smooth:
        self._smooth_records.append(
          smooth_gesture_util.GetAdjustedInteractionIfContainGesture(
            self.model, r))

    # If there is no other smooth records, we make measurements on time range
    # marked by timeline_controller itself.
    # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that
    # page sets are responsible for issueing the markers themselves.
    if len(self._smooth_records) == 0 and run_smooth_actions_record:
      self._smooth_records = [run_smooth_actions_record]
Exemple #3
0
 def testTimelineEventsOfType(self):
     timeline_model = TimelineModel()
     a = TimelineEvent('a', 0, 10)
     b = TimelineEvent('b', 11, 10)
     timeline_model.AddEvent(a)
     timeline_model.AddEvent(b)
     timeline_model.DidFinishRecording()
     self.assertEquals(1, len(timeline_model.GetAllEventsOfName('a')))
Exemple #4
0
 def Stop(self, tab):
   timeline_data = tab.browser.StopTracing()
   self._model = TimelineModel(timeline_data)
   self._renderer_process = self._model.GetRendererProcessFromTab(tab)
   self._action_ranges = [ action.GetActiveRangeOnTimeline(self._model)
                           for action in self._actions ]
   # Make sure no action ranges overlap
   for combo in itertools.combinations(self._action_ranges, 2):
     assert not combo[0].Intersects(combo[1])
 def Stop(self, tab):
     # End the smooth marker for all smooth actions.
     runner = action_runner.ActionRunner(None, tab)
     runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH])
     # Stop tracing for smoothness metric.
     if tab.browser.platform.IsRawDisplayFrameRateSupported():
         tab.browser.platform.StopRawDisplayFrameRateMeasurement()
     self._tracing_timeline_data = tab.browser.StopTracing()
     self._timeline_model = TimelineModel(
         timeline_data=self._tracing_timeline_data)
Exemple #6
0
class TimelineController(object):
  def __init__(self):
    super(TimelineController, self).__init__()
    self.trace_categories = DEFAULT_TRACE_CATEGORIES
    self._model = None
    self._renderer_process = None
    self._actions = []
    self._action_ranges = []

  def Start(self, page, tab):
    """Starts gathering timeline data.

    """
    # Resets these member variables incase this object is reused.
    self._model = None
    self._renderer_process = None
    self._actions = []
    self._action_ranges = []
    if not tab.browser.supports_tracing:
      raise Exception('Not supported')
    if self.trace_categories:
      categories = [self.trace_categories] + \
          page.GetSyntheticDelayCategories()
    else:
      categories = page.GetSyntheticDelayCategories()
    tab.browser.StartTracing(','.join(categories))

  def Stop(self, tab):
    timeline_data = tab.browser.StopTracing()
    self._model = TimelineModel(timeline_data)
    self._renderer_process = self._model.GetRendererProcessFromTab(tab)
    self._action_ranges = [ action.GetActiveRangeOnTimeline(self._model)
                            for action in self._actions ]
    # Make sure no action ranges overlap
    for combo in itertools.combinations(self._action_ranges, 2):
      assert not combo[0].Intersects(combo[1])

  def CleanUp(self, tab):
    if tab.browser.is_tracing_running:
      tab.browser.StopTracing()

  def AddActionToIncludeInMetric(self, action):
    self._actions.append(action)

  @property
  def model(self):
    return self._model

  @property
  def renderer_process(self):
    return self._renderer_process

  @property
  def action_ranges(self):
    return self._action_ranges
 def testBrowserProcess(self):
     ri = tracing_timeline_data.TracingTimelineData(
         map(json.loads, [
             '{"name": "process_name",'
             '"args": {"name": "Browser"},'
             '"pid": 5, "ph": "M"}', '{"name": "thread_name",'
             '"args": {"name": "CrBrowserMain"},'
             '"pid": 5, "tid": 32578, "ph": "M"}'
         ]))
     model = TimelineModel(ri)
     self.assertEquals(model.browser_process.pid, 5)
Exemple #8
0
class SmoothnessController(object):
    def __init__(self):
        self._actions = []
        self._timeline_model = None

    def Start(self, page, tab):
        self._actions = []
        custom_categories = ['webkit.console', 'benchmark']
        custom_categories += page.GetSyntheticDelayCategories()
        tab.browser.StartTracing(','.join(custom_categories), 60)
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            tab.browser.platform.StartRawDisplayFrameRateMeasurement()

    def AddActionToIncludeInMetric(self, action):
        self._actions.append(action)

    def Stop(self, tab):
        # Stop tracing for smoothness metric.
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            tab.browser.platform.StopRawDisplayFrameRateMeasurement()
        tracing_timeline_data = tab.browser.StopTracing()
        self._timeline_model = TimelineModel(
            timeline_data=tracing_timeline_data)

    def AddResults(self, tab, results):
        # Add results of smoothness metric. This computes the smoothness metric for
        # the time range between the first action starts and the last action ends.
        # To get the measurement for each action, use
        # measurement.TimelineBasedMeasurement.
        time_bounds = timeline_bounds.Bounds()
        for action in self._actions:
            time_bounds.AddBounds(
                action.GetActiveRangeOnTimeline(self._timeline_model))
        # Create an interaction_record for this legacy measurement. Since we don't
        # wrap the results that is sent to smoothnes metric, the logical_name will
        # not be used.
        interaction_record = tir_module.TimelineInteractionRecord(
            'smoothness_interaction', time_bounds.min, time_bounds.max)
        renderer_thread = self._timeline_model.GetRendererThreadFromTab(tab)
        smoothness_metric = smoothness.SmoothnessMetric()
        smoothness_metric.AddResults(self._timeline_model, renderer_thread,
                                     interaction_record, results)
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements():
                if r.value is None:
                    raise MissingDisplayFrameRateError(r.name)
                results.Add(r.name, r.unit, r.value)

    def CleanUp(self, tab):
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            tab.browser.platform.StopRawDisplayFrameRateMeasurement()
        if tab.browser.is_tracing_running:
            tab.browser.StopTracing()
class SmoothnessController(object):
    def __init__(self):
        self._timeline_model = None
        self._tracing_timeline_data = None

    def Start(self, page, tab):
        custom_categories = ['webkit.console', 'benchmark']
        custom_categories += page.GetSyntheticDelayCategories()
        tab.browser.StartTracing(','.join(custom_categories), 60)
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            tab.browser.platform.StartRawDisplayFrameRateMeasurement()
        # Start the smooth marker for all smooth actions.
        runner = action_runner.ActionRunner(None, tab)
        runner.BeginInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH])

    def Stop(self, tab):
        # End the smooth marker for all smooth actions.
        runner = action_runner.ActionRunner(None, tab)
        runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH])
        # Stop tracing for smoothness metric.
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            tab.browser.platform.StopRawDisplayFrameRateMeasurement()
        self._tracing_timeline_data = tab.browser.StopTracing()
        self._timeline_model = TimelineModel(
            timeline_data=self._tracing_timeline_data)

    def AddResults(self, tab, results):
        # Add results of smoothness metric. This computes the smoothness metric for
        # the time ranges of gestures, if there is at least one, else the the time
        # ranges from the first action to the last action.

        renderer_thread = self._timeline_model.GetRendererThreadFromTab(tab)
        run_smooth_actions_record = None
        smooth_records = []
        for event in renderer_thread.async_slices:
            if not tir_module.IsTimelineInteractionRecord(event.name):
                continue
            r = tir_module.TimelineInteractionRecord.FromEvent(event)
            if r.logical_name == RUN_SMOOTH_ACTIONS:
                assert run_smooth_actions_record is None, (
                    'SmoothnessController cannot issue more than 1 %s record' %
                    RUN_SMOOTH_ACTIONS)
                run_smooth_actions_record = r
            elif r.is_smooth:
                smooth_records.append(
                    smooth_gesture_util.GetAdjustedInteractionIfContainGesture(
                        self._timeline_model, r))

        # If there is no other smooth records, we make measurements on time range
        # marked smoothness_controller itself.
        # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that
        # page sets are responsible for issueing the markers themselves.
        if len(smooth_records) == 0:
            if run_smooth_actions_record is None:
                sys.stderr.write('Raw tracing data:\n')
                sys.stderr.write(repr(self._tracing_timeline_data.EventData()))
                sys.stderr.write('\n')
                raise Exception(
                    'SmoothnessController failed to issue markers for the '
                    'whole interaction.')
            else:
                smooth_records = [run_smooth_actions_record]

        # Create an interaction_record for this legacy measurement. Since we don't
        # wrap the results that is sent to smoothnes metric, the logical_name will
        # not be used.
        smoothness_metric = smoothness.SmoothnessMetric()
        smoothness_metric.AddResults(self._timeline_model, renderer_thread,
                                     smooth_records, results)
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements():
                if r.value is None:
                    raise MissingDisplayFrameRateError(r.name)
                results.Add(r.name, r.unit, r.value)

    def CleanUp(self, tab):
        if tab.browser.platform.IsRawDisplayFrameRateSupported():
            tab.browser.platform.StopRawDisplayFrameRateMeasurement()
        if tab.browser.is_tracing_running:
            tab.browser.StopTracing()
  def MeasurePage(self, page, tab, results):
    if not self._compositing_features_enabled:
      raise page_test.TestNotSupportedOnPlatformFailure(
          'Compositing feature status unknown or not '+
          'forced and threaded. Skipping measurement.')

    # Rasterize only what's visible.
    tab.ExecuteJavaScript(
        'chrome.gpuBenchmarking.setRasterizeOnlyVisibleContent();')

    # Wait until the page has loaded and come to a somewhat steady state.
    # Needs to be adjusted for every device (~2 seconds for workstation).
    time.sleep(self.options.start_wait_time)

    # Render one frame before we start gathering a trace. On some pages, the
    # first frame requested has more variance in the number of pixels
    # rasterized.
    tab.ExecuteJavaScript(
        'window.__rafFired = false;'
        'window.webkitRequestAnimationFrame(function() {'
          'chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers();'
          'window.__rafFired  = true;'
        '});')

    time.sleep(self.options.stop_wait_time)
    tab.browser.StartTracing('webkit.console,benchmark', 60)

    tab.ExecuteJavaScript(
        'window.__rafFired = false;'
        'window.webkitRequestAnimationFrame(function() {'
          'chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers();'
          'console.time("' + TIMELINE_MARKER + '");'
          'window.__rafFired  = true;'
        '});')
    # Wait until the frame was drawn.
    # Needs to be adjusted for every device and for different
    # raster_record_repeat counts.
    # TODO(ernstm): replace by call-back.
    time.sleep(self.options.stop_wait_time)
    tab.ExecuteJavaScript(
        'console.timeEnd("' + TIMELINE_MARKER + '")')

    tracing_timeline_data = tab.browser.StopTracing()
    timeline = TimelineModel(timeline_data=tracing_timeline_data)
    try:
      timeline_markers = timeline.FindTimelineMarkers(TIMELINE_MARKER)
    except (MarkerMismatchError, MarkerOverlapError) as e:
      raise page_measurement.MeasurementFailure(str(e))
    timeline_ranges = [ timeline_bounds.Bounds.CreateFromEvent(marker)
                        for marker in timeline_markers ]
    renderer_process = timeline.GetRendererProcessFromTab(tab)

    stats = rendering_stats.RenderingStats(
        renderer_process, timeline.browser_process, timeline_ranges)

    results.Add('rasterize_time', 'ms', max(FlattenList(stats.rasterize_times)))
    results.Add('record_time', 'ms', max(FlattenList(stats.record_times)))
    results.Add('rasterized_pixels', 'pixels',
                max(FlattenList(stats.rasterized_pixel_counts)))
    results.Add('recorded_pixels', 'pixels',
                max(FlattenList(stats.recorded_pixel_counts)))
class TimelineController(object):
  def __init__(self):
    super(TimelineController, self).__init__()
    self.trace_categories = tracing_backend.DEFAULT_TRACE_CATEGORIES
    self._model = None
    self._renderer_process = None
    self._smooth_records = []

  def Start(self, page, tab):
    """Starts gathering timeline data.

    """
    # Resets these member variables incase this object is reused.
    self._model = None
    self._renderer_process = None
    if not tab.browser.supports_tracing:
      raise Exception('Not supported')
    if self.trace_categories:
      categories = [self.trace_categories] + \
          page.GetSyntheticDelayCategories()
    else:
      categories = page.GetSyntheticDelayCategories()
    tab.browser.StartTracing(','.join(categories))
    # Start the smooth marker for all actions.
    runner = action_runner.ActionRunner(None, tab)
    runner.BeginInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH])

  def Stop(self, tab):
    # End the smooth marker for all actions.
    runner = action_runner.ActionRunner(None, tab)
    runner.EndInteraction(RUN_SMOOTH_ACTIONS, [tir_module.IS_SMOOTH])
    # Stop tracing.
    timeline_data = tab.browser.StopTracing()
    self._model = TimelineModel(timeline_data)
    self._renderer_process = self._model.GetRendererProcessFromTab(tab)
    renderer_thread = self.model.GetRendererThreadFromTab(tab)

    run_smooth_actions_record = None
    self._smooth_records = []
    for event in renderer_thread.async_slices:
      if not tir_module.IsTimelineInteractionRecord(event.name):
        continue
      r = tir_module.TimelineInteractionRecord.FromEvent(event)
      if r.logical_name == RUN_SMOOTH_ACTIONS:
        assert run_smooth_actions_record is None, (
          'TimelineController cannot issue more than 1 %s record' %
          RUN_SMOOTH_ACTIONS)
        run_smooth_actions_record = r
      elif r.is_smooth:
        self._smooth_records.append(
          smooth_gesture_util.GetAdjustedInteractionIfContainGesture(
            self.model, r))

    # If there is no other smooth records, we make measurements on time range
    # marked by timeline_controller itself.
    # TODO(nednguyen): when crbug.com/239179 is marked fixed, makes sure that
    # page sets are responsible for issueing the markers themselves.
    if len(self._smooth_records) == 0 and run_smooth_actions_record:
      self._smooth_records = [run_smooth_actions_record]


  def CleanUp(self, tab):
    if tab.browser.is_tracing_running:
      tab.browser.StopTracing()

  @property
  def model(self):
    return self._model

  @property
  def renderer_process(self):
    return self._renderer_process

  @property
  def smooth_records(self):
    return self._smooth_records