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-- Defines slices for all of the individual scrolls in a trace based on the 6-- LatencyInfo-based scroll definition. 7-- 8-- NOTE: this view of top level scrolls is based on the LatencyInfo definition 9-- of a scroll, which differs subtly from the definition based on 10-- EventLatencies. 11-- TODO(b/278684408): add support for tracking scrolls across multiple Chrome/ 12-- WebView instances. Currently gesture_scroll_id unique within an instance, but 13-- is not unique across multiple instances. Switching to an EventLatency based 14-- definition of scrolls should resolve this. 15CREATE PERFETTO TABLE chrome_scrolls( 16 -- The unique identifier of the scroll. 17 id INT, 18 -- The start timestamp of the scroll. 19 ts INT, 20 -- The duration of the scroll. 21 dur INT, 22 -- The earliest timestamp of the InputLatency::GestureScrollBegin for the 23 -- corresponding scroll id. 24 gesture_scroll_begin_ts INT, 25 -- The earliest timestamp of the InputLatency::GestureScrollEnd for the 26 -- corresponding scroll id. 27 gesture_scroll_end_ts INT 28) AS 29WITH all_scrolls AS ( 30 SELECT 31 name, 32 ts, 33 dur, 34 extract_arg(arg_set_id, 'chrome_latency_info.gesture_scroll_id') AS scroll_id 35 FROM slice 36 WHERE name GLOB 'InputLatency::GestureScroll*' 37 AND extract_arg(arg_set_id, 'chrome_latency_info.gesture_scroll_id') IS NOT NULL 38), 39scroll_starts AS ( 40 SELECT 41 scroll_id, 42 MIN(ts) AS gesture_scroll_begin_ts 43 FROM all_scrolls 44 WHERE name = 'InputLatency::GestureScrollBegin' 45 GROUP BY scroll_id 46), scroll_ends AS ( 47 SELECT 48 scroll_id, 49 MIN(ts) AS gesture_scroll_end_ts 50 FROM all_scrolls 51 WHERE name = 'InputLatency::GestureScrollEnd' 52 GROUP BY scroll_id 53) 54SELECT 55 sa.scroll_id AS id, 56 MIN(ts) AS ts, 57 CAST(MAX(ts + dur) - MIN(ts) AS INT) AS dur, 58 ss.gesture_scroll_begin_ts AS gesture_scroll_begin_ts, 59 se.gesture_scroll_end_ts AS gesture_scroll_end_ts 60FROM all_scrolls sa 61 LEFT JOIN scroll_starts ss ON 62 sa.scroll_id = ss.scroll_id 63 LEFT JOIN scroll_ends se ON 64 sa.scroll_id = se.scroll_id 65GROUP BY sa.scroll_id; 66 67-- Defines slices for all of scrolls intervals in a trace based on the scroll 68-- definition in chrome_scrolls. Note that scrolls may overlap (particularly in 69-- cases of jank/broken traces, etc); so scrolling intervals are not exactly the 70-- same as individual scrolls. 71CREATE PERFETTO VIEW chrome_scrolling_intervals( 72 -- The unique identifier of the scroll interval. This may span multiple scrolls if they overlap. 73 id INT, 74 -- Comma-separated list of scroll ids that are included in this interval. 75 scroll_ids STRING, 76 -- The start timestamp of the scroll interval. 77 ts INT, 78 -- The duration of the scroll interval. 79 dur INT 80) AS 81WITH all_scrolls AS ( 82 SELECT 83 id AS scroll_id, 84 s.ts AS start_ts, 85 s.ts + s.dur AS end_ts 86 FROM chrome_scrolls s), 87ordered_end_ts AS ( 88 SELECT 89 *, 90 MAX(end_ts) OVER (ORDER BY start_ts) AS max_end_ts_so_far 91 FROM all_scrolls), 92range_starts AS ( 93 SELECT 94 *, 95 CASE 96 WHEN start_ts <= 1 + LAG(max_end_ts_so_far) OVER (ORDER BY start_ts) THEN 0 97 ELSE 1 98 END AS range_start 99 FROM ordered_end_ts), 100range_groups AS ( 101 SELECT 102 *, 103 SUM(range_start) OVER (ORDER BY start_ts) AS range_group 104 FROM range_starts) 105SELECT 106 range_group AS id, 107 GROUP_CONCAT(scroll_id) AS scroll_ids, 108 MIN(start_ts) AS ts, 109 MAX(end_ts) - MIN(start_ts) AS dur 110FROM range_groups 111GROUP BY range_group; 112