1#!/usr/bin/env python3 2# Copyright (C) 2024 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 Csv, Path, DataPath 17from python.generators.diff_tests.testing import DiffTestBlueprint 18from python.generators.diff_tests.testing import TestSuite 19 20 21class WattsonStdlib(TestSuite): 22 consolidate_tables_template = (''' 23 SELECT 24 sum(dur) as duration, 25 SUM(l3_hit_count) AS l3_hit_count, 26 SUM(l3_miss_count) AS l3_miss_count, 27 freq_0, idle_0, freq_1, idle_1, freq_2, idle_2, freq_3, idle_3, 28 freq_4, idle_4, freq_5, idle_5, freq_6, idle_6, freq_7, idle_7, 29 suspended 30 FROM SYSTEM_STATE_TABLE 31 GROUP BY 32 freq_0, idle_0, freq_1, idle_1, freq_2, idle_2, freq_3, idle_3, 33 freq_4, idle_4, freq_5, idle_5, freq_6, idle_6, freq_7, idle_7, 34 suspended 35 ORDER BY duration desc 36 LIMIT 20; 37 ''') 38 39 # Test raw system state before any grouping 40 def test_wattson_system_state(self): 41 return DiffTestBlueprint( 42 trace=DataPath('wattson_dsu_pmu.pb'), 43 query=""" 44 INCLUDE PERFETTO MODULE wattson.system_state; 45 SELECT * from _wattson_system_states 46 ORDER by ts DESC 47 LIMIT 20 48 """, 49 out=Csv(""" 50 "ts","dur","l3_hit_count","l3_miss_count","freq_0","idle_0","freq_1","idle_1","freq_2","idle_2","freq_3","idle_3","freq_4","idle_4","freq_5","idle_5","freq_6","idle_6","freq_7","idle_7","suspended" 51 370103436540,339437,"[NULL]","[NULL]",738000,-1,738000,1,738000,-1,738000,-1,400000,-1,400000,1,1106000,1,1106000,1,0 52 370103419857,16683,"[NULL]","[NULL]",738000,-1,738000,1,738000,1,738000,-1,400000,-1,400000,1,1106000,1,1106000,1,0 53 370103213314,206543,"[NULL]","[NULL]",738000,1,738000,1,738000,1,738000,-1,400000,-1,400000,1,1106000,1,1106000,1,0 54 370103079729,133585,"[NULL]","[NULL]",738000,1,738000,1,738000,1,738000,-1,400000,-1,400000,1,1106000,-1,1106000,1,0 55 370102869076,210653,"[NULL]","[NULL]",738000,1,738000,1,738000,1,738000,-1,400000,1,400000,1,1106000,-1,1106000,1,0 56 370102837378,31698,"[NULL]","[NULL]",738000,1,738000,1,738000,-1,738000,-1,400000,1,400000,1,1106000,-1,1106000,1,0 57 370102832862,4516,"[NULL]","[NULL]",738000,1,738000,1,738000,-1,738000,-1,400000,1,400000,1,1106000,-1,1106000,-1,0 58 370102831844,1018,"[NULL]","[NULL]",738000,1,738000,1,738000,-1,738000,-1,400000,1,400000,1,1106000,-1,984000,-1,0 59 370102819475,12369,"[NULL]","[NULL]",738000,1,738000,1,738000,-1,738000,-1,400000,1,400000,1,984000,-1,984000,-1,0 60 370102816586,1098,"[NULL]","[NULL]",738000,1,574000,1,574000,-1,574000,-1,400000,1,400000,1,984000,-1,984000,-1,0 61 370102669043,147543,"[NULL]","[NULL]",574000,1,574000,1,574000,-1,574000,-1,400000,1,400000,1,984000,-1,984000,-1,0 62 370102044564,624479,"[NULL]","[NULL]",574000,1,574000,1,574000,-1,574000,1,400000,1,400000,1,984000,-1,984000,-1,0 63 370100810360,1234204,"[NULL]","[NULL]",574000,1,574000,1,574000,-1,574000,1,400000,1,400000,1,984000,1,984000,-1,0 64 370100731096,79264,"[NULL]","[NULL]",574000,1,574000,1,574000,-1,574000,-1,400000,1,400000,1,984000,1,984000,-1,0 65 370100411312,319784,"[NULL]","[NULL]",574000,1,574000,1,574000,1,574000,-1,400000,1,400000,1,984000,1,984000,-1,0 66 370100224219,187093,"[NULL]","[NULL]",574000,-1,574000,1,574000,1,574000,-1,400000,1,400000,1,984000,1,984000,-1,0 67 370100171729,52490,"[NULL]","[NULL]",574000,1,574000,1,574000,1,574000,-1,400000,1,400000,1,984000,1,984000,-1,0 68 370096452775,3718954,"[NULL]","[NULL]",574000,1,574000,1,574000,1,574000,1,400000,1,400000,1,984000,1,984000,-1,0 69 370096412858,39917,"[NULL]","[NULL]",574000,-1,574000,1,574000,1,574000,1,400000,1,400000,1,984000,1,984000,-1,0 70 370096347307,65551,"[NULL]","[NULL]",574000,-1,574000,1,574000,1,574000,1,400000,1,400000,1,984000,-1,984000,-1,0 71 """)) 72 73 # Test fixup of deep idle offset and time marker window. 74 def test_wattson_time_window(self): 75 return DiffTestBlueprint( 76 trace=DataPath('wattson_dsu_pmu.pb'), 77 query=""" 78 INCLUDE PERFETTO MODULE wattson.system_state; 79 80 CREATE PERFETTO TABLE wattson_time_window 81 AS 82 SELECT 362426061658 AS ts, 5067704349 AS dur; 83 84 -- Final table that is cut off to fit within the requested time window. 85 CREATE VIRTUAL TABLE time_window_intersect 86 USING SPAN_JOIN(_wattson_system_states, wattson_time_window); 87 """ + self.consolidate_tables_template.replace("SYSTEM_STATE_TABLE", 88 "time_window_intersect"), 89 out=Csv(""" 90 "duration","l3_hit_count","l3_miss_count","freq_0","idle_0","freq_1","idle_1","freq_2","idle_2","freq_3","idle_3","freq_4","idle_4","freq_5","idle_5","freq_6","idle_6","freq_7","idle_7","suspended" 91 59232508,2796301,1232977,574000,0,574000,1,574000,1,574000,0,553000,0,553000,0,500000,1,500000,0,0 92 50664181,2364802,1133322,574000,0,574000,1,574000,1,574000,0,553000,1,553000,0,500000,0,500000,0,0 93 41917186,2020898,920691,574000,0,574000,0,574000,1,574000,1,553000,0,553000,0,500000,0,500000,1,0 94 33778317,1478303,683731,300000,0,300000,0,300000,1,300000,1,400000,0,400000,0,500000,0,500000,1,0 95 32703489,1428203,690001,300000,0,300000,0,300000,1,300000,0,400000,0,400000,0,500000,0,500000,0,0 96 28770906,1588177,715673,574000,0,574000,0,574000,1,574000,0,553000,1,553000,0,500000,1,500000,0,0 97 28310872,1211262,566873,300000,0,300000,1,300000,1,300000,0,400000,0,400000,0,500000,0,500000,0,0 98 26754474,1224826,569901,300000,0,300000,1,300000,0,300000,0,400000,1,400000,0,500000,0,500000,0,0 99 24816645,1047517,467614,300000,0,300000,1,300000,1,300000,0,400000,0,400000,0,500000,1,500000,0,0 100 24251986,984546,417947,300000,0,300000,0,300000,1,300000,0,400000,1,400000,0,500000,1,500000,0,0 101 23771603,987803,450930,300000,0,300000,1,300000,1,300000,0,400000,1,400000,0,500000,0,500000,0,0 102 22988523,984240,473025,300000,0,300000,0,300000,1,300000,0,400000,0,400000,0,500000,0,500000,1,0 103 22057168,998933,453689,300000,0,300000,1,300000,1,300000,0,400000,0,400000,0,500000,0,500000,1,0 104 21663200,1034424,445500,574000,0,574000,0,574000,1,574000,0,553000,0,553000,0,500000,0,500000,1,0 105 20665650,974100,442861,300000,0,300000,0,300000,1,300000,0,400000,0,400000,1,500000,0,500000,0,0 106 18224891,834959,345078,300000,0,300000,1,300000,0,300000,0,400000,0,400000,0,500000,1,500000,0,0 107 17469272,816735,342795,574000,0,574000,0,574000,0,574000,0,553000,1,553000,0,500000,1,500000,0,0 108 16560058,754170,344777,574000,0,574000,1,574000,1,574000,0,553000,0,553000,0,500000,0,500000,1,0 109 16191449,689792,316923,300000,0,300000,0,300000,1,300000,0,400000,1,400000,0,500000,0,500000,0,0 110 16008137,748321,327736,574000,0,574000,1,574000,0,574000,1,553000,0,553000,0,500000,1,500000,0,0 111 """)) 112 113 # Test on Raven for checking system states and the DSU PMU counts. 114 def test_wattson_dsu_pmu(self): 115 return DiffTestBlueprint( 116 trace=DataPath('wattson_dsu_pmu.pb'), 117 query=("INCLUDE PERFETTO MODULE wattson.system_state;\n" + 118 self.consolidate_tables_template.replace( 119 "SYSTEM_STATE_TABLE", "_wattson_system_states")), 120 out=Csv(""" 121 "duration","l3_hit_count","l3_miss_count","freq_0","idle_0","freq_1","idle_1","freq_2","idle_2","freq_3","idle_3","freq_4","idle_4","freq_5","idle_5","freq_6","idle_6","freq_7","idle_7","suspended" 122 1280071578,1319309,419083,300000,1,300000,1,300000,1,300000,1,400000,1,400000,1,500000,1,500000,1,0 123 165833778,118250,42072,300000,-1,300000,1,300000,1,300000,1,400000,1,400000,1,500000,1,500000,1,0 124 121848767,5879527,2358273,574000,0,574000,1,574000,0,574000,0,553000,0,553000,0,500000,1,500000,1,0 125 72914132,134731,58480,300000,1,300000,1,300000,-1,300000,1,400000,1,400000,1,500000,1,500000,1,0 126 70723657,68341,22021,300000,1,300000,-1,300000,1,300000,1,400000,1,400000,1,500000,1,500000,1,0 127 64738046,275953,309822,300000,1,300000,1,300000,1,300000,1,400000,1,400000,1,500000,-1,500000,1,0 128 59232508,2796301,1232977,574000,0,574000,1,574000,1,574000,0,553000,0,553000,0,500000,1,500000,0,0 129 50960835,50577,17976,300000,1,300000,1,300000,1,300000,-1,400000,1,400000,1,500000,1,500000,1,0 130 50664181,2364802,1133322,574000,0,574000,1,574000,1,574000,0,553000,1,553000,0,500000,0,500000,0,0 131 49614333,2201254,928640,300000,0,300000,1,300000,0,300000,0,400000,0,400000,0,500000,1,500000,1,0 132 41917186,2020898,920691,574000,0,574000,0,574000,1,574000,1,553000,0,553000,0,500000,0,500000,1,0 133 40469221,"[NULL]","[NULL]",1401000,1,1401000,1,1401000,1,1401000,1,400000,1,400000,1,2802000,1,2802000,1,0 134 40265209,14021,1245,300000,0,300000,1,300000,1,300000,1,400000,1,400000,1,500000,1,500000,1,0 135 38159789,1428203,690001,300000,0,300000,0,300000,1,300000,0,400000,0,400000,0,500000,0,500000,0,0 136 33778317,1478303,683731,300000,0,300000,0,300000,1,300000,1,400000,0,400000,0,500000,0,500000,1,0 137 31421773,34528,17983,300000,1,300000,1,300000,1,300000,1,400000,-1,400000,1,500000,1,500000,1,0 138 31137678,162530,198792,1098000,1,1098000,1,1098000,1,1098000,1,400000,1,400000,1,500000,1,500000,-1,0 139 30271091,38946,48402,300000,1,300000,1,300000,1,300000,1,400000,1,400000,1,500000,1,500000,-1,0 140 30209881,"[NULL]","[NULL]",1328000,1,1328000,1,1328000,1,1328000,1,2253000,1,2253000,1,500000,1,500000,1,0 141 30118849,1394832,585081,574000,0,574000,1,574000,0,574000,0,553000,0,553000,0,500000,1,500000,0,0 142 """)) 143 144 # Test on eos to check that suspend states are being calculated appropriately. 145 def test_wattson_suspend(self): 146 return DiffTestBlueprint( 147 trace=DataPath('wattson_eos_suspend.pb'), 148 query=""" 149 INCLUDE PERFETTO MODULE wattson.system_state; 150 SELECT 151 sum(dur) as duration, 152 freq_0, idle_0, freq_1, idle_1, freq_2, idle_2, freq_3, idle_3, 153 suspended 154 FROM _wattson_system_states 155 GROUP BY 156 freq_0, idle_0, freq_1, idle_1, freq_2, idle_2, freq_3, idle_3, 157 suspended 158 ORDER BY duration desc 159 LIMIT 20; 160 """, 161 out=Csv(""" 162 "duration","freq_0","idle_0","freq_1","idle_1","freq_2","idle_2","freq_3","idle_3","suspended" 163 16606175990,614400,1,614400,1,614400,1,614400,1,0 164 10648392546,1708800,1,1708800,1,1708800,1,1708800,1,1 165 6972220533,1708800,-1,1708800,-1,1708800,-1,1708800,-1,0 166 1649400745,614400,0,614400,0,614400,0,614400,0,0 167 1206977074,614400,-1,614400,1,614400,1,614400,1,0 168 945900007,1708800,0,1708800,0,1708800,0,1708800,0,0 169 943703078,1363200,0,1363200,0,1363200,0,1363200,1,0 170 736663600,1708800,0,1708800,0,1708800,0,1708800,1,0 171 706695995,1708800,1,1708800,1,1708800,1,1708800,1,0 172 656873956,1363200,1,1363200,1,1363200,1,1363200,1,0 173 633440914,1363200,0,1363200,0,1363200,0,1363200,0,0 174 627957352,1708800,-1,1708800,0,1708800,0,1708800,0,0 175 615611076,1708800,-1,1708800,1,1708800,1,1708800,1,0 176 575584212,1708800,-1,1708800,0,1708800,0,1708800,-1,0 177 527581753,1708800,-1,1708800,-1,1708800,0,1708800,-1,0 178 488107828,1708800,0,1708800,0,1708800,0,1708800,-1,0 179 474912603,1363200,-1,1363200,0,1363200,0,1363200,1,0 180 461943392,1708800,0,1708800,-1,1708800,0,1708800,0,0 181 375051979,864000,1,864000,1,864000,1,864000,1,0 182 371458882,1363200,-1,1363200,0,1363200,0,1363200,-1,0 183 """)) 184 185 # Test that the device name can be extracted from the trace's metadata. 186 def test_wattson_device_name(self): 187 return DiffTestBlueprint( 188 trace=DataPath('wattson_wo_device_name.pb'), 189 query=(""" 190 INCLUDE PERFETTO MODULE wattson.device_infos; 191 select name from _wattson_device 192 """), 193 out=Csv(""" 194 "name" 195 "monaco" 196 """)) 197 198 # Tests intermediate table 199 def test_wattson_intermediate_table(self): 200 return DiffTestBlueprint( 201 trace=DataPath('wattson_dsu_pmu.pb'), 202 query=(""" 203 INCLUDE PERFETTO MODULE wattson.curves.estimates; 204 select 205 ts,dur,l3_hit_count,l3_miss_count,freq_0,idle_0,freq_1,idle_1,freq_2,idle_2,freq_3,idle_3,freq_4,idle_4,freq_5,idle_5,freq_6,idle_6,freq_7,idle_7,policy_4,policy_5,policy_6,policy_7,no_static,cpu0_curve,cpu1_curve,cpu2_curve,cpu3_curve,cpu4_curve,cpu5_curve,cpu6_curve,cpu7_curve,static_4,static_5,static_6,static_7 206 from _w_independent_cpus_calc 207 WHERE ts > 359661672577 208 ORDER by ts ASC 209 LIMIT 10 210 """), 211 out=Csv(""" 212 "ts","dur","l3_hit_count","l3_miss_count","freq_0","idle_0","freq_1","idle_1","freq_2","idle_2","freq_3","idle_3","freq_4","idle_4","freq_5","idle_5","freq_6","idle_6","freq_7","idle_7","policy_4","policy_5","policy_6","policy_7","no_static","cpu0_curve","cpu1_curve","cpu2_curve","cpu3_curve","cpu4_curve","cpu5_curve","cpu6_curve","cpu7_curve","static_4","static_5","static_6","static_7" 213 359661672578,75521,8326,9689,1401000,0,1401000,0,1401000,0,1401000,0,2253000,-1,2253000,0,2802000,-1,2802000,0,4,4,6,6,0,"[NULL]","[NULL]","[NULL]","[NULL]",527.050000,23.500000,1942.890000,121.430000,35.660000,-1.000000,35.640000,-1.000000 214 359661748099,2254517,248577,289258,1401000,0,1401000,0,1401000,0,1401000,0,2253000,0,2253000,0,2802000,-1,2802000,0,4,4,6,6,0,"[NULL]","[NULL]","[NULL]","[NULL]",23.500000,23.500000,1942.890000,121.430000,-1.000000,-1.000000,35.640000,-1.000000 215 359664003674,11596,1278,1487,1401000,-1,1401000,-1,1401000,-1,1401000,-1,2253000,-1,2253000,-1,2802000,-1,2802000,-1,4,4,6,6,-1,"[NULL]","[NULL]","[NULL]","[NULL]",527.050000,527.050000,1942.890000,1942.890000,35.660000,35.660000,35.640000,35.640000 216 359664015270,4720,520,605,1401000,-1,1401000,-1,1401000,-1,1401000,-1,2253000,-1,2253000,-1,2802000,-1,2802000,0,4,4,6,6,-1,"[NULL]","[NULL]","[NULL]","[NULL]",527.050000,527.050000,1942.890000,121.430000,35.660000,35.660000,35.640000,-1.000000 217 359664019990,18921,2086,2427,1401000,-1,1401000,-1,1401000,-1,1401000,-1,2253000,0,2253000,-1,2802000,-1,2802000,0,4,4,6,6,-1,"[NULL]","[NULL]","[NULL]","[NULL]",23.500000,527.050000,1942.890000,121.430000,-1.000000,35.660000,35.640000,-1.000000 218 359664038911,8871,978,1138,1401000,-1,1401000,-1,1401000,0,1401000,-1,2253000,0,2253000,-1,2802000,-1,2802000,0,4,4,6,6,-1,"[NULL]","[NULL]","[NULL]","[NULL]",23.500000,527.050000,1942.890000,121.430000,-1.000000,35.660000,35.640000,-1.000000 219 359664047782,1343,148,172,1401000,-1,1401000,0,1401000,0,1401000,-1,2253000,0,2253000,-1,2802000,-1,2802000,0,4,4,6,6,-1,"[NULL]","[NULL]","[NULL]","[NULL]",23.500000,527.050000,1942.890000,121.430000,-1.000000,35.660000,35.640000,-1.000000 220 359664049491,1383,152,177,1401000,0,1401000,0,1401000,0,1401000,-1,2253000,0,2253000,0,2802000,-1,2802000,0,4,4,6,6,-1,"[NULL]","[NULL]","[NULL]","[NULL]",23.500000,23.500000,1942.890000,121.430000,-1.000000,-1.000000,35.640000,-1.000000 221 359664050874,2409912,265711,309195,1401000,0,1401000,0,1401000,0,1401000,0,2253000,0,2253000,0,2802000,-1,2802000,0,4,4,6,6,0,"[NULL]","[NULL]","[NULL]","[NULL]",23.500000,23.500000,1942.890000,121.430000,-1.000000,-1.000000,35.640000,-1.000000 222 359666460786,13754,1516,1764,1401000,0,1401000,0,1401000,0,1401000,0,2253000,-1,2253000,0,2802000,-1,2802000,0,4,4,6,6,0,"[NULL]","[NULL]","[NULL]","[NULL]",527.050000,23.500000,1942.890000,121.430000,35.660000,-1.000000,35.640000,-1.000000 223 """)) 224 225 # Tests that device static curve selection is only when CPUs are active 226 def test_wattson_static_curve_selection(self): 227 return DiffTestBlueprint( 228 trace=DataPath('wattson_dsu_pmu.pb'), 229 query=(""" 230 INCLUDE PERFETTO MODULE wattson.curves.estimates; 231 select * from _system_state_curves 232 ORDER by ts ASC 233 LIMIT 5 234 """), 235 out=Csv(""" 236 "ts","dur","cpu0_curve","cpu1_curve","cpu2_curve","cpu3_curve","cpu4_curve","cpu5_curve","cpu6_curve","cpu7_curve","static_curve","l3_hit_value","l3_miss_value" 237 359085636893,23030,0.000000,"[NULL]",0.000000,0.000000,0.000000,28.510000,0.000000,0.000000,0.000000,"[NULL]","[NULL]" 238 359085659923,6664673,0.000000,"[NULL]",0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 239 359092324596,1399699,0.000000,"[NULL]",0.000000,21.840000,0.000000,0.000000,0.000000,0.000000,3.730000,"[NULL]","[NULL]" 240 359093724295,6959391,0.000000,"[NULL]",0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 241 359100683686,375122,0.000000,"[NULL]",0.000000,0.000000,28.510000,0.000000,0.000000,0.000000,0.000000,"[NULL]","[NULL]" 242 """)) 243 244 # Tests that L3 cache calculations are being done correctly 245 def test_wattson_l3_calculations(self): 246 return DiffTestBlueprint( 247 trace=DataPath('wattson_dsu_pmu.pb'), 248 query=(""" 249 INCLUDE PERFETTO MODULE wattson.curves.estimates; 250 select * from _system_state_curves 251 WHERE ts > 359661672577 252 ORDER by ts ASC 253 LIMIT 5 254 """), 255 out=Csv(""" 256 "ts","dur","cpu0_curve","cpu1_curve","cpu2_curve","cpu3_curve","cpu4_curve","cpu5_curve","cpu6_curve","cpu7_curve","static_curve","l3_hit_value","l3_miss_value" 257 359661672578,75521,3.410000,3.410000,3.410000,3.410000,527.050000,23.500000,1942.890000,121.430000,35.660000,16836.004600,1215.000600 258 359661748099,2254517,3.450000,3.450000,3.450000,3.450000,23.500000,23.500000,1942.890000,121.430000,35.640000,578637.540600,262212.377000 259 359664003674,11596,248.900000,248.900000,248.900000,248.900000,527.050000,527.050000,1942.890000,1942.890000,35.660000,2584.243800,186.469800 260 359664015270,4720,248.900000,248.900000,248.900000,248.900000,527.050000,527.050000,1942.890000,121.430000,35.660000,1051.492000,75.867000 261 359664019990,18921,248.900000,248.900000,248.900000,248.900000,23.500000,527.050000,1942.890000,121.430000,35.660000,4218.100600,304.345800 262 """)) 263 264 # Tests calculations when everything in system state is converted to mW 265 def test_wattson_system_state_mw_calculations(self): 266 return DiffTestBlueprint( 267 trace=DataPath('wattson_dsu_pmu.pb'), 268 query=(""" 269 INCLUDE PERFETTO MODULE wattson.curves.estimates; 270 select * from _system_state_mw 271 WHERE ts > 359661672577 272 ORDER by ts ASC 273 LIMIT 10 274 """), 275 out=Csv(""" 276 "ts","dur","cpu0_mw","cpu1_mw","cpu2_mw","cpu3_mw","cpu4_mw","cpu5_mw","cpu6_mw","cpu7_mw","dsu_scu_mw" 277 359661672578,75521,3.410000,3.410000,3.410000,3.410000,527.050000,23.500000,1942.890000,121.430000,274.679679 278 359661748099,2254517,3.450000,3.450000,3.450000,3.450000,23.500000,23.500000,1942.890000,121.430000,408.602332 279 359664003674,11596,248.900000,248.900000,248.900000,248.900000,527.050000,527.050000,1942.890000,1942.890000,274.597013 280 359664015270,4720,248.900000,248.900000,248.900000,248.900000,527.050000,527.050000,1942.890000,121.430000,274.507246 281 359664019990,18921,248.900000,248.900000,248.900000,248.900000,23.500000,527.050000,1942.890000,121.430000,274.677304 282 359664038911,8871,248.900000,248.900000,3.410000,248.900000,23.500000,527.050000,1942.890000,121.430000,274.676909 283 359664047782,1343,248.900000,3.410000,3.410000,248.900000,23.500000,527.050000,1942.890000,121.430000,274.557692 284 359664049491,1383,3.450000,3.450000,3.450000,208.140000,23.500000,23.500000,1942.890000,121.430000,407.495459 285 359664050874,2409912,3.450000,3.450000,3.450000,3.450000,23.500000,23.500000,1942.890000,121.430000,408.602720 286 359666460786,13754,3.410000,3.410000,3.410000,3.410000,527.050000,23.500000,1942.890000,121.430000,274.623880 287 """)) 288 289 # Tests that suspend values are being skipped 290 def test_wattson_suspend_calculations(self): 291 return DiffTestBlueprint( 292 trace=DataPath('wattson_eos_suspend.pb'), 293 query=(""" 294 INCLUDE PERFETTO MODULE wattson.curves.estimates; 295 select * from _system_state_curves 296 WHERE ts > 24790009884888 297 ORDER by ts ASC 298 LIMIT 5 299 """), 300 out=Csv(""" 301 "ts","dur","cpu0_curve","cpu1_curve","cpu2_curve","cpu3_curve","cpu4_curve","cpu5_curve","cpu6_curve","cpu7_curve","static_curve","l3_hit_value","l3_miss_value" 302 24790009907857,2784616769,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0 303 24792794524626,424063,39.690000,39.690000,39.690000,39.690000,0.000000,0.000000,0.000000,0.000000,18.390000,"[NULL]","[NULL]" 304 24792794948689,205625,39.690000,39.690000,39.690000,39.690000,0.000000,0.000000,0.000000,0.000000,18.390000,"[NULL]","[NULL]" 305 24792795154314,19531,39.690000,39.690000,39.690000,39.690000,0.000000,0.000000,0.000000,0.000000,18.390000,"[NULL]","[NULL]" 306 24792795173845,50781,39.690000,39.690000,0.000000,39.690000,0.000000,0.000000,0.000000,0.000000,18.390000,"[NULL]","[NULL]" 307 """)) 308 309 # Tests that total calculations are correct 310 def test_wattson_idle_attribution(self): 311 return DiffTestBlueprint( 312 trace=DataPath('wattson_eos_suspend.pb'), 313 query=(""" 314 INCLUDE PERFETTO MODULE wattson.curves.idle_attribution; 315 SELECT 316 SUM(estimated_mw * dur) / 1000000000 as idle_transition_cost_mws, 317 utid, 318 upid 319 FROM _idle_transition_cost 320 GROUP BY utid 321 ORDER BY idle_transition_cost_mws DESC 322 LIMIT 20 323 """), 324 out=Csv(""" 325 "idle_transition_cost_mws","utid","upid" 326 19.068358,10,10 327 7.642105,73,73 328 6.069991,146,146 329 4.887564,457,457 330 4.641823,694,353 331 4.575867,1262,401 332 4.513442,515,137 333 3.819375,169,169 334 3.803823,11,11 335 3.617314,147,147 336 3.522582,396,396 337 3.385840,486,486 338 3.351066,727,356 339 3.279231,606,326 340 3.155939,464,464 341 2.949362,29,29 342 2.848033,414,414 343 2.660892,471,471 344 2.573006,1270,401 345 2.488196,172,172 346 """)) 347 348 # Tests that DSU devfreq calculations are merged correctly 349 def test_wattson_dsu_devfreq(self): 350 return DiffTestBlueprint( 351 trace=DataPath('wattson_tk4_pcmark.pb'), 352 query=(""" 353 INCLUDE PERFETTO MODULE wattson.curves.w_dsu_dependence; 354 SELECT 355 ts,dur,freq_0,idle_0,freq_1,idle_1,freq_2,idle_2,freq_3,idle_3,cpu4_curve,cpu5_curve,cpu6_curve,cpu7_curve,l3_hit_count,l3_miss_count,no_static,all_cpu_deep_idle 356 FROM _cpu_curves 357 WHERE ts > 4108586775197 358 LIMIT 20 359 """), 360 out=Csv(""" 361 "ts","dur","freq_0","idle_0","freq_1","idle_1","freq_2","idle_2","freq_3","idle_3","cpu4_curve","cpu5_curve","cpu6_curve","cpu7_curve","l3_hit_count","l3_miss_count","no_static","all_cpu_deep_idle" 362 4108586789603,35685,1950000,0,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,14718,5837,-1,-1 363 4108586825288,30843,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,12721,5045,-1,-1 364 4108586856131,13387,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,99.470000,5521,2189,-1,-1 365 4108586869518,22542,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,9297,3687,-1,-1 366 4108586892060,2482,1950000,-1,1950000,-1,1950000,-1,1950000,0,674.240000,674.240000,674.240000,3327.560000,1023,406,-1,-1 367 4108586894542,68563,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,28279,11216,-1,-1 368 4108586963105,59652,1950000,-1,1950000,-1,1950000,-1,1950000,0,674.240000,674.240000,674.240000,3327.560000,24603,9758,-1,-1 369 4108587022757,3743,1950000,0,1950000,-1,1950000,-1,1950000,0,674.240000,674.240000,674.240000,3327.560000,1543,612,-1,-1 370 4108587026500,15992,1950000,-1,1950000,-1,1950000,-1,1950000,0,674.240000,674.240000,674.240000,3327.560000,6595,2616,-1,-1 371 4108587042492,15625,1950000,-1,1950000,-1,1950000,-1,1950000,0,674.240000,674.240000,674.240000,99.470000,6444,2556,-1,-1 372 4108587058117,8138,1950000,-1,1950000,-1,1950000,-1,1950000,0,674.240000,674.240000,674.240000,3327.560000,3356,1331,-1,-1 373 4108587066255,80566,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,33229,13179,-1,-1 374 4108587146821,19572,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,99.470000,8072,3201,-1,-1 375 4108587166393,219116,1950000,-1,1950000,-1,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,90375,35845,-1,-1 376 4108587385509,81991,1950000,-1,1950000,0,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,33817,13413,-1,-1 377 4108587467500,90413,1950000,-1,1950000,0,1950000,0,1950000,-1,674.240000,674.240000,674.240000,3327.560000,37291,14790,-1,-1 378 4108587557913,92896,1950000,0,1950000,0,1950000,0,1950000,-1,674.240000,674.240000,674.240000,3327.560000,38315,15196,-1,-1 379 4108587650809,95296,1950000,-1,1950000,0,1950000,0,1950000,-1,674.240000,674.240000,674.240000,3327.560000,39305,15589,-1,-1 380 4108587746105,12451,1950000,0,1950000,0,1950000,0,1950000,-1,674.240000,674.240000,674.240000,3327.560000,5135,2036,-1,-1 381 4108587758556,28524,1950000,0,1950000,0,1950000,-1,1950000,-1,674.240000,674.240000,674.240000,3327.560000,11764,4666,-1,-1 382 """)) 383 384 # Tests that DSU devfreq calculations are merged correctly 385 def test_wattson_dsu_devfreq_system_state(self): 386 return DiffTestBlueprint( 387 trace=DataPath('wattson_tk4_pcmark.pb'), 388 query=(""" 389 INCLUDE PERFETTO MODULE wattson.curves.estimates; 390 SELECT * FROM _system_state_mw 391 WHERE ts > 4108586775197 392 LIMIT 20 393 """), 394 out=Csv(""" 395 "ts","dur","cpu0_mw","cpu1_mw","cpu2_mw","cpu3_mw","cpu4_mw","cpu5_mw","cpu6_mw","cpu7_mw","dsu_scu_mw" 396 4108586789603,35685,2.670000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.695271 397 4108586825288,30843,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.698554 398 4108586856131,13387,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,99.470000,1166.545753 399 4108586869518,22542,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.655587 400 4108586892060,2482,205.600000,205.600000,205.600000,2.670000,674.240000,674.240000,674.240000,3327.560000,1166.164641 401 4108586894542,68563,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.746124 402 4108586963105,59652,205.600000,205.600000,205.600000,2.670000,674.240000,674.240000,674.240000,3327.560000,1166.716706 403 4108587022757,3743,2.670000,205.600000,205.600000,2.670000,674.240000,674.240000,674.240000,3327.560000,1166.170321 404 4108587026500,15992,205.600000,205.600000,205.600000,2.670000,674.240000,674.240000,674.240000,3327.560000,1166.620056 405 4108587042492,15625,205.600000,205.600000,205.600000,2.670000,674.240000,674.240000,674.240000,99.470000,1166.668234 406 4108587058117,8138,205.600000,205.600000,205.600000,2.670000,674.240000,674.240000,674.240000,3327.560000,1166.555033 407 4108587066255,80566,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.717766 408 4108587146821,19572,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,99.470000,1166.626795 409 4108587166393,219116,205.600000,205.600000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.750356 410 4108587385509,81991,205.600000,2.670000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.743880 411 4108587467500,90413,205.600000,2.670000,2.670000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.736713 412 4108587557913,92896,2.670000,2.670000,2.670000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.730805 413 4108587650809,95296,205.600000,2.670000,2.670000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.740927 414 4108587746105,12451,2.670000,2.670000,2.670000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.556475 415 4108587758556,28524,2.670000,2.670000,205.600000,205.600000,674.240000,674.240000,674.240000,3327.560000,1166.680924 416 """)) 417 418 def test_wattson_time_window_api(self): 419 return DiffTestBlueprint( 420 trace=DataPath('wattson_dsu_pmu.pb'), 421 query=""" 422 INCLUDE PERFETTO MODULE wattson.curves.estimates; 423 424 SELECT 425 cpu0_mw, 426 cpu1_mw, 427 cpu2_mw, 428 cpu3_mw, 429 cpu4_mw, 430 cpu5_mw, 431 cpu6_mw, 432 cpu7_mw, 433 dsu_scu_mw 434 FROM _windowed_system_state_mw(362426061658, 5067704349) 435 """, 436 out=Csv(""" 437 "cpu0_mw","cpu1_mw","cpu2_mw","cpu3_mw","cpu4_mw","cpu5_mw","cpu6_mw","cpu7_mw","dsu_scu_mw" 438 13.025673,6.270190,5.448549,8.796540,8.937174,10.717942,29.482823,30.239208,26.121213 439 """)) 440 441 # Tests that suspend calculations are correct on 8 CPU device where suspend 442 # indication comes from "syscore" command 443 def test_wattson_syscore_suspend(self): 444 return DiffTestBlueprint( 445 trace=DataPath('wattson_syscore_suspend.pb'), 446 query=(""" 447 INCLUDE PERFETTO MODULE wattson.curves.estimates; 448 SELECT ts, dur, cpu0_id, cpu1_id, cpu2_id, cpu3_id, suspended 449 FROM _stats_cpu0123_suspend 450 WHERE suspended 451 """), 452 out=Csv(""" 453 "ts","dur","cpu0_id","cpu1_id","cpu2_id","cpu3_id","suspended" 454 385019771468,61975407053,12042,12219,10489,8911,1 455 448320364476,3674872885,13008,12957,11169,9275,1 456 452415394221,69579176303,13659,13366,11656,9614,1 457 564873995228,135118729231,45230,37601,22805,20139,1 458 """)) 459 460 # Tests traces from VM that have incomplete CPU tracks 461 def test_wattson_missing_cpus_on_guest(self): 462 return DiffTestBlueprint( 463 trace=DataPath('wattson_tk4_vm.pb'), 464 query=(""" 465 INCLUDE PERFETTO MODULE wattson.curves.estimates; 466 SELECT 467 ts, dur, cpu0_mw, cpu1_mw, cpu2_mw, cpu3_mw, cpu4_mw, cpu5_mw, 468 cpu6_mw 469 FROM _system_state_mw 470 WHERE ts > 25150000000 471 LIMIT 10 472 """), 473 out=Csv(""" 474 "ts","dur","cpu0_mw","cpu1_mw","cpu2_mw","cpu3_mw","cpu4_mw","cpu5_mw","cpu6_mw" 475 25150029000,1080,0.000000,0.000000,0.000000,0.000000,70.050000,83.260000,0.000000 476 25150030640,42920,0.000000,0.000000,0.000000,0.000000,70.050000,70.050000,0.000000 477 25150073560,99800,0.000000,0.000000,0.000000,0.000000,70.050000,0.000000,0.000000 478 25150173360,28240,176.280000,0.000000,0.000000,0.000000,70.050000,0.000000,0.000000 479 25150201600,6480,176.280000,0.000000,0.000000,176.280000,70.050000,0.000000,0.000000 480 25150208080,29840,176.280000,0.000000,0.000000,176.280000,70.050000,70.050000,0.000000 481 25150237920,129800,0.000000,0.000000,0.000000,176.280000,70.050000,70.050000,0.000000 482 25150367720,37480,0.000000,0.000000,0.000000,176.280000,70.050000,0.000000,0.000000 483 25150405200,15120,0.000000,176.280000,0.000000,176.280000,70.050000,0.000000,0.000000 484 25150420320,15920,0.000000,176.280000,0.000000,0.000000,70.050000,0.000000,0.000000 485 """)) 486 487 # Tests suspend path with devfreq code path 488 def test_wattson_devfreq_hotplug_and_suspend(self): 489 return DiffTestBlueprint( 490 trace=DataPath('wattson_cpuhp_devfreq_suspend.pb'), 491 query=(""" 492 INCLUDE PERFETTO MODULE wattson.curves.estimates; 493 SELECT 494 ts, dur, cpu0_mw, cpu1_mw, cpu2_mw, cpu3_mw, cpu4_mw, cpu5_mw, 495 cpu6_mw, cpu7_mw, dsu_scu_mw 496 FROM _system_state_mw 497 WHERE ts > 165725449108 498 LIMIT 6 499 """), 500 out=Csv(""" 501 "ts","dur","cpu0_mw","cpu1_mw","cpu2_mw","cpu3_mw","cpu4_mw","cpu5_mw","cpu6_mw","cpu7_mw","dsu_scu_mw" 502 165725450194,7527,111.020000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,375.490000,14.560000 503 165725457721,17334,111.020000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,14.560000 504 165725475055,6999,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 505 165725482054,1546,111.020000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,14.560000 506 165725483600,4468465,111.020000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,14.560000 507 165729952065,73480460119,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000 508 """)) 509 510 # Tests remapping of idle states 511 def test_wattson_idle_remap(self): 512 return DiffTestBlueprint( 513 trace=DataPath('wattson_idle_map.pb'), 514 query=(""" 515 INCLUDE PERFETTO MODULE wattson.curves.estimates; 516 SELECT ts, dur, cpu, idle 517 FROM _adjusted_deep_idle 518 WHERE ts > 1450338950433 AND cpu = 3 519 LIMIT 10 520 """), 521 out=Csv(""" 522 "ts","dur","cpu","idle" 523 1450338950434,1395365,3,1 524 1450340345799,96927,3,-1 525 1450340442726,301250,3,0 526 1450340743976,24010,3,-1 527 1450340767986,3748386,3,1 528 1450344516372,70208,3,-1 529 1450344586580,2400521,3,1 530 1450346987101,306458,3,-1 531 1450347293559,715573,3,0 532 1450348009132,82292,3,-1 533 """)) 534 535 # Tests that hotplug slices that defined CPU off region are correct 536 def test_wattson_hotplug_tk(self): 537 return DiffTestBlueprint( 538 trace=DataPath('wattson_cpuhp_devfreq_suspend.pb'), 539 query=(""" 540 INCLUDE PERFETTO MODULE wattson.cpu_hotplug; 541 SELECT cpu, ts, dur 542 FROM _gapless_hotplug_slices 543 WHERE cpu < 2 544 """), 545 out=Csv(""" 546 "cpu","ts","dur" 547 0,86747008512,302795933205 548 1,86747008512,3769632400 549 1,90516640912,4341919 550 1,90520982831,73692291133 551 1,164213273964,1478796428 552 1,165692070392,73525895666 553 1,239217966058,10896074956 554 1,250114041014,95948 555 1,250114136962,4705159 556 1,250118842121,137102890041 557 1,387221732162,2321209555 558 """)) 559