• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-- 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.
10CREATE PERFETTO TABLE chrome_vsync_intervals(
11  -- Slice id of the vsync slice.
12  slice_id LONG,
13  -- Timestamp of the vsync slice.
14  ts TIMESTAMP,
15  -- Duration of the vsync slice.
16  dur DURATION,
17  -- Track id of the vsync slice.
18  track_id LONG,
19  -- Duration until next vsync arrives.
20  time_to_next_vsync LONG
21) AS
22SELECT
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
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
36-- assuming its 60 FPS (this is the 1.6e+7 in the COALESCE which
37-- corresponds to 16 ms or 60 FPS).
38CREATE PERFETTO FUNCTION chrome_calculate_avg_vsync_interval(
39  -- Interval start time.
40  begin_ts TIMESTAMP,
41  -- Interval end time.
42  end_ts TIMESTAMP
43)
44-- The average vsync interval on this time segment
45-- or 1.6e+7, if trace doesn't contain the VSync TraceEvent.
46RETURNS DOUBLE AS
47SELECT
48  COALESCE((
49    SELECT
50      cast_double!(AVG(time_to_next_vsync))
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);
57