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 GraphicsParser(TestSuite): 23 # Contains tests for graphics related events and tables. Graphics frame 24 # trace tests. 25 def test_graphics_frame_events(self): 26 return DiffTestBlueprint( 27 trace=Path('graphics_frame_events.py'), 28 query=""" 29 SELECT ts, gpu_track.name AS track_name, dur, frame_slice.name AS slice_name, 30 frame_number, layer_name 31 FROM gpu_track 32 LEFT JOIN frame_slice ON gpu_track.id = frame_slice.track_id 33 WHERE scope = 'graphics_frame_event' 34 ORDER BY ts; 35 """, 36 out=Path('graphics_frame_events.out')) 37 38 # GPU Memory ftrace packets 39 def test_gpu_mem_total(self): 40 return DiffTestBlueprint( 41 trace=Path('gpu_mem_total.py'), 42 query=Path('gpu_mem_total_test.sql'), 43 out=Csv(""" 44 "name","unit","description","ts","pid","value" 45 "GPU Memory","7","Total GPU memory used by the entire system",0,"[NULL]",123 46 "GPU Memory","7","Total GPU memory used by this process",0,1,100 47 "GPU Memory","7","Total GPU memory used by the entire system",5,"[NULL]",256 48 "GPU Memory","7","Total GPU memory used by this process",5,1,233 49 "GPU Memory","7","Total GPU memory used by the entire system",10,"[NULL]",123 50 "GPU Memory","7","Total GPU memory used by this process",10,1,0 51 """)) 52 53 def test_gpu_mem_total_after_free_gpu_mem_total(self): 54 return DiffTestBlueprint( 55 trace=Path('gpu_mem_total_after_free.py'), 56 query=Path('gpu_mem_total_test.sql'), 57 out=Csv(""" 58 "name","unit","description","ts","pid","value" 59 "GPU Memory","7","Total GPU memory used by this process",0,1,100 60 "GPU Memory","7","Total GPU memory used by this process",5,1,233 61 "GPU Memory","7","Total GPU memory used by this process",10,1,50 62 """)) 63 64 # Clock sync 65 def test_clock_sync(self): 66 return DiffTestBlueprint( 67 trace=Path('clock_sync.py'), 68 query=""" 69 SELECT ts, cast(value AS integer) AS int_value 70 FROM counters 71 WHERE name GLOB 'gpu_counter*'; 72 """, 73 out=Csv(""" 74 "ts","int_value" 75 1,3 76 102,5 77 1003,7 78 1005,9 79 2006,11 80 2010,12 81 2013,13 82 3007,14 83 3010,15 84 """)) 85 86 # Frame Timeline event trace tests 87 def test_expected_frame_timeline_events(self): 88 return DiffTestBlueprint( 89 trace=Path('frame_timeline_events.py'), 90 query=Path('expected_frame_timeline_events_test.sql'), 91 out=Csv(""" 92 "ts","dur","pid","display_frame_token","surface_frame_token","layer_name" 93 20,6,666,2,0,"[NULL]" 94 21,15,1000,4,1,"Layer1" 95 40,6,666,4,0,"[NULL]" 96 41,15,1000,6,5,"Layer1" 97 80,6,666,6,0,"[NULL]" 98 90,16,1000,8,7,"Layer1" 99 120,6,666,8,0,"[NULL]" 100 140,6,666,12,0,"[NULL]" 101 150,20,1000,15,14,"Layer1" 102 170,6,666,15,0,"[NULL]" 103 200,6,666,17,0,"[NULL]" 104 220,-1,666,18,0,"[NULL]" 105 220,10,666,18,0,"[NULL]" 106 """)) 107 108 def test_actual_frame_timeline_events(self): 109 return DiffTestBlueprint( 110 trace=Path('frame_timeline_events.py'), 111 query=Path('actual_frame_timeline_events_test.sql'), 112 out=Csv(""" 113 "ts","dur","pid","display_frame_token","surface_frame_token","layer_name","present_type","on_time_finish","gpu_composition","jank_type","prediction_type","jank_tag","jank_severity_type" 114 20,6,666,2,0,"[NULL]","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 115 21,16,1000,4,1,"Layer1","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 116 41,33,1000,6,5,"Layer1","Late Present",0,0,"App Deadline Missed","Valid Prediction","Self Jank","Full" 117 42,5,666,4,0,"[NULL]","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 118 80,110,1000,17,16,"Layer1","Unknown Present",0,0,"Unknown Jank","Expired Prediction","Self Jank","Partial" 119 81,7,666,6,0,"[NULL]","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 120 90,16,1000,8,7,"Layer1","Early Present",1,0,"SurfaceFlinger Scheduling","Valid Prediction","Other Jank","Unknown" 121 108,4,666,8,0,"[NULL]","Early Present",1,0,"SurfaceFlinger Scheduling","Valid Prediction","Self Jank","Unknown" 122 148,8,666,12,0,"[NULL]","Late Present",0,0,"SurfaceFlinger Scheduling, SurfaceFlinger CPU Deadline Missed","Valid Prediction","Self Jank","Unknown" 123 150,17,1000,15,14,"Layer1","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 124 150,17,1000,15,14,"Layer2","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 125 170,6,666,15,0,"[NULL]","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 126 200,6,666,17,0,"[NULL]","On-time Present",1,0,"None","Valid Prediction","No Jank","None" 127 245,-1,666,18,0,"[NULL]","Late Present",0,0,"SurfaceFlinger Stuffing","Valid Prediction","SurfaceFlinger Stuffing","Unknown" 128 245,15,666,18,0,"[NULL]","Dropped Frame",0,0,"Dropped Frame","Unspecified Prediction","Dropped Frame","Unknown" 129 """)) 130 131 # Video 4 Linux 2 related tests 132 def test_v4l2_vidioc_slice(self): 133 return DiffTestBlueprint( 134 trace=Path('v4l2_vidioc.textproto'), 135 query=""" 136 SELECT ts, dur, name 137 FROM slice 138 WHERE category = 'Video 4 Linux 2'; 139 """, 140 out=Csv(""" 141 "ts","dur","name" 142 593268475912,0,"VIDIOC_QBUF minor=0 seq=0 type=9 index=19" 143 593268603800,0,"VIDIOC_QBUF minor=0 seq=0 type=9 index=20" 144 593528238295,0,"VIDIOC_DQBUF minor=0 seq=0 type=9 index=19" 145 593544028229,0,"VIDIOC_DQBUF minor=0 seq=0 type=9 index=20" 146 """)) 147 148 def test_v4l2_vidioc_flow(self): 149 return DiffTestBlueprint( 150 trace=Path('v4l2_vidioc.textproto'), 151 query=""" 152 SELECT qbuf.ts, qbuf.dur, qbuf.name, dqbuf.ts, dqbuf.dur, dqbuf.name 153 FROM flow 154 JOIN slice qbuf ON flow.slice_out = qbuf.id 155 JOIN slice dqbuf ON flow.slice_in = dqbuf.id; 156 """, 157 out=Path('v4l2_vidioc_flow.out')) 158 159 def test_virtio_video_slice(self): 160 return DiffTestBlueprint( 161 trace=Path('virtio_video.textproto'), 162 query=""" 163 SELECT slice.ts, slice.dur, slice.name, track.name 164 FROM slice 165 JOIN track ON slice.track_id = track.id; 166 """, 167 out=Csv(""" 168 "ts","dur","name","name" 169 593125003271,84500592,"Resource #102","virtio_video stream #4 OUTPUT" 170 593125003785,100000,"RESOURCE_QUEUE","virtio_video stream #4 Requests" 171 593125084611,709696,"Resource #62","virtio_video stream #3 OUTPUT" 172 593125084935,100000,"RESOURCE_QUEUE","virtio_video stream #3 Requests" 173 593125794194,100000,"RESOURCE_QUEUE","virtio_video stream #3 Responses" 174 593209502603,100000,"RESOURCE_QUEUE","virtio_video stream #4 Responses" 175 """)) 176 177 # virtgpu (drm/virtio) related tests 178 def test_virtio_gpu(self): 179 return DiffTestBlueprint( 180 trace=Path('virtio_gpu.textproto'), 181 query=""" 182 SELECT 183 ts, 184 dur, 185 name 186 FROM 187 slice 188 ORDER BY ts; 189 """, 190 out=Csv(""" 191 "ts","dur","name" 192 1345090723759,1180312,"SUBMIT_3D" 193 1345090746311,1167135,"CTX_DETACH_RESOURCE" 194 """)) 195 196 # TODO(b/294866695): Reenable 197 # mali GPU events 198 #def test_mali(self): 199 # return DiffTestBlueprint( 200 # trace=TextProto(r""" 201 # packet { 202 # ftrace_events { 203 # cpu: 2 204 # event { 205 # timestamp: 751796307210 206 # pid: 2857 207 # mali_mali_KCPU_CQS_WAIT_START { 208 # info_val1: 1 209 # info_val2: 0 210 # kctx_tgid: 2201 211 # kctx_id: 10 212 # id: 0 213 # } 214 # } 215 # event { 216 # timestamp: 751800621175 217 # pid: 2857 218 # mali_mali_KCPU_CQS_WAIT_END { 219 # info_val1: 412313493488 220 # info_val2: 0 221 # kctx_tgid: 2201 222 # kctx_id: 10 223 # id: 0 224 # } 225 # } 226 # event { 227 # timestamp: 751800638997 228 # pid: 2857 229 # mali_mali_KCPU_CQS_SET { 230 # info_val1: 412313493480 231 # info_val2: 0 232 # kctx_tgid: 2201 233 # kctx_id: 10 234 # id: 0 235 # } 236 # } 237 # } 238 # } 239 # """), 240 # query=""" 241 # SELECT ts, dur, name FROM slice WHERE name GLOB "mali_KCPU_CQS*"; 242 # """, 243 # out=Csv(""" 244 # "ts","dur","name" 245 # 751796307210,4313965,"mali_KCPU_CQS_WAIT" 246 # 751800638997,0,"mali_KCPU_CQS_SET" 247 # """)) 248 249 #def test_mali_fence(self): 250 # return DiffTestBlueprint( 251 # trace=TextProto(r""" 252 # packet { 253 # ftrace_events { 254 # cpu: 2 255 # event { 256 # timestamp: 751796307210 257 # pid: 2857 258 # mali_mali_KCPU_FENCE_WAIT_START { 259 # info_val1: 1 260 # info_val2: 0 261 # kctx_tgid: 2201 262 # kctx_id: 10 263 # id: 0 264 # } 265 # } 266 # event { 267 # timestamp: 751800621175 268 # pid: 2857 269 # mali_mali_KCPU_FENCE_WAIT_END { 270 # info_val1: 412313493488 271 # info_val2: 0 272 # kctx_tgid: 2201 273 # kctx_id: 10 274 # id: 0 275 # } 276 # } 277 # event { 278 # timestamp: 751800638997 279 # pid: 2857 280 # mali_mali_KCPU_FENCE_SIGNAL { 281 # info_val1: 412313493480 282 # info_val2: 0 283 # kctx_tgid: 2201 284 # kctx_id: 10 285 # id: 0 286 # } 287 # } 288 # } 289 # } 290 # """), 291 # query=""" 292 # SELECT ts, dur, name FROM slice WHERE name GLOB "mali_KCPU_FENCE*"; 293 # """, 294 # out=Csv(""" 295 # "ts","dur","name" 296 # 751796307210,4313965,"mali_KCPU_FENCE_WAIT" 297 # 751800638997,0,"mali_KCPU_FENCE_SIGNAL" 298 # """)) 299 300 # Tests gpu_track with machine_id ID. 301 def test_graphics_frame_events_machine_id(self): 302 return DiffTestBlueprint( 303 trace=Path('graphics_frame_events.py'), 304 trace_modifier=TraceInjector(['graphics_frame_event'], 305 {'machine_id': 1001}), 306 query=""" 307 SELECT ts, gpu_track.name AS track_name, dur, frame_slice.name AS slice_name, 308 frame_number, layer_name 309 FROM gpu_track 310 LEFT JOIN frame_slice ON gpu_track.id = frame_slice.track_id 311 WHERE scope = 'graphics_frame_event' 312 AND gpu_track.machine_id IS NOT NULL 313 ORDER BY ts; 314 """, 315 out=Path('graphics_frame_events.out')) 316