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 | |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 5 | -- A simple table that checks the time between VSync (this can be used to |
| 6 | -- determine if we're refreshing at 90 FPS or 60 FPS). |
| 7 | -- |
| 8 | -- Note: In traces without the "Java" category there will be no VSync |
| 9 | -- TraceEvents and this table will be empty. |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 10 | CREATE PERFETTO TABLE chrome_vsync_intervals( |
| 11 | -- Slice id of the vsync slice. |
| 12 | slice_id INT, |
| 13 | -- Timestamp of the vsync slice. |
| 14 | ts INT, |
| 15 | -- Duration of the vsync slice. |
| 16 | dur INT, |
| 17 | -- Track id of the vsync slice. |
| 18 | track_id INT, |
| 19 | -- Duration until next vsync arrives. |
| 20 | time_to_next_vsync INT |
| 21 | ) AS |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 22 | SELECT |
| 23 | slice_id, |
| 24 | ts, |
| 25 | dur, |
| 26 | track_id, |
| 27 | LEAD(ts) OVER(PARTITION BY track_id ORDER BY ts) - ts AS time_to_next_vsync |
| 28 | FROM slice |
| 29 | WHERE name = "VSync" |
| 30 | ORDER BY track_id, ts; |
| 31 | |
| 32 | -- Function: compute the average Vysnc interval of the |
| 33 | -- gesture (hopefully this would be either 60 FPS for the whole gesture or 90 |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 34 | -- FPS but that isnt always the case) on the given time segment. |
| 35 | -- If the trace doesnt contain the VSync TraceEvent we just fall back on |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 36 | -- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which |
| 37 | -- corresponds to 16 ms or 60 FPS). |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 38 | CREATE PERFETTO FUNCTION chrome_calculate_avg_vsync_interval( |
| 39 | -- Interval start time. |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 40 | begin_ts LONG, |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 41 | -- Interval end time. |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 42 | end_ts LONG |
| 43 | ) |
Rasika Navarange | 156094f6 | 2023-11-09 18:13:09 | [diff] [blame^] | 44 | -- The average vsync interval on this time segment |
| 45 | -- or 1.6e+7, if trace doesn't contain the VSync TraceEvent. |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 46 | RETURNS FLOAT AS |
| 47 | SELECT |
| 48 | COALESCE(( |
| 49 | SELECT |
| 50 | CAST(AVG(time_to_next_vsync) AS FLOAT) |
| 51 | FROM chrome_vsync_intervals in_query |
| 52 | WHERE |
| 53 | time_to_next_vsync IS NOT NULL AND |
| 54 | in_query.ts > $begin_ts AND |
| 55 | in_query.ts < $end_ts |
| 56 | ), 1e+9 / 60); |