blob: f3a88889d23cd6bef77965dcadb38ba3421e002a [file] [log] [blame]
Rasika Navarange0e3d9b62023-08-23 11:45:031-- 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 Navarange0e3d9b62023-08-23 11:45:035-- 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 Silvae30216c2025-03-17 19:03:4810CREATE PERFETTO TABLE chrome_vsync_intervals (
Rasika Navarange71a395f2023-11-06 18:13:5511 -- Slice id of the vsync slice.
Victor Hugo Vianna Silvaf40c7d52024-11-29 16:49:1212 slice_id LONG,
Rasika Navarange71a395f2023-11-06 18:13:5513 -- Timestamp of the vsync slice.
Victor Hugo Vianna Silvaf40c7d52024-11-29 16:49:1214 ts TIMESTAMP,
Rasika Navarange71a395f2023-11-06 18:13:5515 -- Duration of the vsync slice.
Victor Hugo Vianna Silvaf40c7d52024-11-29 16:49:1216 dur DURATION,
Rasika Navarange71a395f2023-11-06 18:13:5517 -- Track id of the vsync slice.
Victor Hugo Vianna Silvaf40c7d52024-11-29 16:49:1218 track_id LONG,
Rasika Navarange71a395f2023-11-06 18:13:5519 -- Duration until next vsync arrives.
Victor Hugo Vianna Silvaf40c7d52024-11-29 16:49:1220 time_to_next_vsync LONG
Rasika Navarange71a395f2023-11-06 18:13:5521) AS
Rasika Navarange0e3d9b62023-08-23 11:45:0322SELECT
23 slice_id,
24 ts,
25 dur,
26 track_id,
Victor Hugo Vianna Silvae30216c2025-03-17 19:03:4827 lead(ts) OVER (PARTITION BY track_id ORDER BY ts) - ts AS time_to_next_vsync
Rasika Navarange0e3d9b62023-08-23 11:45:0328FROM slice
Victor Hugo Vianna Silvae30216c2025-03-17 19:03:4829WHERE
30 name = "VSync"
31ORDER BY
32 track_id,
33 ts;
Rasika Navarange0e3d9b62023-08-23 11:45:0334
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 Navarange71a395f2023-11-06 18:13:5537-- 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 Navarange0e3d9b62023-08-23 11:45:0339-- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which
40-- corresponds to 16 ms or 60 FPS).
Rasika Navarange71a395f2023-11-06 18:13:5541CREATE PERFETTO FUNCTION chrome_calculate_avg_vsync_interval(
Victor Hugo Vianna Silvae30216c2025-03-17 19:03:4842 -- Interval start time.
43 begin_ts TIMESTAMP,
44 -- Interval end time.
45 end_ts TIMESTAMP
Rasika Navarange0e3d9b62023-08-23 11:45:0346)
Rasika Navarange156094f62023-11-09 18:13:0947-- The average vsync interval on this time segment
48-- or 1.6e+7, if trace doesn't contain the VSync TraceEvent.
Victor Hugo Vianna Silvaf40c7d52024-11-29 16:49:1249RETURNS DOUBLE AS
Rasika Navarange0e3d9b62023-08-23 11:45:0350SELECT
Victor Hugo Vianna Silvae30216c2025-03-17 19:03:4851 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 );