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-- Consider calling android_jank_correlate_frame_slice which passes a default value for 17-- `table_name_prefix`. 18-- 19-- Matches slices with frames within CUJs and aggregates slices durations within each frame. 20-- This allows comparing the cumulative durations of a set of slices vs what was the expected 21-- duration of each frame. It can be a useful heuristic to figure out what contributed to 22-- frames missing their expected deadlines. 23-- 24-- For more details see the documentation in query_frame_slice.sql. 25-- 26-- Example usage: 27-- 28-- CREATE PERFETTO VIEW example_table AS 29-- SELECT * FROM android_jank_cuj_slice WHERE name = 'binder transaction'; 30-- SELECT android_jank_correlate_frame_slice_impl('MainThread', 31-- 'example_table', 32-- 'jank_query'); 33-- SELECT * FROM jank_query_slice_in_frame_agg; 34-- 35-- Function arguments: 36-- 37-- table_set - Name of a set of tables from `android_jank_cuj_table_set`. 38-- Groups releated tables to simplify passing them as arguments to 39-- functions. 40-- 41-- relevant_slice_table_name - Table or View which selects slices for analysis 42-- from the `android_jank_cuj_slice` table. 43-- 44-- table_name_prefix - Running the function will create multiple tables. This 45-- value will be used as a prefx for their names to avoid 46-- name collisions with other tables. 47CREATE OR REPLACE PERFETTO FUNCTION android_jank_correlate_frame_slice_impl( 48 table_set STRING, 49 relevant_slice_table_name STRING, 50 table_name_prefix STRING 51) 52RETURNS STRING AS 53-- COALESCE to return the text with table names to the caller instead of NULL 54SELECT COALESCE( 55 RUN_METRIC( 56 "android/jank/internal/query_frame_slice.sql", 57 "table_name_prefix", $table_name_prefix, 58 "relevant_slice_table_name", $relevant_slice_table_name, 59 "slice_table_name", (SELECT android_jank_cuj_table_set_slice($table_set)), 60 "frame_boundary_table_name", (SELECT android_jank_cuj_table_set_frame_boundary($table_set)), 61 "frame_table_name", (SELECT android_jank_cuj_table_set_frame($table_set)) 62 ), 63 "Query results in `" || $table_name_prefix || "_slice_in_frame_agg` and `" || $table_name_prefix || "_slice_in_frame`." 64); 65 66-- Provides a default value for table_name_prefix in 67-- android_jank_correlate_frame_slice_impl. 68-- See documentation for android_jank_correlate_frame_slice_impl. 69CREATE OR REPLACE PERFETTO FUNCTION android_jank_correlate_frame_slice( 70 table_set STRING, 71 relevant_slice_table_name STRING 72) 73RETURNS STRING AS 74SELECT android_jank_correlate_frame_slice_impl( 75 $table_set, 76 $relevant_slice_table_name, 77 "jank_query" 78); 79