INCLUDE PERFETTO MODULE chrome.android_input;
INCLUDE PERFETTO MODULE intervals.intersect;
INCLUDE PERFETTO MODULE slices.with_context;
CREATE PERFETTO TABLE _chrome_input_pipeline_steps_no_input_type (
latency_id LONG,
slice_id LONG,
ts TIMESTAMP,
dur DURATION,
utid LONG,
step STRING,
input_type STRING,
task_start_time_ts TIMESTAMP
) AS
WITH
steps_with_potential_duplicates AS (
SELECT
extract_arg(thread_slice.arg_set_id, 'chrome_latency_info.trace_id') AS latency_id,
id AS slice_id,
ts,
dur,
utid,
extract_arg(thread_slice.arg_set_id, 'chrome_latency_info.step') AS step,
extract_arg(thread_slice.arg_set_id, 'chrome_latency_info.input_type') AS input_type,
ts - (
extract_arg(thread_slice.arg_set_id, 'current_task.event_offset_from_task_start_time_us') * 1000
) AS task_start_time_ts
FROM thread_slice
WHERE
NOT step IS NULL AND latency_id != -1
),
steps_with_ordering AS (
SELECT
*,
row_number() OVER (PARTITION BY latency_id, utid, step, input_type ORDER BY ts DESC) AS ordering_within_partition
FROM steps_with_potential_duplicates
)
SELECT
latency_id,
slice_id,
ts,
dur,
utid,
step,
input_type,
task_start_time_ts
FROM steps_with_ordering
WHERE
ordering_within_partition = 1
ORDER BY
slice_id,
ts;
CREATE PERFETTO TABLE chrome_inputs (
latency_id LONG,
input_type STRING
) AS
SELECT
latency_id,
min(input_type) AS input_type
FROM _chrome_input_pipeline_steps_no_input_type
WHERE
latency_id != -1
GROUP BY
latency_id;
CREATE PERFETTO TABLE chrome_input_pipeline_steps (
latency_id LONG,
slice_id LONG,
ts TIMESTAMP,
dur DURATION,
utid LONG,
step STRING,
input_type STRING,
task_start_time_ts TIMESTAMP
) AS
SELECT
latency_id,
slice_id,
ts,
dur,
utid,
step,
chrome_inputs.input_type AS input_type,
task_start_time_ts
FROM chrome_inputs
LEFT JOIN _chrome_input_pipeline_steps_no_input_type
USING (latency_id)
WHERE
chrome_inputs.input_type IS NOT NULL;
CREATE PERFETTO TABLE chrome_coalesced_inputs (
coalesced_latency_id LONG,
presented_latency_id LONG
) AS
SELECT
args.int_value AS coalesced_latency_id,
latency_id AS presented_latency_id
FROM chrome_input_pipeline_steps AS step
JOIN slice
USING (slice_id)
JOIN args
USING (arg_set_id)
WHERE
step.step = 'STEP_RESAMPLE_SCROLL_EVENTS'
AND args.flat_key = 'chrome_latency_info.coalesced_trace_ids'
AND coalesced_latency_id != presented_latency_id;
CREATE PERFETTO TABLE chrome_touch_move_to_scroll_update (
touch_move_latency_id LONG,
scroll_update_latency_id LONG
) AS
WITH
scroll_update_steps AS MATERIALIZED (
SELECT
*
FROM chrome_input_pipeline_steps
WHERE
step = 'STEP_SEND_INPUT_EVENT_UI' AND input_type = 'GESTURE_SCROLL_UPDATE_EVENT'
),
default_mapping AS MATERIALIZED (
SELECT
touch_move_handled_step.latency_id AS touch_move_latency_id,
scroll_update_step.latency_id AS scroll_update_latency_id
FROM _interval_intersect!(
(
(
SELECT slice_id AS id, *
FROM scroll_update_steps
WHERE dur > 0
),
(
SELECT slice_id AS id, *
FROM chrome_input_pipeline_steps step
WHERE step = 'STEP_TOUCH_EVENT_HANDLED'
AND dur > 0
)
),
(utid)
) AS ii
JOIN scroll_update_steps AS scroll_update_step
ON ii.id_0 = scroll_update_step.slice_id
JOIN chrome_input_pipeline_steps AS touch_move_handled_step
ON ii.id_1 = touch_move_handled_step.slice_id
WHERE
ii.ts = scroll_update_step.ts AND ii.dur = scroll_update_step.dur
),
fallback_mapping AS MATERIALIZED (
SELECT
send_touch_move_step.latency_id AS touch_move_latency_id,
scroll_update_step.latency_id AS scroll_update_latency_id
FROM _interval_intersect!(
(
(
SELECT slice_id AS id, *
FROM scroll_update_steps
WHERE dur > 0
),
(
SELECT slice_id AS id, *
FROM chrome_input_pipeline_steps step
WHERE step = 'STEP_SEND_INPUT_EVENT_UI'
AND input_type = 'TOUCH_MOVE_EVENT'
AND dur > 0
)
),
(utid)
) AS ii
JOIN scroll_update_steps AS scroll_update_step
ON ii.id_0 = scroll_update_step.slice_id
JOIN chrome_input_pipeline_steps AS send_touch_move_step
ON ii.id_1 = send_touch_move_step.slice_id
WHERE
ii.ts = scroll_update_step.ts AND ii.dur = scroll_update_step.dur
),
scroll_update_latency_ids AS (
SELECT
scroll_update_latency_id
FROM default_mapping
UNION
SELECT
scroll_update_latency_id
FROM fallback_mapping
)
SELECT
coalesce(default_mapping.touch_move_latency_id, fallback_mapping.touch_move_latency_id) AS touch_move_latency_id,
scroll_update_latency_id
FROM scroll_update_latency_ids
LEFT JOIN default_mapping
USING (scroll_update_latency_id)
LEFT JOIN fallback_mapping
USING (scroll_update_latency_id);
CREATE PERFETTO TABLE chrome_dispatch_android_input_event_to_touch_move (
android_input_id STRING,
touch_move_latency_id LONG
) AS
SELECT
chrome_deliver_android_input_event.android_input_id,
latency_id AS touch_move_latency_id
FROM chrome_deliver_android_input_event
LEFT JOIN chrome_input_pipeline_steps
USING (utid)
WHERE
chrome_input_pipeline_steps.input_type = 'TOUCH_MOVE_EVENT'
AND chrome_input_pipeline_steps.step = 'STEP_SEND_INPUT_EVENT_UI'
AND chrome_deliver_android_input_event.ts <= chrome_input_pipeline_steps.ts
AND chrome_deliver_android_input_event.ts + chrome_deliver_android_input_event.dur >= chrome_input_pipeline_steps.ts + chrome_input_pipeline_steps.dur;