1-- 2-- Copyright 2024 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 callstacks.stack_profile; 17 18CREATE PERFETTO MACRO _android_heap_profile_callstacks_for_allocations( 19 allocations TableOrSubquery 20) 21RETURNS TableOrSubquery AS 22( 23 WITH 24 metrics AS MATERIALIZED ( 25 SELECT 26 callsite_id, 27 sum(size) AS self_size, 28 sum(count) AS self_count, 29 sum(alloc_size) AS self_alloc_size, 30 sum(alloc_count) AS self_alloc_count 31 FROM $allocations 32 GROUP BY 33 callsite_id 34 ) 35 SELECT 36 c.id, 37 c.parent_id, 38 c.name, 39 c.mapping_name, 40 c.source_file, 41 c.line_number, 42 coalesce(m.self_size, 0) AS self_size, 43 coalesce(m.self_count, 0) AS self_count, 44 coalesce(m.self_alloc_size, 0) AS self_alloc_size, 45 coalesce(m.self_alloc_count, 0) AS self_alloc_count 46 FROM _callstacks_for_stack_profile_samples!(metrics) AS c 47 LEFT JOIN metrics AS m 48 USING (callsite_id) 49); 50