1-- 2-- Copyright 2023 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 16INCLUDE PERFETTO MODULE prelude.after_eof.views; 17 18-- Given two slice ids, returns whether the first is an ancestor of the second. 19CREATE PERFETTO FUNCTION slice_is_ancestor( 20 -- Id of the potential ancestor slice. 21 ancestor_id LONG, 22 -- Id of the potential descendant slice. 23 descendant_id LONG 24) 25-- Whether `ancestor_id` slice is an ancestor of `descendant_id`. 26RETURNS BOOL AS 27SELECT 28 ancestor.track_id = descendant.track_id 29 AND ancestor.ts <= descendant.ts 30 AND ( 31 ancestor.dur = -1 OR ancestor.ts + ancestor.dur >= descendant.ts + descendant.dur 32 ) 33FROM slice AS ancestor, slice AS descendant 34WHERE 35 ancestor.id = $ancestor_id AND descendant.id = $descendant_id; 36