File: android_input.sql

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (134 lines) | stat: -rw-r--r-- 5,014 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
-- Copyright 2024 The Chromium Authors
-- Use of this source code is governed by a BSD-style license that can be
-- found in the LICENSE file.

INCLUDE PERFETTO MODULE slices.with_context;

-- This module defines tables with information about Android input pipeline
-- steps. The trace needs to be recorded with the 'view' atrace category.

-- On Android, input goes through the following path before getting to Chrome:
--  * InputReader thread (part of Android system_server)
--  * InputDispatcher thread (part of Android system_server)
--  * Browser Main thread (Chromium/Chrome)

-- In traces, each of these three steps have slices which are implicitly linked
-- together by an input id (part of slice name) assigned by the Android system.

-- The following queries correlate the three steps mentioned above
-- with the rest of the `LatencyInfo.Flow` pipeline.

-- InputReader is the first step in the input pipeline.
-- It is responsible for reading the input events from the system_server
-- process and sending them to the InputDispatcher (which then sends them
-- to the browser process).

CREATE PERFETTO TABLE _chrome_android_motion_input_reader_step (
  -- Input reader step timestamp.
  ts TIMESTAMP,
  -- Input reader step duration.
  dur DURATION,
  -- Input reader step slice id.
  id LONG,
  -- Input id.
  android_input_id STRING,
  -- Input reader step utid.
  utid LONG
) AS
SELECT
  ts,
  dur,
  id,
  -- Get the substring that starts with 'id=', remove the 'id=' and remove the trailing ')'.
  -- 'id=0x344bb0f9)' ->  '0x344bb0f9'
  trim(substr(substr(name, instr(name, 'id=')), 4), ')') AS android_input_id,
  utid
FROM thread_slice AS slice
WHERE
  name GLOB 'UnwantedInteractionBlocker::notifyMotion*';

-- InputDispatcher is the second step in the input pipeline.
-- It is responsible for dispatching the input events to the browser process.
CREATE PERFETTO TABLE _chrome_android_motion_input_dispatcher_step (
  -- Input dispatcher step timestamp.
  ts TIMESTAMP,
  -- Input dispatcher step duration.
  dur DURATION,
  -- Input dispatcher step slice id.
  id LONG,
  -- Input id.
  android_input_id STRING,
  -- Input dispatcher step utid.
  utid LONG
) AS
SELECT
  ts,
  dur,
  id,
  trim(substr(substr(name, instr(name, 'id=')), 4), ')') AS android_input_id,
  utid
FROM thread_slice AS slice
WHERE
  name GLOB 'prepareDispatchCycleLocked*chrome*';

-- DeliverInputEvent is the third step in the input pipeline.
-- It is responsible for routing the input events within browser process.
CREATE PERFETTO TABLE chrome_deliver_android_input_event (
  -- Timestamp.
  ts TIMESTAMP,
  -- Touch move processing duration.
  dur DURATION,
  -- Utid.
  utid LONG,
  -- Input id (assigned by the system, used by InputReader and InputDispatcher)
  android_input_id STRING
) AS
SELECT
  slice.ts,
  slice.dur,
  slice.utid,
  substr(substr(name, instr(name, 'id=')), 4) AS android_input_id
FROM thread_slice AS slice
WHERE
  slice.name GLOB 'deliverInputEvent*';

-- Collects information about input reader, input dispatcher and
-- DeliverInputEvent steps for the given Android input id.
CREATE PERFETTO TABLE chrome_android_input (
  -- Input id.
  android_input_id STRING,
  -- Input reader step start timestamp.
  input_reader_processing_start_ts TIMESTAMP,
  -- Input reader step end timestamp.
  input_reader_processing_end_ts TIMESTAMP,
  -- Input reader step utid.
  input_reader_utid LONG,
  -- Input dispatcher step start timestamp.
  input_dispatcher_processing_start_ts TIMESTAMP,
  -- Input dispatcher step end timestamp.
  input_dispatcher_processing_end_ts TIMESTAMP,
  -- Input dispatcher step utid.
  input_dispatcher_utid LONG,
  -- DeliverInputEvent step start timestamp.
  deliver_input_event_start_ts TIMESTAMP,
  -- DeliverInputEvent step end timestamp.
  deliver_input_event_end_ts TIMESTAMP,
  -- DeliverInputEvent step utid.
  deliver_input_event_utid LONG
) AS
SELECT
  _chrome_android_motion_input_reader_step.android_input_id,
  _chrome_android_motion_input_reader_step.ts AS input_reader_processing_start_ts,
  _chrome_android_motion_input_reader_step.ts + _chrome_android_motion_input_reader_step.dur AS input_reader_processing_end_ts,
  _chrome_android_motion_input_reader_step.utid AS input_reader_utid,
  _chrome_android_motion_input_dispatcher_step.ts AS input_dispatcher_processing_start_ts,
  _chrome_android_motion_input_dispatcher_step.ts + _chrome_android_motion_input_dispatcher_step.dur AS input_dispatcher_processing_end_ts,
  _chrome_android_motion_input_dispatcher_step.utid AS input_dispatcher_utid,
  chrome_deliver_android_input_event.ts AS deliver_input_event_start_ts,
  chrome_deliver_android_input_event.ts + chrome_deliver_android_input_event.dur AS deliver_input_event_end_ts,
  chrome_deliver_android_input_event.utid AS deliver_input_event_utid
FROM _chrome_android_motion_input_reader_step
LEFT JOIN _chrome_android_motion_input_dispatcher_step
  USING (android_input_id)
LEFT JOIN chrome_deliver_android_input_event
  USING (android_input_id);