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