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-- Script params: 17-- {{duration_causing_jank_ms}} : The duration of a single task that would cause 18-- jank, by delaying input from being handled on the main thread. 19-- {{task_table_name}} : The table tracking chrome tasks which will be used to 20-- determine which chrome tasks are causing the delay. One of chrome_tasks or 21-- chrome_long_tasks. 22-- {{input_browser_interval_table_name}} : The table tracking chrome input to 23-- browser interval. This may differ based on whether the scenario is for 24-- topLevel events or LongTask events. 25 26CREATE OR REPLACE PERFETTO FUNCTION {{function_prefix}}SELECT_SLOW_BROWSER_TASKS() 27RETURNS TABLE(full_name STRING, dur INT, ts INT, id INT, upid INT, thread_dur INT) AS 28SELECT 29 task_table.full_name AS full_name, 30 task_table.dur AS dur, 31 task_table.ts AS ts, 32 task_table.id AS id, 33 task_table.upid AS upid, 34 thread_dur 35FROM 36 {{task_table_name}} task_table 37WHERE 38 task_table.dur >= {{duration_causing_jank_ms}} * 1e6 39 AND task_table.thread_name = "CrBrowserMain"; 40 41-- Get the tasks that was running for more than 8ms within windows 42-- that we could have started processing input but did not on the 43-- main thread, because it was blocked by those tasks. 44DROP VIEW IF EXISTS chrome_tasks_delaying_input_processing_unaggregated; 45CREATE PERFETTO VIEW chrome_tasks_delaying_input_processing_unaggregated AS 46SELECT 47 tasks.full_name AS full_name, 48 tasks.dur / 1e6 AS duration_ms, 49 id AS slice_id, 50 thread_dur / 1e6 AS thread_dur_ms, 51 input_tbl.window_start_id, 52 input_tbl.window_end_id 53FROM ({{function_prefix}}SELECT_SLOW_BROWSER_TASKS()) tasks 54JOIN {{input_browser_interval_table_name}} input_tbl 55 ON tasks.ts + tasks.dur > input_tbl.window_start_ts 56 AND tasks.ts + tasks.dur < input_tbl.window_end_ts 57 AND tasks.upid = input_tbl.upid; 58 59-- Same task can delay multiple GestureUpdates, this step dedups 60-- multiple occrences of the same slice_id 61DROP VIEW IF EXISTS chrome_tasks_delaying_input_processing; 62CREATE PERFETTO VIEW chrome_tasks_delaying_input_processing AS 63SELECT 64 full_name, 65 duration_ms, 66 slice_id, 67 thread_dur_ms 68FROM chrome_tasks_delaying_input_processing_unaggregated 69GROUP BY slice_id; 70 71-- Get the tasks that were running for more than 8ms within windows 72-- that we could have started processing input but did not on the 73-- main thread, because it was blocked by those tasks. 74DROP VIEW IF EXISTS chrome_tasks_delaying_input_processing_summary; 75CREATE PERFETTO VIEW chrome_tasks_delaying_input_processing_summary AS 76SELECT 77 full_name AS full_name, 78 AVG(duration_ms) AS avg_duration_ms, 79 AVG(thread_dur_ms) AS avg_thread_duration_ms, 80 MIN(duration_ms) AS min_task_duration, 81 MAX(duration_ms) AS max_task_duration, 82 SUM(duration_ms) AS total_duration_ms, 83 SUM(thread_dur_ms) AS total_thread_duration_ms, 84 GROUP_CONCAT(slice_id, '-') AS slice_ids, 85 COUNT(*) AS count 86FROM 87 chrome_tasks_delaying_input_processing 88GROUP BY 89 full_name; 90