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 67SELECT CREATE_FUNCTION( 68 'ANDROID_JANK_CUJ_TABLE_SET_SLICE(table_set STRING)', 69 'STRING', 70 'SELECT slice_table_name FROM android_jank_cuj_table_set ts WHERE ts.name = $table_set' 71); 72 73SELECT CREATE_FUNCTION( 74 'ANDROID_JANK_CUJ_TABLE_SET_FRAME_BOUNDARY(table_set STRING)', 75 'STRING', 76 'SELECT frame_boundary_table_name FROM android_jank_cuj_table_set ts WHERE ts.name = $table_set' 77); 78 79SELECT CREATE_FUNCTION( 80 'ANDROID_JANK_CUJ_TABLE_SET_CUJ_BOUNDARY(table_set STRING)', 81 'STRING', 82 'SELECT cuj_boundary_table_name FROM android_jank_cuj_table_set ts WHERE ts.name = $table_set' 83); 84 85SELECT CREATE_FUNCTION( 86 'ANDROID_JANK_CUJ_TABLE_SET_FRAME(table_set STRING)', 87 'STRING', 88 'SELECT frame_table_name FROM android_jank_cuj_table_set ts WHERE ts.name = $table_set' 89); 90 91-- Checks if two slices, described by ts and dur, ts_second and dur_second, overlap. 92-- Does not handle cases where slices are unfinished (dur = -1). 93SELECT 94 CREATE_FUNCTION( 95 'ANDROID_JANK_CUJ_SLICE_OVERLAPS(ts LONG, dur LONG, ts_second LONG, dur_second LONG)', 96 'BOOL', 97 'SELECT 98 -- A starts before B ends and A ends after B starts 99 ($ts < $ts_second + $dur_second AND $ts + $dur > $ts_second) 100 -- or A starts after B starts and A ends before B ends 101 OR ($ts > $ts_second AND $ts < $ts_second + $ts_dur)'); 102