• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15
16INCLUDE PERFETTO MODULE slices.with_context;
17
18-- All slices related to one frame for max SDK 28. Aggregates
19-- "Choreographer#doFrame" and "DrawFrame". Tries to guess the `ts` and `dur`
20-- of the frame by first guessing which "DrawFrame" slices are related to which
21-- "Choreographer#doSlice".
22CREATE PERFETTO TABLE _frames_maxsdk_28(
23    -- Frame id. Created manually starting from 0.
24    frame_id INT,
25    -- Timestamp of the frame. Start of "Choreographer#doFrame" slice.
26    ts INT,
27    -- Duration of the frame, defined as the duration until the last
28    -- "DrawFrame" of this frame finishes.
29    dur INT,
30    -- `slice.id` of "Choreographer#doFrame" slice.
31    do_frame_id INT,
32    -- `slice.id` of "DrawFrame" slice. Fetched as one of the "DrawFrame"
33    -- slices that happen for the same process as "Choreographer#doFrame" slice
34    -- and start after it started and before the next "doFrame" started.
35    draw_frame_id INT,
36    -- `utid` of the render thread.
37    render_thread_utid INT,
38    -- `utid` of the UI thread.
39    ui_thread_utid INT,
40    -- "maxsdk28"
41    sdk STRING
42) AS
43WITH choreographer AS (
44  SELECT id
45  FROM slice
46  WHERE name = 'Choreographer#doFrame'
47),
48do_frames AS (
49    SELECT
50        id,
51        ts,
52        LEAD(ts, 1, TRACE_END()) OVER (PARTITION BY upid ORDER BY ts) AS next_do_frame,
53        utid,
54        upid
55    FROM choreographer
56    JOIN thread_slice USING (id)
57    WHERE is_main_thread = 1
58    ORDER BY ts
59),
60draw_frames AS (
61    SELECT
62        id,
63        ts,
64        dur,
65        ts + dur AS ts_end,
66        utid,
67        upid
68    FROM thread_slice
69    WHERE name = 'DrawFrame'
70)
71SELECT
72  ROW_NUMBER() OVER () AS frame_id,
73  do.ts,
74  MAX(draw.ts_end) OVER (PARTITION BY do.id) - do.ts AS dur,
75  do.id AS do_frame_id,
76  draw.id AS draw_frame_id,
77  draw.utid AS render_thread_utid,
78  do.utid AS ui_thread_utid,
79  "maxsdk28" AS sdk
80FROM do_frames do
81JOIN draw_frames draw ON (do.upid = draw.upid AND draw.ts >= do.ts AND draw.ts < next_do_frame)
82ORDER BY do.ts;