• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (C) 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 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, DataPath, Metric
17from python.generators.diff_tests.testing import Csv, Json, TextProto
18from python.generators.diff_tests.testing import DiffTestBlueprint
19from python.generators.diff_tests.testing import TestSuite
20
21
22class ProfilingMetrics(TestSuite):
23
24  def test_unsymbolized_frames(self):
25    return DiffTestBlueprint(
26        trace=Path('heap_profile_no_symbols.textproto'),
27        query=Metric('unsymbolized_frames'),
28        out=TextProto(r"""
29        unsymbolized_frames {
30          frames {
31            module: "/liblib.so"
32            build_id: "6275696c642d6964"
33            address: 4096
34            google_lookup_id: "6275696c642d6964"
35          }
36          frames {
37            module: "/liblib.so"
38            build_id: "6275696c642d6964"
39            address: 8192
40            google_lookup_id: "6275696c642d6964"
41          }
42          frames {
43            module: "/libmonochrome_64.so"
44            build_id: "7f0715c286f8b16c10e4ad349cda3b9b56c7a773"
45            address: 4096
46            google_lookup_id: "c215077ff8866cb110e4ad349cda3b9b0"
47          }
48          frames {
49            module: "/libmonochrome_64.so"
50            build_id: "7f0715c286f8b16c10e4ad349cda3b9b56c7a773"
51            address: 8192
52            google_lookup_id: "c215077ff8866cb110e4ad349cda3b9b0"
53          }
54        }
55        """))
56
57  def test_simpleperf_event(self):
58    return DiffTestBlueprint(
59        trace=Path('simpleperf_event.py'),
60        query=Metric('android_simpleperf'),
61        out=Path('simpleperf_event.out'))
62
63  def test_java_heap_stats(self):
64    return DiffTestBlueprint(
65        trace=Path('heap_graph.textproto'),
66        query=Metric('java_heap_stats'),
67        out=TextProto(r"""
68        java_heap_stats {
69          instance_stats {
70            upid: 2
71            process {
72              name: "system_server"
73              uid: 1000
74              pid: 2
75              android_user_id: 0
76              is_kernel_task: false
77            }
78            samples {
79              ts: 10
80              heap_size: 1760
81              heap_native_size: 0
82              reachable_heap_size: 352
83              reachable_heap_native_size: 0
84              obj_count: 6
85              reachable_obj_count: 3
86              anon_rss_and_swap_size: 4096000
87              oom_score_adj: 0
88              roots {
89                root_type: "ROOT_JAVA_FRAME"
90                type_name: "DeobfuscatedA[]"
91                obj_count: 1
92              }
93              roots {
94                root_type: "ROOT_JAVA_FRAME"
95                type_name: "FactoryProducerDelegateImplActor"
96                obj_count: 1
97              }
98            }
99          }
100        }
101        """))
102
103  def test_heap_stats_closest_proc(self):
104    return DiffTestBlueprint(
105        trace=Path('heap_graph_closest_proc.textproto'),
106        query=Metric('java_heap_stats'),
107        out=Path('heap_stats_closest_proc.out'))
108
109  def test_java_heap_histogram(self):
110    return DiffTestBlueprint(
111        trace=Path('heap_graph.textproto'),
112        query=Metric('java_heap_histogram'),
113        out=Path('java_heap_histogram.out'))
114
115  def test_java_heap_class_stats(self):
116    return DiffTestBlueprint(
117        trace=Path('heap_graph.textproto'),
118        query=Metric('java_heap_class_stats'),
119        out=Path('java_heap_class_stats.out'))
120
121  def test_java_heap_class_stats_no_heap_graph(self):
122    return DiffTestBlueprint(
123        trace=Path('heap_profile_no_symbols.textproto'),
124        query=Metric('java_heap_class_stats'),
125        out=TextProto(r"""
126        java_heap_class_stats {
127        }
128        """))
129