• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16-- Given two slice ids, returns whether the first is an ancestor of the second.
17CREATE PERFETTO FUNCTION slice_is_ancestor(
18  -- Id of the potential ancestor slice.
19  ancestor_id LONG,
20  -- Id of the potential descendant slice.
21  descendant_id LONG
22)
23-- Whether `ancestor_id` slice is an ancestor of `descendant_id`.
24RETURNS BOOL AS
25SELECT
26  ancestor.track_id = descendant.track_id AND
27  ancestor.ts <= descendant.ts AND
28  (ancestor.dur == -1 OR ancestor.ts + ancestor.dur >= descendant.ts + descendant.dur)
29FROM slice ancestor
30JOIN slice descendant
31WHERE ancestor.id = $ancestor_id
32  AND descendant.id = $descendant_id;