• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.memory.heap_graph.class_tree;
17
18INCLUDE PERFETTO MODULE graphs.scan;
19
20CREATE PERFETTO TABLE _heap_graph_class_tree_cumulatives AS
21SELECT
22  *
23FROM _graph_aggregating_scan!(
24  (
25    SELECT id AS source_node_id, parent_id AS dest_node_id
26    FROM _heap_graph_class_tree
27    WHERE parent_id IS NOT NULL
28  ),
29  (
30    SELECT
31      p.id,
32      p.self_count AS cumulative_count,
33      p.self_size AS cumulative_size
34    FROM _heap_graph_class_tree p
35    LEFT JOIN _heap_graph_class_tree c ON c.parent_id = p.id
36    WHERE c.id IS NULL
37  ),
38  (cumulative_count, cumulative_size),
39  (
40    WITH agg AS (
41      SELECT
42        t.id,
43        SUM(t.cumulative_count) AS child_count,
44        SUM(t.cumulative_size) AS child_size
45      FROM $table t
46      GROUP BY t.id
47    )
48    SELECT
49      a.id,
50      a.child_count + r.self_count as cumulative_count,
51      a.child_size + r.self_size as cumulative_size
52    FROM agg a
53    JOIN _heap_graph_class_tree r USING (id)
54  )
55) AS a
56ORDER BY
57  id;
58
59-- Table containing all the Android heap graphs in the trace converted to a
60-- shortest-path tree and then aggregated by class name.
61--
62-- This table contains a "flamegraph-like" representation of the contents of the
63-- heap graph.
64CREATE PERFETTO TABLE android_heap_graph_class_summary_tree (
65  -- The timestamp the heap graph was dumped at.
66  graph_sample_ts TIMESTAMP,
67  -- The upid of the process.
68  upid JOINID(process.id),
69  -- The id of the node in the class tree.
70  id LONG,
71  -- The parent id of the node in the class tree or NULL if this is the root.
72  parent_id LONG,
73  -- The name of the class.
74  name STRING,
75  -- A string describing the type of Java root if this node is a root or NULL
76  -- if this node is not a root.
77  root_type STRING,
78  -- The count of objects with the same class name and the same path to the
79  -- root.
80  self_count LONG,
81  -- The size of objects with the same class name and the same path to the
82  -- root.
83  self_size LONG,
84  -- The sum of `self_count` of this node and all descendants of this node.
85  cumulative_count LONG,
86  -- The sum of `self_size` of this node and all descendants of this node.
87  cumulative_size LONG
88) AS
89SELECT
90  t.graph_sample_ts,
91  t.upid,
92  t.id,
93  t.parent_id,
94  t.name,
95  t.root_type,
96  t.self_count,
97  t.self_size,
98  c.cumulative_count,
99  c.cumulative_size
100FROM _heap_graph_class_tree AS t
101JOIN _heap_graph_class_tree_cumulatives AS c
102  USING (id);
103