• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1-- Copyright 2023 The Chromium Authors
2-- Use of this source code is governed by a BSD-style license that can be
3-- found in the LICENSE file.
4
5-- This file creates two public views:
6--     - chrome_scroll_input_offsets and
7--     - chrome_presented_scroll_offsets
8--
9-- These views store the pixel deltas and offsets for (respectively) all chrome
10-- scroll inputs (coalesced and not coalesced), and for chrome presented frames
11-- (not coalesced), along with the associated timestamp, and id.
12--
13-- Raw deltas are recorded as changes in pixel positions along the y-axis of a
14-- screen, and are scaled to the viewport size. The corresponding trace event
15-- for this is TranslateAndScaleWebInputEvent. These are the deltas for all
16-- chrome scroll inputs.
17--
18-- For presented frames, the delta is calculated from the visual offset,
19-- recorded once the input has been processed, in the
20-- InputHandlerProxy::HandleGestureScrollUpdate_Result event. These values are
21-- also scaled to the screen size.
22--
23-- Offsets are calculated by summing all of the deltas, ordered by timestamp.
24-- For a given input/frame, the offset is the sum of its corresponding delta and
25-- all previous deltas.
26--
27--
28-- All values required for calculating deltas and offsets are recorded at
29-- various stages of input processing, and are unified by a single
30-- scroll_update_id value, recorded as scroll_deltas.trace_id in each event.
31
32INCLUDE PERFETTO MODULE chrome.chrome_scrolls;
33INCLUDE PERFETTO MODULE chrome.scroll_jank.scroll_jank_v3;
34
35-- All (coalesced and non-coalesced) vertical scrolling deltas and their
36-- associated scroll ids. Delta values are recorded after being scaled to the
37-- device's screen size in the TranslateAndScaleWebInputEvent trace event. In
38-- this trace event, the deltas recorded represent the true (read "original")
39-- values that the Browser receives from Android, and the only processing is
40-- scaling and translation.
41CREATE PERFETTO TABLE _translate_and_scale_scroll_deltas AS
42SELECT
43  EXTRACT_ARG(arg_set_id, 'scroll_deltas.trace_id') AS scroll_update_id,
44  EXTRACT_ARG(arg_set_id, 'scroll_deltas.original_delta_y') AS delta_y
45FROM slice
46WHERE slice.name = 'TranslateAndScaleWebInputEvent';
47
48-- Associate the gesture scroll update OS timestamp with the delta.
49CREATE PERFETTO TABLE _scroll_deltas_with_timestamp AS
50SELECT
51  slice.id AS event_latency_slice_id,
52  slice.ts AS input_ts,
53  data.scroll_update_id,
54  data.delta_y
55FROM _translate_and_scale_scroll_deltas data
56  JOIN slice ON slice.name = 'EventLatency'
57    AND data.scroll_update_id = EXTRACT_ARG(arg_set_id,
58        'event_latency.event_latency_id');
59
60-- Associate the scroll update/delta with the correct scroll.
61CREATE PERFETTO TABLE _scroll_deltas_with_scroll_id AS
62SELECT
63  scrolls.id AS scroll_id,
64  deltas.event_latency_slice_id,
65  deltas.input_ts,
66  deltas.scroll_update_id,
67  deltas.delta_y
68FROM _scroll_deltas_with_timestamp deltas
69  LEFT JOIN chrome_scrolls scrolls
70    ON deltas.input_ts >= scrolls.ts
71      AND deltas.input_ts <= scrolls.ts + scrolls.dur;
72
73-- Associate the presentation timestamp/deltas with the user deltas.
74CREATE PERFETTO TABLE _scroll_deltas_with_delays AS
75SELECT
76  deltas.scroll_id,
77  delay.total_delta,
78  deltas.scroll_update_id,
79  deltas.event_latency_slice_id,
80  delay.presentation_timestamp AS presentation_timestamp,
81  deltas.input_ts,
82  deltas.delta_y
83FROM _scroll_deltas_with_scroll_id AS deltas
84  LEFT JOIN chrome_frame_info_with_delay AS delay USING(scroll_update_id);
85
86-- The raw coordinates and pixel offsets for all input events which were part of
87-- a scroll.
88CREATE PERFETTO TABLE chrome_scroll_input_offsets(
89  -- An ID that ties all EventLatencies in a particular scroll. (implementation
90  -- note: This is the EventLatency TraceId of the GestureScrollbegin).
91  scroll_id LONG,
92  -- An ID for this particular EventLatency regardless of it being presented or
93  -- not.
94  event_latency_slice_id LONG,
95  -- An ID that ties this |event_latency_id| with the Trace Id (another
96  -- event_latency_id) that it was presented with.
97  scroll_update_id LONG,
98  -- Timestamp the of the scroll input event.
99  ts TIMESTAMP,
100  -- The delta in raw coordinates between this scroll update event and the
101  -- previous.
102  delta_y DOUBLE,
103  -- The pixel offset of this scroll update event compared to the initial one.
104  relative_offset_y DOUBLE
105) AS
106SELECT
107  scroll_id,
108  event_latency_slice_id,
109  scroll_update_id,
110  input_ts AS ts,
111  delta_y,
112  SUM(IFNULL(delta_y, 0)) OVER ( PARTITION BY scroll_id
113    ORDER BY scroll_update_id, input_ts
114    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS relative_offset_y
115FROM _scroll_deltas_with_delays;
116
117-- The scrolling offsets for the actual (applied) scroll events. These are not
118-- necessarily inclusive of all user scroll events, rather those scroll events
119-- that are actually processed.
120CREATE PERFETTO TABLE chrome_presented_scroll_offsets(
121  -- An ID that ties all EventLatencies in a particular scroll. (implementation
122  -- note: This is the EventLatency TraceId of the GestureScrollbegin).
123  scroll_id LONG,
124  -- An ID for this particular EventLatency regardless of it being presented or
125  -- not.
126  event_latency_slice_id LONG,
127  -- An ID that ties this |event_latency_id| with the Trace Id (another
128  -- event_latency_id) that it was presented with.
129  scroll_update_id LONG,
130  -- Presentation timestamp.
131  ts TIMESTAMP,
132  -- The delta in raw coordinates between this scroll update event and the
133  -- previous.
134  delta_y DOUBLE,
135  -- The pixel offset of this scroll update event compared to the initial one.
136  relative_offset_y DOUBLE
137) AS
138SELECT
139  scroll_id,
140  event_latency_slice_id,
141  scroll_update_id,
142  presentation_timestamp AS ts,
143  total_delta AS delta_y,
144  SUM(IFNULL(total_delta, 0)) OVER ( PARTITION BY scroll_id
145    ORDER BY scroll_update_id, presentation_timestamp
146    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS relative_offset_y
147FROM _scroll_deltas_with_delays
148WHERE presentation_timestamp IS NOT NULL
149;
150