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-- Stores sets of tables that make sense together (e.g. slices on the main thread 17-- and frame boundaries on the main thread). 18-- Used to simplify passing arguments to other functions / metrics. 19DROP TABLE IF EXISTS android_jank_cuj_table_set; 20CREATE TABLE android_jank_cuj_table_set( 21 name TEXT, 22 slice_table_name TEXT, 23 frame_boundary_table_name TEXT, 24 cuj_boundary_table_name TEXT, 25 frame_table_name TEXT); 26 27INSERT INTO android_jank_cuj_table_set( 28 name, 29 slice_table_name, 30 frame_boundary_table_name, 31 cuj_boundary_table_name, 32 frame_table_name) 33VALUES 34('App threads', 35 'android_jank_cuj_slice', 36 'android_jank_cuj_frame', 37 'android_jank_cuj_boundary', 38 'android_jank_cuj_frame'), 39('MainThread', 40 'android_jank_cuj_main_thread_slice', 41 'android_jank_cuj_main_thread_frame_boundary', 42 'android_jank_cuj_main_thread_cuj_boundary', 43 'android_jank_cuj_frame'), 44('RenderThread', 45 'android_jank_cuj_render_thread_slice', 46 'android_jank_cuj_render_thread_frame_boundary', 47 'android_jank_cuj_render_thread_cuj_boundary', 48 'android_jank_cuj_frame'), 49('SF threads', 50 'android_jank_cuj_sf_slice', 51 'android_jank_cuj_sf_frame', 52 'android_jank_cuj_sf_boundary', 53 'android_jank_cuj_sf_frame'), 54('SF MainThread', 55 'android_jank_cuj_sf_main_thread_slice', 56 'android_jank_cuj_sf_main_thread_frame_boundary', 57 'android_jank_cuj_sf_main_thread_cuj_boundary', 58 'android_jank_cuj_sf_frame'), 59('SF RenderEngine', 60 'android_jank_cuj_sf_render_engine_slice', 61 'android_jank_cuj_sf_render_engine_frame_boundary', 62 'android_jank_cuj_sf_boundary', 63 'android_jank_cuj_sf_frame'); 64 65-- Functions below retrieve specific columns for a given table set. 66 67CREATE OR REPLACE PERFETTO FUNCTION android_jank_cuj_table_set_slice(table_set STRING) 68RETURNS STRING AS 69SELECT slice_table_name 70FROM android_jank_cuj_table_set ts 71WHERE ts.name = $table_set; 72 73CREATE OR REPLACE PERFETTO FUNCTION android_jank_cuj_table_set_frame_boundary( 74 table_set STRING 75) 76RETURNS STRING AS 77SELECT frame_boundary_table_name 78FROM android_jank_cuj_table_set ts 79WHERE ts.name = $table_set; 80 81CREATE OR REPLACE PERFETTO FUNCTION android_jank_cuj_table_set_cuj_boundary( 82 table_set STRING 83) 84RETURNS STRING AS 85SELECT cuj_boundary_table_name 86FROM android_jank_cuj_table_set ts 87WHERE ts.name = $table_set; 88 89CREATE OR REPLACE PERFETTO FUNCTION android_jank_cuj_table_set_frame(table_set STRING) 90RETURNS STRING AS 91SELECT frame_table_name 92FROM android_jank_cuj_table_set ts 93WHERE ts.name = $table_set; 94 95-- Checks if two slices, described by ts and dur, ts_second and dur_second, overlap. 96-- Does not handle cases where slices are unfinished (dur = -1). 97CREATE OR REPLACE PERFETTO FUNCTION android_jank_cuj_slice_overlaps(ts LONG, 98 dur LONG, 99 ts_second LONG, 100 dur_second LONG) 101RETURNS BOOL AS 102SELECT 103 -- A starts before B ends and A ends after B starts 104 ($ts < $ts_second + $dur_second AND $ts + $dur > $ts_second) 105 -- or A starts after B starts and A ends before B ends 106 OR ($ts > $ts_second AND $ts < $ts_second + $ts_dur); 107