• 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 LONG,
25  -- Timestamp of the frame. Start of "Choreographer#doFrame" slice.
26  ts TIMESTAMP,
27  -- Duration of the frame, defined as the duration until the last
28  -- "DrawFrame" of this frame finishes.
29  dur DURATION,
30  -- Slice with name "Choreographer#doFrame" corresponding to this frame.
31  do_frame_id JOINID(slice.id),
32  -- Slice with name "DrawFrame" corresponding to this frame. Fetched as one
33  -- of the "DrawFrame" slices that happen for the same process as
34  -- "Choreographer#doFrame" slice and start after it started and before the
35  -- next "doFrame" started.
36  draw_frame_id JOINID(slice.id),
37  -- `utid` of the render thread.
38  render_thread_utid JOINID(thread.id),
39  -- `utid` of the UI thread.
40  ui_thread_utid JOINID(thread.id),
41  -- "maxsdk28"
42  sdk STRING,
43  -- process id.
44  upid JOINID(process.id),
45  -- process name.
46  process_name STRING
47) AS
48WITH
49  choreographer AS (
50    SELECT
51      id
52    FROM slice
53    WHERE
54      name = 'Choreographer#doFrame'
55  ),
56  do_frames AS (
57    SELECT
58      id,
59      ts,
60      lead(ts, 1, trace_end()) OVER (PARTITION BY upid ORDER BY ts) AS next_do_frame,
61      utid,
62      upid
63    FROM choreographer
64    JOIN thread_slice
65      USING (id)
66    WHERE
67      is_main_thread = 1
68    ORDER BY
69      ts
70  ),
71  draw_frames AS (
72    SELECT
73      id,
74      ts,
75      dur,
76      ts + dur AS ts_end,
77      utid,
78      upid
79    FROM thread_slice
80    WHERE
81      name = 'DrawFrame'
82  )
83SELECT
84  row_number() OVER () AS frame_id,
85  do.ts,
86  max(draw.ts_end) OVER (PARTITION BY do.id) - do.ts AS dur,
87  do.id AS do_frame_id,
88  draw.id AS draw_frame_id,
89  draw.utid AS render_thread_utid,
90  do.utid AS ui_thread_utid,
91  do.upid AS upid,
92  process.name AS process_name,
93  "maxsdk28" AS sdk
94FROM do_frames AS do
95JOIN draw_frames AS draw
96  ON (
97    do.upid = draw.upid AND draw.ts >= do.ts AND draw.ts < next_do_frame
98  )
99JOIN process
100  USING (upid)
101ORDER BY
102  do.ts;
103