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 Fuchsia(TestSuite): 23 # Contains tests for parsing Fuchsia traces. Smoke test a bunch of different 24 # types. 25 def test_fuchsia_smoke(self): 26 return DiffTestBlueprint( 27 trace=DataPath('fuchsia_trace.fxt'), 28 query=""" 29 SELECT 30 ts, 31 cpu, 32 dur, 33 end_state, 34 priority, 35 tid 36 FROM sched 37 JOIN thread USING(utid) 38 ORDER BY ts 39 LIMIT 10; 40 """, 41 out=Csv(""" 42 "ts","cpu","dur","end_state","priority","tid" 43 19675868967,2,79022,"S",20,4344 44 19676000188,3,504797,"S",20,6547 45 19676504985,3,42877,"S",20,6525 46 19676582005,0,48467,"S",20,11566 47 19676989045,2,138116,"S",20,9949 48 19677162311,3,48655,"S",20,6525 49 19677305405,3,48814,"S",20,6525 50 19677412330,0,177220,"S",20,4344 51 19677680485,2,91422,"S",20,6537 52 19677791779,3,96082,"S",20,1680 53 """)) 54 55 def test_fuchsia_sched(self): 56 return DiffTestBlueprint( 57 trace=DataPath('fuchsia_trace_sched.fxt'), 58 query=""" 59 SELECT 60 ts, 61 cpu, 62 dur, 63 end_state, 64 priority, 65 tid 66 FROM sched 67 JOIN thread USING(utid) 68 ORDER BY ts 69 LIMIT 10; 70 """, 71 out=Csv(""" 72 "ts","cpu","dur","end_state","priority","tid" 73 68988611421,3,313611,"S",3122,3196 74 68988925032,3,98697,"S",3122,23416 75 68988957574,0,632536,"S",3122,3189 76 68989023729,3,51371,"S",3122,3196 77 68989075100,3,46773,"R",3122,25332 78 68989121873,3,53620,"S",2147483647,24654 79 68989175493,3,5241,"S",3122,25332 80 68989180734,3,138507,"S",3122,30933 81 68989319241,3,25028,"S",3122,30297 82 68989344269,3,52723,"S",3122,28343 83 """)) 84 85 def test_fuchsia_smoke_slices(self): 86 return DiffTestBlueprint( 87 trace=DataPath('fuchsia_trace.fxt'), 88 query=""" 89 SELECT depth, count(*) AS count 90 FROM slice 91 JOIN track ON slice.track_id = track.id 92 GROUP BY depth 93 ORDER BY depth; 94 """, 95 out=Csv(""" 96 "depth","count" 97 0,2153 98 1,1004 99 """)) 100 101 def test_fuchsia_smoke_instants(self): 102 return DiffTestBlueprint( 103 trace=DataPath('fuchsia_trace.fxt'), 104 query=""" 105 SELECT 106 ts, 107 name 108 FROM slice 109 WHERE 110 dur = 0 111 LIMIT 10; 112 """, 113 out=Csv(""" 114 "ts","name" 115 21442756010,"task_start" 116 21446583438,"task_end" 117 21448366538,"task_start" 118 21450363277,"task_end" 119 21454255741,"task_start" 120 21457834528,"task_end" 121 21459006408,"task_start" 122 21460601866,"task_end" 123 21461282720,"task_start" 124 21462998487,"task_end" 125 """)) 126 127 def test_fuchsia_smoke_counters(self): 128 return DiffTestBlueprint( 129 trace=DataPath('fuchsia_trace.fxt'), 130 query=""" 131 SELECT 132 ts, 133 value, 134 name 135 FROM counters 136 LIMIT 10; 137 """, 138 out=Csv(""" 139 "ts","value","name" 140 20329439768,30.331177,"cpu_usage:average_cpu_percentage:0" 141 21331281870,7.829745,"cpu_usage:average_cpu_percentage:0" 142 22332302017,9.669818,"cpu_usage:average_cpu_percentage:0" 143 23332974162,6.421237,"cpu_usage:average_cpu_percentage:0" 144 24333405767,12.079849,"cpu_usage:average_cpu_percentage:0" 145 """)) 146 147 def test_fuchsia_smoke_flow(self): 148 return DiffTestBlueprint( 149 trace=DataPath('fuchsia_trace.fxt'), 150 query=""" 151 SELECT 152 id, 153 slice_out, 154 slice_in 155 FROM flow 156 LIMIT 10; 157 """, 158 out=Csv(""" 159 "id","slice_out","slice_in" 160 0,0,1 161 1,2,3 162 2,4,5 163 3,6,7 164 4,8,9 165 5,10,11 166 6,12,13 167 7,14,15 168 8,16,17 169 9,18,19 170 """)) 171 172 def test_fuchsia_smoke_type(self): 173 return DiffTestBlueprint( 174 trace=DataPath('fuchsia_trace.fxt'), 175 query=""" 176 SELECT 177 id, 178 name 179 FROM track 180 LIMIT 10; 181 """, 182 out=Csv(""" 183 "id","name" 184 0,"[NULL]" 185 1,"[NULL]" 186 2,"[NULL]" 187 3,"[NULL]" 188 4,"[NULL]" 189 5,"cpu_usage:average_cpu_percentage:0" 190 6,"[NULL]" 191 7,"[NULL]" 192 8,"[NULL]" 193 9,"[NULL]" 194 """)) 195 196 # Smoke test a high-CPU trace. 197 def test_fuchsia_workstation_smoke_slices(self): 198 return DiffTestBlueprint( 199 trace=DataPath('fuchsia_workstation.fxt'), 200 query=""" 201 SELECT depth, count(*) AS count 202 FROM slice 203 JOIN track ON slice.track_id = track.id 204 GROUP BY depth 205 ORDER BY depth; 206 """, 207 out=Csv(''' 208 "depth","count" 209 0,15283 210 1,11621 211 2,10182 212 3,1927 213 4,4001 214 5,2543 215 6,1856 216 7,2209 217 8,2200 218 9,1672 219 10,353 220 11,331 221 12,304 222 13,246 223 14,207 224 15,175 225 16,114 226 17,38 227 18,12 228 19,1 229 ''')) 230 231 def test_fuchsia_workstation_smoke_args(self): 232 return DiffTestBlueprint( 233 trace=DataPath('fuchsia_workstation.fxt'), 234 query=""" 235 SELECT 236 key, 237 COUNT(*) 238 FROM args 239 GROUP BY key 240 LIMIT 10; 241 """, 242 out=Csv(""" 243 "key","COUNT(*)" 244 "Dart Arguments",3 245 "Escher frame number",33 246 "Expected presentation time",17 247 "Frame number",33 248 "MinikinFontsCount",2 249 "Predicted frame duration(ms)",21 250 "Render time(ms)",21 251 "Timestamp",917 252 "Update time(ms)",21 253 "Vsync interval",900 254 """)) 255 256 def test_fuchsia_args_import(self): 257 return DiffTestBlueprint( 258 trace=DataPath('fuchsia_events_and_args.fxt'), 259 query=""" 260 SELECT key,int_value,string_value,real_value,value_type,display_value 261 FROM args 262 GROUP BY key 263 ORDER BY key 264 """, 265 out=Csv(""" 266 "key","int_value","string_value","real_value","value_type","display_value" 267 "SomeNullArg","[NULL]","null","[NULL]","string","null" 268 "Somedouble","[NULL]","[NULL]",3.141500,"real","3.1415" 269 "Someint32",-7,"[NULL]","[NULL]","int","-7" 270 "Someint64",-234516543631231,"[NULL]","[NULL]","int","-234516543631231" 271 "Someuint32",2145,"[NULL]","[NULL]","int","2145" 272 "Someuint64",423621626134123415,"[NULL]","[NULL]","int","423621626134123415" 273 "cookie",658,"[NULL]","[NULL]","int","658" 274 "name","[NULL]","example_counter:somedataseries:0","[NULL]","string","example_counter:somedataseries:0" 275 "ping","[NULL]","pong","[NULL]","string","pong" 276 "scope","[NULL]","[NULL]","[NULL]","string","[NULL]" 277 "somebool",1,"[NULL]","[NULL]","bool","true" 278 "somekoid",18,"[NULL]","[NULL]","int","18" 279 "someotherbool",0,"[NULL]","[NULL]","bool","false" 280 "someotherpointer",43981,"[NULL]","[NULL]","pointer","0xabcd" 281 "somepointer",3285933758964,"[NULL]","[NULL]","pointer","0x2fd10ea19f4" 282 "source","[NULL]","chrome","[NULL]","string","chrome" 283 "source_scope","[NULL]","[NULL]","[NULL]","string","[NULL]" 284 "trace_id",658,"[NULL]","[NULL]","int","658" 285 "trace_id_is_process_scoped",0,"[NULL]","[NULL]","bool","false" 286 "upid",1,"[NULL]","[NULL]","int","1" 287 "utid",1,"[NULL]","[NULL]","int","1" 288 """)) 289