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-- Creates a Stack consisting of one frame for a path in the 17-- EXPERIMENTAL_PROTO_PATH table. 18-- 19-- @arg path_id INT Id of the path in EXPERIMENTAL_PROTO_PATH 20-- @ret BYTES Stack with one frame 21SELECT CREATE_FUNCTION( 22"EXPERIMENTAL_PROTO_PATH_TO_FRAME(path_id LONG)", 23"BYTES", 24" 25SELECT 26 CAT_STACKS( 27 'event.name:' || EXTRACT_ARG(arg_set_id, 'event.name'), 28 'event.category:' || EXTRACT_ARG(arg_set_id, 'event.category'), 29 field_name, 30 field_type) 31FROM EXPERIMENTAL_PROTO_PATH 32WHERE id = $path_id 33"); 34 35-- Creates a Stack following the parent relations in EXPERIMENTAL_PROTO_PATH 36-- table starting at the given path_id. 37-- 38-- @arg path_id INT Id of the path in EXPERIMENTAL_PROTO_PATH that will be 39-- the leaf in the returned stack 40-- @ret BYTES Stack 41SELECT CREATE_FUNCTION( 42"EXPERIMENTAL_PROTO_PATH_TO_STACK(path_id LONG)", 43"BYTES", 44" 45WITH 46 R AS ( 47 -- Starting at the given path_id generate a stack 48 SELECT 49 EXPERIMENTAL_PROTO_PATH_TO_FRAME($path_id) AS stack, 50 parent_id AS parent_id 51 FROM EXPERIMENTAL_PROTO_PATH AS p 52 WHERE id = $path_id 53 UNION ALL 54 -- And recursively add parent paths to the stack 55 SELECT 56 CAT_STACKS( 57 EXPERIMENTAL_PROTO_PATH_TO_FRAME(p.id), 58 c.stack) 59 AS stack, 60 p.parent_id AS parent_id 61 FROM EXPERIMENTAL_PROTO_PATH AS p, R AS c 62 WHERE p.id = c.parent_id 63 ) 64-- Select only the last row in the recursion (the one that stopped it because 65-- it had no parent, i.e. the root) as this will be the row that has the full 66-- stack. All the others will only have partial stacks. 67SELECT stack 68FROM R 69WHERE 70 parent_id IS NULL 71");