Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / telemetry / web_perf / metrics / jitter_timeline.py
blobcc1879d50e99bf5f5da87aab01447ebb03ea30d8
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.
5 from telemetry.value import improvement_direction
6 from telemetry.value import list_of_scalar_values
7 from telemetry.web_perf.metrics import timeline_based_metric
10 JITTER_EVENT_NAME = 'jitter'
13 class JitterTimelineMetric(timeline_based_metric.TimelineBasedMetric):
14 """JitterTimelineMetric reports jitter in composited layers.
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 """
21 def __init__(self):
22 super(JitterTimelineMetric, self).__init__()
24 @staticmethod
25 def IsJitterEvent(event):
26 return event.name == JITTER_EVENT_NAME
28 def AddResults(self, model, renderer_thread, interactions, results):
29 assert interactions
31 jitter_events = []
32 for event in model.IterAllEvents(
33 event_predicate=self.IsJitterEvent):
34 jitter_events.append(event)
36 self._AddJitterResultsInternal(jitter_events, interactions, results)
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))