Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame^] | 1 | -- Copyright 2023 The Chromium Authors |
| 2 | -- Use of this source code is governed by a BSD-style license that can be |
| 3 | -- found in the LICENSE file. |
| 4 | |
| 5 | DROP TABLE IF EXISTS chrome_vsync_intervals; |
| 6 | |
| 7 | -- A simple table that checks the time between VSync (this can be used to |
| 8 | -- determine if we're refreshing at 90 FPS or 60 FPS). |
| 9 | -- |
| 10 | -- Note: In traces without the "Java" category there will be no VSync |
| 11 | -- TraceEvents and this table will be empty. |
| 12 | CREATE PERFETTO TABLE chrome_vsync_intervals AS |
| 13 | SELECT |
| 14 | slice_id, |
| 15 | ts, |
| 16 | dur, |
| 17 | track_id, |
| 18 | LEAD(ts) OVER(PARTITION BY track_id ORDER BY ts) - ts AS time_to_next_vsync |
| 19 | FROM slice |
| 20 | WHERE name = "VSync" |
| 21 | ORDER BY track_id, ts; |
| 22 | |
| 23 | -- Function: compute the average Vysnc interval of the |
| 24 | -- gesture (hopefully this would be either 60 FPS for the whole gesture or 90 |
| 25 | -- FPS but that isn't always the case) on the given time segment. |
| 26 | -- If the trace doesn't contain the VSync TraceEvent we just fall back on |
| 27 | -- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which |
| 28 | -- corresponds to 16 ms or 60 FPS). |
| 29 | -- |
| 30 | -- begin_ts: segment start time |
| 31 | -- end_ts: segment end time |
| 32 | CREATE PERFETTO FUNCTION calculate_avg_vsync_interval( |
| 33 | begin_ts LONG, |
| 34 | end_ts LONG |
| 35 | ) |
| 36 | -- Returns: the average Vysnc interval on this time segment |
| 37 | -- or 1.6e+7, if trace doesnt contain the VSync TraceEvent. |
| 38 | RETURNS FLOAT AS |
| 39 | SELECT |
| 40 | COALESCE(( |
| 41 | SELECT |
| 42 | CAST(AVG(time_to_next_vsync) AS FLOAT) |
| 43 | FROM chrome_vsync_intervals in_query |
| 44 | WHERE |
| 45 | time_to_next_vsync IS NOT NULL AND |
| 46 | in_query.ts > $begin_ts AND |
| 47 | in_query.ts < $end_ts |
| 48 | ), 1e+9 / 60); |