• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 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 a
7#
8#      http://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
16from python.generators.diff_tests.testing import Path
17from python.generators.diff_tests.testing import Csv
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20
21
22class HeapGraphDominatorTree(TestSuite):
23
24  def test_heap_graph_dominator_tree(self):
25    return DiffTestBlueprint(
26        trace=Path('heap_graph_for_dominator_tree.textproto'),
27        query="""
28          INCLUDE PERFETTO MODULE memory.heap_graph_dominator_tree;
29
30          SELECT
31            node.id,
32            node.idom_id,
33            node.dominated_obj_count,
34            node.dominated_size_bytes,
35            node.depth,
36            cls.name AS type_name
37          FROM memory_heap_graph_dominator_tree node
38          JOIN heap_graph_object obj USING(id)
39          JOIN heap_graph_class cls ON obj.type_id = cls.id
40          ORDER BY type_name;
41        """,
42        out=Csv("""
43          "id","idom_id","dominated_obj_count","dominated_size_bytes",\
44"depth","type_name"
45          0,12,1,3,2,"A"
46          2,12,1,3,2,"B"
47          4,12,4,12,2,"C"
48          1,12,2,6,2,"D"
49          3,12,1,3,2,"E"
50          5,4,1,3,3,"F"
51          6,4,2,6,3,"G"
52          8,12,1,3,2,"H"
53          9,12,1,3,2,"I"
54          10,6,1,3,4,"J"
55          11,12,1,3,2,"K"
56          7,1,1,3,3,"L"
57          13,22,6,922,2,"M"
58          16,22,3,100,2,"N"
59          14,13,4,904,3,"O"
60          15,13,1,16,3,"P"
61          17,16,1,32,3,"Q"
62          12,25,13,39,1,"R"
63          22,25,10,1023,1,"S"
64          18,16,1,64,3,"T"
65          19,14,1,128,4,"U"
66          20,14,1,256,4,"V"
67          21,14,1,512,4,"W"
68          23,25,1,1024,1,"sun.misc.Cleaner"
69        """))
70
71  def test_heap_graph_super_root_fn(self):
72    return DiffTestBlueprint(
73        trace=Path('heap_graph_for_dominator_tree.textproto'),
74        query="""
75          INCLUDE PERFETTO MODULE memory.heap_graph_dominator_tree;
76
77          SELECT memory_heap_graph_super_root_fn();
78        """,
79        out=Csv("""
80          "memory_heap_graph_super_root_fn()"
81          25
82        """))
83