1# Copyright 2015 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 5from telemetry.value import improvement_direction 6from telemetry.value import list_of_scalar_values 7from telemetry.web_perf.metrics import timeline_based_metric 8 9 10JITTER_EVENT_NAME = 'jitter' 11 12 13class JitterTimelineMetric(timeline_based_metric.TimelineBasedMetric): 14 """JitterTimelineMetric reports jitter in composited layers. 15 16 This jitter is due to the main thread attempting to fix the position of a 17 scrolling composited layer. 'jitter-amount' is the metric added to the 18 results. 19 """ 20 21 def __init__(self): 22 super(JitterTimelineMetric, self).__init__() 23 24 @staticmethod 25 def IsJitterEvent(event): 26 return event.name == JITTER_EVENT_NAME 27 28 def AddResults(self, model, renderer_thread, interactions, results): 29 assert interactions 30 31 jitter_events = [] 32 for event in model.IterAllEvents( 33 event_predicate=self.IsJitterEvent): 34 jitter_events.append(event) 35 36 self._AddJitterResultsInternal(jitter_events, interactions, results) 37 38 def _AddJitterResultsInternal(self, events, interactions, results): 39 jitters = [] 40 for event in events: 41 if timeline_based_metric.IsEventInInteractions(event, interactions): 42 jitters.append(event.args['value']) 43 if jitters: 44 results.AddValue(list_of_scalar_values.ListOfScalarValues( 45 page=results.current_page, 46 tir_label=interactions[0].label, 47 name='jitter-amount', 48 units='score', 49 values=jitters, 50 description='Jitter each frame', 51 improvement_direction=improvement_direction.DOWN)) 52