1-- 2-- Copyright 2022 The Android Open Source Project 3-- 4-- Licensed under the Apache License, Version 2.0 (the "License"); 5-- you may not use this file except in compliance with the License. 6-- You may obtain a copy of the License at 7-- 8-- https://www.apache.org/licenses/LICENSE-2.0 9-- 10-- Unless required by applicable law or agreed to in writing, software 11-- distributed under the License is distributed on an "AS IS" BASIS, 12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13-- See the License for the specific language governing permissions and 14-- limitations under the License. 15-- 16 17-- This metric calculates the number of user inputs during a scroll per frame 18-- generated, this can be used to track smoothness. 19-- For normal input, we expect 2 inputs per frame, for flings, we expect 20-- 1 input per frame as flings are generated once per vsync. 21-- The numbers mentioned above are estimates in the ideal case scenario. 22 23INCLUDE PERFETTO MODULE chrome.scroll_jank.utils; 24INCLUDE PERFETTO MODULE common.slices; 25 26-- Grab all GestureScrollUpdate slices. 27DROP VIEW IF EXISTS chrome_all_scroll_updates; 28CREATE PERFETTO VIEW chrome_all_scroll_updates AS 29SELECT 30 S.id, 31 chrome_get_most_recent_scroll_begin_id(ts) AS scroll_id, 32 has_descendant_slice_with_name(S.id, "SubmitCompositorFrameToPresentationCompositorFrame") 33 AS is_presented, 34 ts, 35 dur, 36 track_id 37FROM slice S JOIN args USING(arg_set_id) 38WHERE NAME = "EventLatency" 39AND args.string_value GLOB "*GESTURE_SCROLL_UPDATE"; 40 41-- Count number of input GestureScrollUpdates per scroll. 42DROP VIEW IF EXISTS chrome_update_count_per_scroll; 43CREATE PERFETTO VIEW chrome_update_count_per_scroll AS 44SELECT 45 CAST(COUNT() AS FLOAT) AS count, 46 scroll_id, 47 dur, 48 track_id 49FROM chrome_all_scroll_updates 50GROUP BY scroll_id; 51 52-- Count the number of input GestureScrollUpdates that were converted 53-- frames per scroll. 54DROP VIEW IF EXISTS chrome_presented_update_count_per_scroll; 55CREATE PERFETTO VIEW chrome_presented_update_count_per_scroll AS 56SELECT 57 CAST(COUNT() AS FLOAT) AS presented_count, 58 scroll_id, 59 id, 60 track_id, 61 dur 62FROM chrome_all_scroll_updates 63WHERE is_presented 64GROUP BY scroll_id; 65 66-- Get the average number of inputs per frame per scroll. 67DROP VIEW IF EXISTS chrome_avg_scroll_inputs_per_frame; 68CREATE PERFETTO VIEW chrome_avg_scroll_inputs_per_frame AS 69SELECT 70 count / presented_count AS avg_inputs_per_frame_per_scroll, 71 scroll_id, 72 presented_count 73FROM chrome_presented_update_count_per_scroll 74JOIN chrome_update_count_per_scroll USING(scroll_id); 75 76-- Get the last scroll update event that wasn't coalesced before the 77-- current scroll update. 78DROP VIEW IF EXISTS chrome_frame_main_input_id; 79CREATE PERFETTO VIEW chrome_frame_main_input_id AS 80SELECT 81 id, 82 scroll_id, 83 is_presented, 84 ts, 85 dur, 86 track_id, 87 (SELECT 88 MAX(id) 89 FROM chrome_all_scroll_updates parent_scrolls 90 WHERE is_presented 91 AND parent_scrolls.ts <= scrolls.ts) AS presented_scroll_id 92FROM chrome_all_scroll_updates scrolls; 93 94-- Count the number of inputs per presented frame. 95DROP VIEW IF EXISTS chrome_scroll_inputs_per_frame; 96CREATE PERFETTO VIEW chrome_scroll_inputs_per_frame AS 97SELECT 98 COUNT() AS count_for_frame, 99 presented_scroll_id, 100 ts, 101 dur, 102 id AS slice_id, 103 track_id 104FROM 105 chrome_frame_main_input_id 106GROUP BY presented_scroll_id; 107