• 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 PowerPowerRails(TestSuite):
23
24  def test_android_power_rails_counters(self):
25    return DiffTestBlueprint(
26        trace=DataPath('power_rails.pb'),
27        query="""
28        INCLUDE PERFETTO MODULE android.power_rails;
29        SELECT
30        power_rail_name, AVG(value), COUNT(*)
31        FROM android_power_rails_counters
32        GROUP BY 1
33        LIMIT 20;
34      """,
35        out=Csv("""
36        "power_rail_name","AVG(value)","COUNT(*)"
37        "power.PPVAR_VPH_PWR_ABH_uws",7380269.414634,41
38        "power.PPVAR_VPH_PWR_OLED_uws",202362991.655738,61
39        """))
40
41  def test_power_rails_power_rails(self):
42    return DiffTestBlueprint(
43        trace=DataPath('power_rails.pb'),
44        query="""
45        SELECT name, AVG(value), COUNT(*)
46        FROM counters
47        WHERE name GLOB "power.*"
48        GROUP BY name
49        LIMIT 20;
50        """,
51        out=Csv("""
52        "name","AVG(value)","COUNT(*)"
53        "power.PPVAR_VPH_PWR_ABH_uws",7390700.360656,61
54        "power.PPVAR_VPH_PWR_OLED_uws",202362991.655738,61
55        """))
56
57  def test_power_rails_event_power_rails_custom_clock(self):
58    return DiffTestBlueprint(
59        trace=Path('power_rails_custom_clock.textproto'),
60        query="""
61        SELECT ts, value
62        FROM counters
63        WHERE name GLOB "power.*"
64        LIMIT 20;
65        """,
66        out=Csv("""
67        "ts","value"
68        104000000,333.000000
69        106000000,666.000000
70        106000000,999.000000
71        109000000,0.000000
72        """))
73
74  def test_power_rails_timestamp_sort(self):
75    return DiffTestBlueprint(
76        trace=Path('power_rails.textproto'),
77        query="""
78        SELECT ts, extract_arg(arg_set_id,'packet_ts') as packet_ts, value, t.name AS name
79        FROM counter c JOIN counter_track t ON t.id = c.track_id
80        ORDER BY ts
81        LIMIT 20;
82        """,
83        out=Csv("""
84        "ts","packet_ts","value","name"
85        3000000,3000003,333.000000,"power.test_rail_uws"
86        3000000,3000005,0.000000,"power.test_rail_uws"
87        3000004,"[NULL]",1000.000000,"Testing"
88        3000005,3000005,999.000000,"power.test_rail2_uws"
89        5000000,3000005,666.000000,"power.test_rail_uws"
90        """))
91
92  def test_power_rails_well_known_power_rails(self):
93    return DiffTestBlueprint(
94        trace=TextProto(r"""
95        packet {
96          power_rails {
97            rail_descriptor {
98              index: 4
99              rail_name: "S3M_VDD_CPUCL1"
100              subsys_name: "cpu"
101              sampling_rate: 1023
102            }
103          }
104        }
105        packet {
106          timestamp: 3000003
107          power_rails {
108            energy_data {
109              index: 4
110              timestamp_ms: 3
111              energy: 333
112            }
113          }
114        }
115        packet {
116          timestamp: 3000005
117          power_rails {
118            rail_descriptor {
119              index: 3
120              rail_name: "S2S_VDD_G3D"
121              subsys_name: "gpu"
122              sampling_rate: 1022
123            }
124            energy_data {
125              index: 4
126              timestamp_ms: 5
127              energy: 666
128            }
129            energy_data {
130              index: 3
131              energy: 999
132            }
133            energy_data {
134              index: 4
135              timestamp_ms: 3
136              energy: 0
137            }
138          }
139        }
140        """),
141        query="""
142        SELECT name, AVG(value), COUNT(*)
143        FROM counters
144        WHERE name GLOB "power.*"
145        GROUP BY name
146        LIMIT 20;
147        """,
148        out=Csv("""
149        "name","AVG(value)","COUNT(*)"
150        "power.rails.cpu.mid",333.000000,3
151        "power.rails.gpu",999.000000,1
152        """))
153