| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 import copy | 4 import copy |
| 5 | 5 |
| 6 from telemetry.web_perf import timeline_interaction_record as tir_module | 6 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 7 | 7 |
| 8 | 8 |
| 9 def GetAdjustedInteractionIfContainGesture(timeline, interaction_record): | 9 def GetAdjustedInteractionIfContainGesture(timeline, interaction_record): |
| 10 """ Returns a new interaction record if interaction_record contains geture | 10 """ Returns a new interaction record if interaction_record contains geture |
| 11 whose time range that overlaps with interaction_record's range. If not, | 11 whose time range that overlaps with interaction_record's range. If not, |
| 12 returns a clone of original interaction_record. | 12 returns a clone of original interaction_record. |
| 13 The synthetic gesture controller inserts a trace marker to precisely | 13 The synthetic gesture controller inserts a trace marker to precisely |
| 14 demarcate when the gesture was running. We check for overlap, not inclusion, | 14 demarcate when the gesture was running. We check for overlap, not inclusion, |
| 15 because gesture_actions can start/end slightly outside the telemetry markers | 15 because gesture_actions can start/end slightly outside the telemetry markers |
| 16 on Windows. This problem is probably caused by a race condition between | 16 on Windows. This problem is probably caused by a race condition between |
| 17 the browser and renderer process submitting the trace events for the | 17 the browser and renderer process submitting the trace events for the |
| 18 markers. | 18 markers. |
| 19 """ | 19 """ |
| 20 # Only adjust the range for gestures. | 20 # Only adjust the range for gestures. |
| 21 if not interaction_record.label.startswith('Gesture_'): | 21 if not interaction_record.label.startswith('Gesture_'): |
| 22 return copy.copy(interaction_record) | 22 return copy.copy(interaction_record) |
| 23 gesture_events = [ | 23 gesture_events = [ |
| 24 ev for ev | 24 ev for ev |
| 25 in timeline.GetAllToplevelSlicesOfName( | 25 in timeline.IterAllAsyncSlicesOfName('SyntheticGestureController::running') |
| 26 'SyntheticGestureController::running') | 26 if ev.parent_slice is None and |
| 27 if ev.start <= interaction_record.end and | 27 ev.start <= interaction_record.end and |
| 28 ev.end >= interaction_record.start] | 28 ev.end >= interaction_record.start] |
| 29 if len(gesture_events) == 0: | 29 if len(gesture_events) == 0: |
| 30 return copy.copy(interaction_record) | 30 return copy.copy(interaction_record) |
| 31 if len(gesture_events) > 1: | 31 if len(gesture_events) > 1: |
| 32 raise Exception('More than one possible synthetic gesture marker found in ' | 32 raise Exception('More than one possible synthetic gesture marker found in ' |
| 33 'interaction_record %s.' % interaction_record.label) | 33 'interaction_record %s.' % interaction_record.label) |
| 34 return tir_module.TimelineInteractionRecord(interaction_record.label, | 34 return tir_module.TimelineInteractionRecord( |
| 35 gesture_events[0].start, | 35 interaction_record.label, gesture_events[0].start, |
| 36 gesture_events[0].end) | 36 gesture_events[0].end, gesture_events[0], |
| 37 interaction_record._flags) # pylint: disable=W0212 |
| OLD | NEW |