Skip to content

Commit 7bba83a

Browse files
committed
tp: Migrate CUJ render thread boundaries to stdlib
TAG=agy Change-Id: Ia7f19ca672e31157abccd1db4cc3fb268bffe3a0
1 parent 0b6612c commit 7bba83a

2 files changed

Lines changed: 87 additions & 51 deletions

File tree

src/trace_processor/metrics/sql/android/jank/cujs_boundaries.sql

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -44,62 +44,13 @@ DROP TABLE IF EXISTS android_jank_cuj_main_thread_cuj_boundary;
4444
CREATE PERFETTO TABLE android_jank_cuj_main_thread_cuj_boundary AS
4545
SELECT * FROM _android_jank_cuj_main_thread_cuj_boundary;
4646

47-
-- Similar to `android_jank_cuj_main_thread_frame_boundary` but for the render
48-
-- thread the expected start time is the time of the first `postAndWait` slice
49-
-- on the main thread.
50-
-- The query is slightly simpler because we don't have to handle the clock drift
51-
-- and data loss like with the frame timeline.
52-
-- One difference vs main thread is that there might be multiple DrawFrames
53-
-- slices for a single vsync - this happens when we are drawing multiple layers
54-
-- (e.g. status bar & notifications).
5547
DROP TABLE IF EXISTS android_jank_cuj_render_thread_frame_boundary;
5648
CREATE PERFETTO TABLE android_jank_cuj_render_thread_frame_boundary AS
57-
-- see do_frame_ordered above
58-
-- we also order by `ts` to handle multiple DrawFrames for a single vsync
59-
WITH draw_frame_ordered AS (
60-
SELECT
61-
*,
62-
-- ts_end of the previous draw frame, or -1 if no previous draw frame found
63-
COALESCE(LAG(ts_end) OVER (PARTITION BY cuj_id ORDER BY vsync ASC, ts ASC), -1) AS ts_prev_draw_frame_end
64-
FROM android_jank_cuj_draw_frame_slice
65-
),
66-
-- introducing an intermediate table since we want to calculate dur = ts_end - ts
67-
frame_boundary_base AS (
68-
SELECT
69-
draw_frame.cuj_id,
70-
draw_frame.utid,
71-
draw_frame.vsync,
72-
MIN(post_and_wait.ts) AS ts_expected,
73-
MIN(draw_frame.ts) AS ts_draw_frame_start,
74-
MIN(draw_frame.ts_prev_draw_frame_end) AS ts_prev_draw_frame_end,
75-
MIN(
76-
MAX(
77-
MIN(post_and_wait.ts),
78-
MIN(draw_frame.ts_prev_draw_frame_end)),
79-
MIN(draw_frame.ts)) AS ts,
80-
MAX(draw_frame.ts_end) AS ts_end
81-
FROM draw_frame_ordered draw_frame
82-
JOIN _android_jank_cuj_do_frames do_frame USING (cuj_id, vsync)
83-
JOIN descendant_slice(do_frame.id) post_and_wait
84-
WHERE post_and_wait.name = 'postAndWait'
85-
GROUP BY draw_frame.cuj_id, draw_frame.utid, draw_frame.vsync
86-
)
87-
SELECT
88-
*,
89-
ts_end - ts AS dur
90-
FROM frame_boundary_base;
49+
SELECT * FROM _android_jank_cuj_render_thread_frame_boundary;
9150

92-
-- Compute the CUJ boundary on the render thread from the frame boundaries.
9351
DROP TABLE IF EXISTS android_jank_cuj_render_thread_cuj_boundary;
9452
CREATE PERFETTO TABLE android_jank_cuj_render_thread_cuj_boundary AS
95-
SELECT
96-
cuj_id,
97-
utid,
98-
MIN(ts) AS ts,
99-
MAX(ts_end) AS ts_end,
100-
MAX(ts_end) - MIN(ts) AS dur
101-
FROM android_jank_cuj_render_thread_frame_boundary
102-
GROUP BY cuj_id, utid;
53+
SELECT * FROM _android_jank_cuj_render_thread_cuj_boundary;
10354

10455
DROP TABLE IF EXISTS android_jank_cuj_boundary;
10556
CREATE PERFETTO TABLE android_jank_cuj_boundary AS

src/trace_processor/perfetto_sql/stdlib/android/cujs/boundaries.sql

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,88 @@ WITH
231231
main_thread_boundary.ts
232232
)
233233
SELECT *, ts_end - ts AS dur FROM boundary_base;
234+
235+
236+
-- Similar to `_android_jank_cuj_main_thread_frame_boundary` but for the render
237+
-- thread the expected start time is the time of the first `postAndWait` slice
238+
-- on the main thread.
239+
-- The query is slightly simpler because we don't have to handle the clock drift
240+
-- and data loss like with the frame timeline.
241+
-- One difference vs main thread is that there might be multiple DrawFrames
242+
-- slices for a single vsync - this happens when we are drawing multiple layers
243+
-- (e.g. status bar & notifications).
244+
CREATE PERFETTO TABLE _android_jank_cuj_render_thread_frame_boundary(
245+
-- CUJ id.
246+
cuj_id LONG,
247+
-- Thread id of the render thread.
248+
utid JOINID(thread.id),
249+
-- Vsync ID of this frame.
250+
vsync LONG,
251+
-- Expected start timestamp (first postAndWait slice).
252+
ts_expected TIMESTAMP,
253+
-- Start timestamp of the DrawFrame slice.
254+
ts_draw_frame_start TIMESTAMP,
255+
-- End timestamp of the previous DrawFrame slice.
256+
ts_prev_draw_frame_end TIMESTAMP,
257+
-- Corrected start timestamp for the frame boundary.
258+
ts TIMESTAMP,
259+
-- End timestamp of the DrawFrame slice.
260+
ts_end TIMESTAMP,
261+
-- Duration of the frame boundary.
262+
dur DURATION
263+
)
264+
AS
265+
-- see do_frame_ordered above
266+
-- we also order by `ts` to handle multiple DrawFrames for a single vsync
267+
WITH draw_frame_ordered AS (
268+
SELECT
269+
*,
270+
-- ts_end of the previous draw frame, or -1 if no previous draw frame found
271+
COALESCE(LAG(ts_end) OVER (PARTITION BY cuj_id ORDER BY vsync ASC, ts ASC), -1) AS ts_prev_draw_frame_end
272+
FROM _android_jank_cuj_draw_frame_slice
273+
),
274+
-- introducing an intermediate table since we want to calculate dur = ts_end - ts
275+
frame_boundary_base AS (
276+
SELECT
277+
draw_frame.cuj_id,
278+
draw_frame.utid,
279+
draw_frame.vsync,
280+
MIN(post_and_wait.ts) AS ts_expected,
281+
MIN(draw_frame.ts) AS ts_draw_frame_start,
282+
MIN(draw_frame.ts_prev_draw_frame_end) AS ts_prev_draw_frame_end,
283+
MIN(
284+
MAX(
285+
MIN(post_and_wait.ts),
286+
MIN(draw_frame.ts_prev_draw_frame_end)),
287+
MIN(draw_frame.ts)) AS ts,
288+
MAX(draw_frame.ts_end) AS ts_end
289+
FROM draw_frame_ordered draw_frame
290+
JOIN _android_jank_cuj_do_frames do_frame USING (cuj_id, vsync)
291+
JOIN descendant_slice(do_frame.id) post_and_wait
292+
WHERE post_and_wait.name = 'postAndWait'
293+
GROUP BY draw_frame.cuj_id, draw_frame.utid, draw_frame.vsync
294+
)
295+
SELECT *, ts_end - ts AS dur FROM frame_boundary_base;
296+
297+
-- Compute the CUJ boundary on the render thread from the frame boundaries.
298+
CREATE PERFETTO TABLE _android_jank_cuj_render_thread_cuj_boundary(
299+
-- CUJ id.
300+
cuj_id LONG,
301+
-- Thread id of the render thread.
302+
utid JOINID(thread.id),
303+
-- Start timestamp of the CUJ on the render thread.
304+
ts TIMESTAMP,
305+
-- End timestamp of the CUJ on the render thread.
306+
ts_end TIMESTAMP,
307+
-- Duration of the CUJ on the render thread.
308+
dur DURATION
309+
)
310+
AS
311+
SELECT
312+
cuj_id,
313+
utid,
314+
MIN(ts) AS ts,
315+
MAX(ts_end) AS ts_end,
316+
MAX(ts_end) - MIN(ts) AS dur
317+
FROM _android_jank_cuj_render_thread_frame_boundary
318+
GROUP BY cuj_id, utid;

0 commit comments

Comments
 (0)