blob: 694cbc5039d94821afd5d582e87b9aa45ae689f6 [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.
Rasika Navarange71a395f2023-11-06 18:13:5510CREATE 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 Navarange0e3d9b62023-08-23 11:45:0322SELECT
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
28FROM slice
29WHERE name = "VSync"
30ORDER 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 Navarange71a395f2023-11-06 18:13:5534-- 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 Navarange0e3d9b62023-08-23 11:45:0336-- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which
37-- corresponds to 16 ms or 60 FPS).
Rasika Navarange71a395f2023-11-06 18:13:5538CREATE PERFETTO FUNCTION chrome_calculate_avg_vsync_interval(
39 -- Interval start time.
Rasika Navarange0e3d9b62023-08-23 11:45:0340 begin_ts LONG,
Rasika Navarange71a395f2023-11-06 18:13:5541 -- Interval end time.
Rasika Navarange0e3d9b62023-08-23 11:45:0342 end_ts LONG
43)
Rasika Navarange156094f62023-11-09 18:13:0944-- The average vsync interval on this time segment
45-- or 1.6e+7, if trace doesn't contain the VSync TraceEvent.
Rasika Navarange0e3d9b62023-08-23 11:45:0346RETURNS FLOAT AS
47SELECT
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);