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 GraphicsGpuTrace(TestSuite): 23 24 def test_gpu_counters(self): 25 return DiffTestBlueprint( 26 trace=Path('gpu_counters.py'), 27 query=""" 28 SELECT "ts", "value", "name", "gpu_id", "description", "unit" 29 FROM counter 30 JOIN gpu_counter_track 31 ON counter.track_id = gpu_counter_track.id 32 ORDER BY "ts"; 33 """, 34 out=Csv(""" 35 "ts","value","name","gpu_id","description","unit" 36 11,5.000000,"Vertex / Second",0,"Number of vertices per second","25/22" 37 12,7.000000,"Fragment / Second",0,"Number of fragments per second","26/22" 38 14,0.000000,"Triangle Acceleration",0,"Number of triangles per ms-ms","27/21:21" 39 21,10.000000,"Vertex / Second",0,"Number of vertices per second","25/22" 40 22,14.000000,"Fragment / Second",0,"Number of fragments per second","26/22" 41 24,9.000000,"Triangle Acceleration",0,"Number of triangles per ms-ms","27/21:21" 42 31,15.000000,"Vertex / Second",0,"Number of vertices per second","25/22" 43 32,21.000000,"Fragment / Second",0,"Number of fragments per second","26/22" 44 34,7.000000,"Triangle Acceleration",0,"Number of triangles per ms-ms","27/21:21" 45 """)) 46 47 def test_gpu_counter_specs(self): 48 return DiffTestBlueprint( 49 trace=Path('gpu_counter_specs.textproto'), 50 query=""" 51 SELECT group_id, c.name, c.description, unit 52 FROM gpu_counter_group AS g 53 JOIN gpu_counter_track AS c 54 ON g.track_id = c.id; 55 """, 56 out=Csv(""" 57 "group_id","name","description","unit" 58 0,"GPU Frequency","clock speed","/22" 59 3,"Fragments / vertex","Number of fragments per vertex","39/25" 60 2,"Fragments / vertex","Number of fragments per vertex","39/25" 61 3,"Fragment / Second","Number of fragments per second","26/22" 62 4,"Triangle Acceleration","Number of triangles per ms-ms","27/21:21" 63 """)) 64 65 def test_gpu_render_stages(self): 66 return DiffTestBlueprint( 67 trace=Path('gpu_render_stages.py'), 68 query=Path('gpu_render_stages_test.sql'), 69 out=Path('gpu_render_stages.out')) 70 71 def test_gpu_render_stages_interned_spec(self): 72 return DiffTestBlueprint( 73 trace=Path('gpu_render_stages_interned_spec.textproto'), 74 query=Path('gpu_render_stages_test.sql'), 75 out=Path('gpu_render_stages_interned_spec.out')) 76 77 def test_vulkan_api_events(self): 78 return DiffTestBlueprint( 79 trace=Path('vulkan_api_events.py'), 80 query=""" 81 SELECT track.name AS track_name, gpu_track.description AS track_desc, ts, dur, 82 gpu_slice.name AS slice_name, depth, flat_key, int_value, 83 gpu_slice.context_id, command_buffer, submission_id 84 FROM gpu_track 85 LEFT JOIN track USING (id) 86 JOIN gpu_slice ON gpu_track.id = gpu_slice.track_id 87 LEFT JOIN args ON gpu_slice.arg_set_id = args.arg_set_id 88 ORDER BY ts; 89 """, 90 out=Path('vulkan_api_events.out')) 91 92 def test_gpu_log(self): 93 return DiffTestBlueprint( 94 trace=Path('gpu_log.py'), 95 query=""" 96 SELECT scope, track.name AS track_name, ts, dur, gpu_slice.name AS slice_name, 97 key, string_value AS value 98 FROM gpu_track 99 LEFT JOIN track USING (id) 100 LEFT JOIN gpu_slice ON gpu_track.id = gpu_slice.track_id 101 LEFT JOIN args USING (arg_set_id) 102 ORDER BY ts, slice_name, key; 103 """, 104 out=Csv(""" 105 "scope","track_name","ts","dur","slice_name","key","value" 106 "gpu_log","GPU Log",1,0,"VERBOSE","message","message0" 107 "gpu_log","GPU Log",1,0,"VERBOSE","tag","tag0" 108 "gpu_log","GPU Log",2,0,"DEBUG","message","message1" 109 "gpu_log","GPU Log",2,0,"DEBUG","tag","tag0" 110 "gpu_log","GPU Log",3,0,"INFO","message","message2" 111 "gpu_log","GPU Log",3,0,"INFO","tag","tag0" 112 "gpu_log","GPU Log",4,0,"ERROR","message","message4" 113 "gpu_log","GPU Log",4,0,"ERROR","tag","tag0" 114 "gpu_log","GPU Log",4,0,"WARNING","message","message3" 115 "gpu_log","GPU Log",4,0,"WARNING","tag","tag0" 116 "gpu_log","GPU Log",5,0,"VERBOSE","message","message5" 117 "gpu_log","GPU Log",5,0,"VERBOSE","tag","tag1" 118 """)) 119