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-- 16DROP VIEW IF EXISTS same_frame; 17CREATE VIEW same_frame AS 18SELECT COUNT(name) AS total_duplicate_frames 19FROM counters 20WHERE name='SAME_FRAME' 21AND value=1; 22 23DROP VIEW IF EXISTS duplicate_frames_logged; 24CREATE VIEW duplicate_frames_logged AS 25SELECT CASE WHEN COUNT(name) > 0 THEN 1 ELSE 0 END AS logs_found 26FROM counters 27WHERE name='SAME_FRAME' AND value=0; 28 29DROP VIEW IF EXISTS dpu_underrun; 30CREATE VIEW dpu_underrun AS 31SELECT COUNT(name) AS total_dpu_underrun_count 32FROM counters 33WHERE name='DPU_UNDERRUN' 34AND value=1; 35 36DROP VIEW IF EXISTS non_repeated_panel_fps; 37CREATE VIEW non_repeated_panel_fps AS 38SELECT * 39FROM ( 40 SELECT 41 ts, 42 value, 43 track_id, 44 LAG(value, 1, 0) OVER (PARTITION BY track_id ORDER BY ts) AS prev_value 45 FROM counter c JOIN track t ON c.track_id = t.id 46 WHERE t.name = 'panel_fps' 47 ORDER BY ts 48) 49WHERE prev_value != value; 50 51DROP VIEW IF EXISTS panel_fps_spans; 52CREATE VIEW panel_fps_spans AS 53SELECT * 54FROM ( 55 SELECT 56 ts, 57 value, 58 LEAD(ts) OVER (PARTITION BY track_id ORDER BY ts) - ts AS dur 59 FROM non_repeated_panel_fps 60 ORDER BY ts 61) 62WHERE dur > 0; 63 64DROP VIEW IF EXISTS display_metrics_output; 65CREATE VIEW display_metrics_output AS 66SELECT AndroidDisplayMetrics( 67 'total_duplicate_frames', (SELECT total_duplicate_frames 68 FROM same_frame), 69 'duplicate_frames_logged', (SELECT logs_found 70 FROM duplicate_frames_logged), 71 'total_dpu_underrun_count', (SELECT total_dpu_underrun_count 72 FROM dpu_underrun), 73 'refresh_rate_switches', (SELECT COUNT(*) FROM panel_fps_spans), 74 'refresh_rate_stats', ( 75 SELECT RepeatedField(metric) 76 FROM ( 77 SELECT AndroidDisplayMetrics_RefreshRateStat( 78 'refresh_rate_fps', CAST(value AS UINT32), 79 'count', COUNT(*), 80 'total_dur_ms', SUM(dur) / 1e6, 81 'avg_dur_ms', AVG(dur) / 1e6 82 ) AS metric 83 FROM panel_fps_spans 84 GROUP BY value 85 ORDER BY value 86 ) 87 ) 88); 89