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. |
Victor Hugo Vianna Silva | e30216c | 2025-03-17 19:03:48 | [diff] [blame] | 10 | CREATE PERFETTO TABLE chrome_vsync_intervals ( |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 11 | -- Slice id of the vsync slice. |
Victor Hugo Vianna Silva | f40c7d5 | 2024-11-29 16:49:12 | [diff] [blame] | 12 | slice_id LONG, |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 13 | -- Timestamp of the vsync slice. |
Victor Hugo Vianna Silva | f40c7d5 | 2024-11-29 16:49:12 | [diff] [blame] | 14 | ts TIMESTAMP, |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 15 | -- Duration of the vsync slice. |
Victor Hugo Vianna Silva | f40c7d5 | 2024-11-29 16:49:12 | [diff] [blame] | 16 | dur DURATION, |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 17 | -- Track id of the vsync slice. |
Victor Hugo Vianna Silva | f40c7d5 | 2024-11-29 16:49:12 | [diff] [blame] | 18 | track_id LONG, |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 19 | -- Duration until next vsync arrives. |
Victor Hugo Vianna Silva | f40c7d5 | 2024-11-29 16:49:12 | [diff] [blame] | 20 | time_to_next_vsync LONG |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 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, |
Victor Hugo Vianna Silva | e30216c | 2025-03-17 19:03:48 | [diff] [blame] | 27 | lead(ts) OVER (PARTITION BY track_id ORDER BY ts) - ts AS time_to_next_vsync |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 28 | FROM slice |
Victor Hugo Vianna Silva | e30216c | 2025-03-17 19:03:48 | [diff] [blame] | 29 | WHERE |
| 30 | name = "VSync" |
| 31 | ORDER BY |
| 32 | track_id, |
| 33 | ts; |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 34 | |
| 35 | -- Function: compute the average Vysnc interval of the |
| 36 | -- 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] | 37 | -- FPS but that isnt always the case) on the given time segment. |
| 38 | -- If the trace doesnt contain the VSync TraceEvent we just fall back on |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 39 | -- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which |
| 40 | -- corresponds to 16 ms or 60 FPS). |
Rasika Navarange | 71a395f | 2023-11-06 18:13:55 | [diff] [blame] | 41 | CREATE PERFETTO FUNCTION chrome_calculate_avg_vsync_interval( |
Victor Hugo Vianna Silva | e30216c | 2025-03-17 19:03:48 | [diff] [blame] | 42 | -- Interval start time. |
| 43 | begin_ts TIMESTAMP, |
| 44 | -- Interval end time. |
| 45 | end_ts TIMESTAMP |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 46 | ) |
Rasika Navarange | 156094f6 | 2023-11-09 18:13:09 | [diff] [blame] | 47 | -- The average vsync interval on this time segment |
| 48 | -- or 1.6e+7, if trace doesn't contain the VSync TraceEvent. |
Victor Hugo Vianna Silva | f40c7d5 | 2024-11-29 16:49:12 | [diff] [blame] | 49 | RETURNS DOUBLE AS |
Rasika Navarange | 0e3d9b6 | 2023-08-23 11:45:03 | [diff] [blame] | 50 | SELECT |
Victor Hugo Vianna Silva | e30216c | 2025-03-17 19:03:48 | [diff] [blame] | 51 | coalesce( |
| 52 | ( |
| 53 | SELECT |
| 54 | cast_double!(AVG(time_to_next_vsync)) |
| 55 | FROM chrome_vsync_intervals AS in_query |
| 56 | WHERE |
| 57 | NOT time_to_next_vsync IS NULL AND in_query.ts > $begin_ts AND in_query.ts < $end_ts |
| 58 | ), |
| 59 | 1e+9 / 60 |
| 60 | ); |