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 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 consumer_id, name, consumer_type, ordinal 29 FROM energy_counter_track; 30 """, 31 out=Csv(""" 32 "consumer_id","name","consumer_type","ordinal" 33 0,"CPUCL0","CPU_CLUSTER",0 34 """)) 35 36 def test_energy_breakdown_event(self): 37 return DiffTestBlueprint( 38 trace=Path('energy_breakdown.textproto'), 39 query=""" 40 SELECT ts, value 41 FROM counter 42 JOIN energy_counter_track ON counter.track_id = energy_counter_track.id 43 ORDER BY ts; 44 """, 45 out=Csv(""" 46 "ts","value" 47 1030255882785,98567522.000000 48 """)) 49 50 def test_energy_breakdown_uid_table(self): 51 return DiffTestBlueprint( 52 trace=Path('energy_breakdown_uid.textproto'), 53 query=""" 54 SELECT uid, name 55 FROM uid_counter_track; 56 """, 57 out=Csv(""" 58 "uid","name" 59 10234,"GPU" 60 10190,"GPU" 61 10235,"GPU" 62 """)) 63 64 def test_energy_breakdown_uid_event(self): 65 return DiffTestBlueprint( 66 trace=Path('energy_breakdown_uid.textproto'), 67 query=""" 68 SELECT ts, value 69 FROM counter 70 JOIN uid_counter_track ON counter.track_id = uid_counter_track.id 71 ORDER BY ts; 72 """, 73 out=Csv(""" 74 "ts","value" 75 1026753926322,3004536.000000 76 1026753926322,0.000000 77 1026753926322,4002274.000000 78 """)) 79 80 def test_energy_per_uid_table(self): 81 return DiffTestBlueprint( 82 trace=Path('energy_breakdown_uid.textproto'), 83 query=""" 84 SELECT consumer_id, uid 85 FROM energy_per_uid_counter_track; 86 """, 87 out=Csv(""" 88 "consumer_id","uid" 89 3,10234 90 3,10190 91 3,10235 92 """)) 93