1-- A simple table that checks the time between VSync (this can be used to 2-- determine if we're refreshing at 90 FPS or 60 FPS). 3-- 4-- Note: In traces without the "Java" category there will be no VSync 5-- TraceEvents and this table will be empty. 6DROP TABLE IF EXISTS vsync_intervals; 7CREATE TABLE vsync_intervals AS 8SELECT 9 slice_id, 10 ts, 11 dur, 12 track_id, 13 LEAD(ts) OVER(PARTITION BY track_id ORDER BY ts) - ts AS time_to_next_vsync 14FROM slice 15WHERE name = "VSync" 16ORDER BY track_id, ts; 17 18SELECT CREATE_FUNCTION( 19 -- Function: compute the average Vysnc interval of the 20 -- gesture (hopefully this would be either 60 FPS for the whole gesture or 90 21 -- FPS but that isn't always the case) on the given time segment. 22 -- If the trace doesn't contain the VSync TraceEvent we just fall back on 23 -- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which 24 -- corresponds to 16 ms or 60 FPS). 25 -- 26 -- begin_ts: segment start time 27 -- end_ts: segment end time 28 'CalculateAvgVsyncInterval(begin_ts LONG, end_ts LONG)', 29 -- Returns: the average Vysnc interval on this time segment 30 -- or 1.6e+7, if trace doesn't contain the VSync TraceEvent. 31 'FLOAT', 32 'SELECT 33 COALESCE(( 34 SELECT 35 CAST(AVG(time_to_next_vsync) AS FLOAT) 36 FROM vsync_intervals in_query 37 WHERE 38 time_to_next_vsync IS NOT NULL AND 39 in_query.ts > $begin_ts AND 40 in_query.ts < $end_ts 41 ), 1e+9 / 60)' 42); 43