1-- 2-- Copyright 2020 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 at 7-- 8-- https://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 16SELECT RUN_METRIC( 17 'android/frame_missed.sql', 18 'track_name', 'PrevFrameMissed', 19 'output', 'frame_missed' 20); 21SELECT RUN_METRIC( 22 'android/frame_missed.sql', 23 'track_name', 'PrevHwcFrameMissed', 24 'output', 'hwc_frame_missed' 25); 26SELECT RUN_METRIC( 27 'android/frame_missed.sql', 28 'track_name', 'PrevGpuFrameMissed', 29 'output', 'gpu_frame_missed' 30); 31 32DROP VIEW IF EXISTS android_surfaceflinger_event; 33CREATE VIEW android_surfaceflinger_event AS 34SELECT 35 'slice' AS track_type, 36 'Android Missed Frames' AS track_name, 37 ts, 38 dur, 39 'Frame missed' AS slice_name 40FROM frame_missed 41WHERE value = 1 AND ts IS NOT NULL; 42 43DROP VIEW IF EXISTS surfaceflinger_track; 44CREATE VIEW surfaceflinger_track AS 45SELECT tr.id AS track_id, t.utid, t.tid 46FROM process p JOIN thread t ON p.upid = t.upid 47 JOIN thread_track tr ON tr.utid = t.utid 48WHERE p.cmdline='/system/bin/surfaceflinger'; 49 50DROP VIEW IF EXISTS gpu_waiting_start; 51CREATE VIEW gpu_waiting_start AS 52SELECT 53 CAST(SUBSTR(s.name, 28) AS UINT32) AS fence_id, 54 ts AS start_ts 55FROM slices s JOIN surfaceflinger_track t ON s.track_id = t.track_id 56WHERE s.name GLOB 'Trace GPU completion fence *'; 57 58DROP VIEW IF EXISTS gpu_waiting_end; 59CREATE VIEW gpu_waiting_end AS 60SELECT 61 CAST(SUBSTR(s.name, 28) AS UINT32) AS fence_id, 62 dur, 63 ts+dur AS end_ts 64FROM slices s JOIN surfaceflinger_track t ON s.track_id = t.track_id 65WHERE s.name GLOB 'waiting for GPU completion *'; 66 67DROP VIEW IF EXISTS gpu_waiting_span; 68CREATE VIEW gpu_waiting_span AS 69SELECT 70 fence_id, 71 ts, 72 dur 73FROM ( 74 SELECT 75 fence_id, 76 ts, 77 LEAD(ts) OVER (ORDER BY fence_id, event_type) - ts AS dur, 78 LEAD(fence_id) OVER (ORDER BY fence_id, event_type) AS next_fence_id, 79 event_type 80 FROM ( 81 SELECT fence_id, start_ts AS ts, 0 AS event_type FROM gpu_waiting_start 82 UNION 83 SELECT fence_id, end_ts AS ts, 1 AS event_type FROM gpu_waiting_end 84 ) 85 ORDER BY fence_id, event_type 86) 87WHERE event_type = 0 AND fence_id = next_fence_id; 88 89DROP VIEW IF EXISTS android_surfaceflinger_output; 90CREATE VIEW android_surfaceflinger_output AS 91SELECT 92 AndroidSurfaceflingerMetric( 93 'missed_frames', (SELECT COUNT(1) FROM frame_missed WHERE value=1), 94 'missed_hwc_frames', (SELECT COUNT(1) FROM hwc_frame_missed WHERE value=1), 95 'missed_gpu_frames', (SELECT COUNT(1) FROM gpu_frame_missed WHERE value=1), 96 'missed_frame_rate', (SELECT AVG(value) FROM frame_missed), 97 'missed_hwc_frame_rate', (SELECT AVG(value) FROM hwc_frame_missed), 98 'missed_gpu_frame_rate', (SELECT AVG(value) FROM gpu_frame_missed), 99 'gpu_invocations', (SELECT COUNT(1) FROM gpu_waiting_end), 100 'avg_gpu_waiting_dur_ms', (SELECT AVG(dur)/1e6 FROM gpu_waiting_span), 101 'total_non_empty_gpu_waiting_dur_ms', 102 (SELECT SUM(dur)/1e6 FROM gpu_waiting_end) 103 ); 104