• 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            }
76            samples {
77              ts: 10
78              heap_size: 1760
79              heap_native_size: 0
80              reachable_heap_size: 352
81              reachable_heap_native_size: 0
82              obj_count: 6
83              reachable_obj_count: 3
84              anon_rss_and_swap_size: 4096000
85              oom_score_adj: 0
86              roots {
87                root_type: "ROOT_JAVA_FRAME"
88                type_name: "DeobfuscatedA[]"
89                obj_count: 1
90              }
91              roots {
92                root_type: "ROOT_JAVA_FRAME"
93                type_name: "FactoryProducerDelegateImplActor"
94                obj_count: 1
95              }
96            }
97          }
98        }
99        """))
100
101  def test_heap_stats_closest_proc(self):
102    return DiffTestBlueprint(
103        trace=Path('heap_graph_closest_proc.textproto'),
104        query=Metric('java_heap_stats'),
105        out=Path('heap_stats_closest_proc.out'))
106
107  def test_java_heap_histogram(self):
108    return DiffTestBlueprint(
109        trace=Path('heap_graph.textproto'),
110        query=Metric('java_heap_histogram'),
111        out=Path('java_heap_histogram.out'))
112