1-- 2-- Copyright 2021 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 raw_g2d_{{g2d_type}}_spans; 17CREATE VIEW raw_g2d_{{g2d_type}}_spans AS 18SELECT 19 ts, 20 t.name AS track_name, 21 LEAD(ts, 1, 0) OVER (PARTITION BY name ORDER BY ts) - ts AS dur, 22 LAG(value, 1, -1) OVER (PARTITION BY name ORDER BY ts) AS prev_g2d_value, 23 value AS g2d_value, 24 LEAD(value, 1, -1) OVER (PARTITION BY name ORDER BY ts) AS next_g2d_value 25FROM counter c JOIN thread_counter_track t ON t.id = c.track_id 26WHERE t.name LIKE 'g2d_frame_{{g2d_type}}%'; 27 28 29DROP VIEW IF EXISTS g2d_{{g2d_type}}_spans; 30CREATE VIEW g2d_{{g2d_type}}_spans AS 31SELECT ts, track_name, dur 32FROM raw_g2d_{{g2d_type}}_spans 33WHERE g2d_value = 1 AND next_g2d_value = 0; 34 35 36DROP VIEW IF EXISTS g2d_{{g2d_type}}_errors; 37CREATE VIEW g2d_{{g2d_type}}_errors AS 38SELECT ts, track_name, g2d_value 39FROM raw_g2d_{{g2d_type}}_spans 40WHERE (g2d_value = 1 AND next_g2d_value = 1) OR (prev_g2d_value = 0 AND g2d_value = 0); 41 42 43DROP VIEW IF EXISTS g2d_{{g2d_type}}_instances; 44CREATE VIEW g2d_{{g2d_type}}_instances AS 45SELECT 46 G2dMetrics_G2dInstance( 47 'name', g.track_name, 48 'max_dur_ns', CAST(MAX(g.dur) AS INT64), 49 'min_dur_ns', CAST(MIN(g.dur) AS INT64), 50 'avg_dur_ns', CAST(AVG(g.dur) AS INT64), 51 'frame_count', COUNT(*), 52 'error_count', (SELECT COUNT(*) FROM g2d_{{g2d_type}}_errors e WHERE e.track_name = g.track_name) 53 ) AS instance 54FROM g2d_{{g2d_type}}_spans g GROUP BY g.track_name; 55 56 57DROP VIEW IF EXISTS {{output_table}}; 58CREATE VIEW {{output_table}} AS 59SELECT 60 G2dMetrics_G2dMetric( 61 'instances', (SELECT RepeatedField(instance) FROM g2d_{{g2d_type}}_instances), 62 'max_dur_ns', CAST(MAX(dur) AS INT64), 63 'min_dur_ns', CAST(MIN(dur) AS INT64), 64 'avg_dur_ns', CAST(AVG(dur) AS INT64), 65 'frame_count', COUNT(*), 66 'error_count', (SELECT COUNT(*) FROM g2d_{{g2d_type}}_errors) 67 ) AS metric 68FROM g2d_{{g2d_type}}_spans; 69