• 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, TraceInjector
19from python.generators.diff_tests.testing import TestSuite
20
21
22class PowerEnergyBreakdown(TestSuite):
23  # Energy Estimation Breakdown
24  def test_energy_breakdown_table(self):
25    return DiffTestBlueprint(
26        trace=Path('energy_breakdown.textproto'),
27        query="""
28        SELECT
29          EXTRACT_ARG(
30            dimension_arg_set_id,
31            'energy_consumer_id'
32          ) AS consumer_id,
33          name,
34          EXTRACT_ARG(source_arg_set_id, 'consumer_type') AS consumer_type,
35          EXTRACT_ARG(source_arg_set_id, 'ordinal') AS ordinal
36        FROM track
37        WHERE type = 'android_energy_estimation_breakdown';
38        """,
39        out=Csv("""
40        "consumer_id","name","consumer_type","ordinal"
41        0,"CPUCL0","CPU_CLUSTER",0
42        """))
43
44  def test_energy_breakdown_event(self):
45    return DiffTestBlueprint(
46        trace=Path('energy_breakdown.textproto'),
47        query="""
48        SELECT ts, value
49        FROM counter
50        JOIN track ON counter.track_id = track.id
51        ORDER BY ts;
52        """,
53        out=Csv("""
54        "ts","value"
55        1030255882785,98567522.000000
56        """))
57
58  def test_energy_per_uid_table(self):
59    return DiffTestBlueprint(
60        trace=Path('energy_breakdown_uid.textproto'),
61        query="""
62        SELECT
63          EXTRACT_ARG(
64            dimension_arg_set_id,
65            'energy_consumer_id'
66          ) AS consumer_id,
67          EXTRACT_ARG(dimension_arg_set_id, 'uid') AS uid
68        FROM track
69        WHERE type = 'android_energy_estimation_breakdown_per_uid';
70        """,
71        out=Csv("""
72        "consumer_id","uid"
73        3,10234
74        3,10190
75        3,10235
76        """))
77
78  def test_energy_breakdown_uid_table_machine_id(self):
79    return DiffTestBlueprint(
80        trace=Path('energy_breakdown_uid.textproto'),
81        trace_modifier=TraceInjector(['android_energy_estimation_breakdown'],
82                                     {'machine_id': 1001}),
83        query="""
84        SELECT
85          EXTRACT_ARG(dimension_arg_set_id, 'uid') AS uid,
86          name
87        FROM track
88        WHERE type = 'android_energy_estimation_breakdown_per_uid'
89          AND machine_id IS NOT NULL;
90        """,
91        out=Csv("""
92        "uid","name"
93        10234,"GPU"
94        10190,"GPU"
95        10235,"GPU"
96        """))
97
98  def test_energy_breakdown_table_machine_id(self):
99    return DiffTestBlueprint(
100        trace=Path('energy_breakdown.textproto'),
101        trace_modifier=TraceInjector(['android_energy_estimation_breakdown'],
102                                     {'machine_id': 1001}),
103        query="""
104        SELECT
105          EXTRACT_ARG(
106            dimension_arg_set_id,
107            'energy_consumer_id'
108          ) AS consumer_id,
109          name,
110          EXTRACT_ARG(source_arg_set_id, 'consumer_type') AS consumer_type,
111          EXTRACT_ARG(source_arg_set_id, 'ordinal') AS ordinal
112        FROM track
113        WHERE type = 'android_energy_estimation_breakdown'
114          AND machine_id IS NOT NULL;
115        """,
116        out=Csv("""
117        "consumer_id","name","consumer_type","ordinal"
118        0,"CPUCL0","CPU_CLUSTER",0
119        """))
120