• 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 MemoryMetrics(TestSuite):
23
24  def test_android_mem_counters(self):
25    return DiffTestBlueprint(
26        trace=DataPath('memory_counters.pb'),
27        query=Metric('android_mem'),
28        out=Path('android_mem_counters.out'))
29
30  def test_trace_metadata(self):
31    return DiffTestBlueprint(
32        trace=DataPath('memory_counters.pb'),
33        query=Metric('trace_metadata'),
34        out=Path('trace_metadata.out'))
35
36  def test_android_mem_by_priority(self):
37    return DiffTestBlueprint(
38        trace=Path('android_mem_by_priority.py'),
39        query=Metric('android_mem'),
40        out=Path('android_mem_by_priority.out'))
41
42  def test_android_mem_lmk(self):
43    return DiffTestBlueprint(
44        trace=Path('android_systrace_lmk.py'),
45        query=Metric('android_lmk'),
46        out=TextProto(r"""
47        android_lmk {
48          total_count: 1
49            by_oom_score {
50            oom_score_adj: 900
51            count: 1
52          }
53          oom_victim_count: 0
54        }
55        """))
56
57  def test_android_lmk_oom(self):
58    return DiffTestBlueprint(
59        trace=TextProto(r"""
60        packet {
61          process_tree {
62            processes {
63              pid: 1000
64              ppid: 1
65              cmdline: "com.google.android.gm"
66            }
67            threads {
68              tid: 1001
69              tgid: 1000
70            }
71          }
72        }
73        packet {
74          ftrace_events {
75            cpu: 4
76            event {
77              timestamp: 1234
78              pid: 4321
79              mark_victim {
80                pid: 1001
81              }
82            }
83          }
84        }
85        """),
86        query=Metric('android_lmk'),
87        out=TextProto(r"""
88        android_lmk {
89          total_count: 0
90          oom_victim_count: 1
91        }
92        """))
93
94  def test_android_mem_delta(self):
95    return DiffTestBlueprint(
96        trace=Path('android_mem_delta.py'),
97        query=Metric('android_mem'),
98        out=TextProto(r"""
99        android_mem {
100          process_metrics {
101            process_name: "com.my.pkg"
102            total_counters {
103              file_rss {
104                min: 2000.0
105                max: 10000.0
106                avg: 6666.666666666667
107                delta: 7000.0
108              }
109            }
110          }
111        }
112        """))
113