1-- Copyright 2024 The Chromium Authors 2-- Use of this source code is governed by a BSD-style license that can be 3-- found in the LICENSE file. 4 5INCLUDE PERFETTO MODULE slices.with_context; 6 7-- This module defines tables with information about Android input pipeline 8-- steps. The trace needs to be recorded with the 'view' atrace category. 9 10-- On Android, input goes through the following path before getting to Chrome: 11-- * InputReader thread (part of Android system_server) 12-- * InputDispatcher thread (part of Android system_server) 13-- * Browser Main thread (Chromium/Chrome) 14 15-- In traces, each of these three steps have slices which are implicitly linked 16-- together by an input id (part of slice name) assigned by the Android system. 17 18-- The following queries correlate the three steps mentioned above 19-- with the rest of the `LatencyInfo.Flow` pipeline. 20 21-- InputReader is the first step in the input pipeline. 22-- It is responsible for reading the input events from the system_server 23-- process and sending them to the InputDispatcher (which then sends them 24-- to the browser process). 25 26CREATE PERFETTO TABLE _chrome_android_motion_input_reader_step( 27-- Input reader step timestamp. 28 ts TIMESTAMP, 29 -- Input reader step duration. 30 dur DURATION, 31 -- Input reader step slice id. 32 id LONG, 33 -- Input id. 34 android_input_id STRING, 35 -- Input reader step utid. 36 utid LONG 37) 38AS 39SELECT 40 ts, 41 dur, 42 id, 43 -- Get the substring that starts with 'id=', remove the 'id=' and remove the trailing ')'. 44 -- 'id=0x344bb0f9)' -> '0x344bb0f9' 45 TRIM( 46 SUBSTR( 47 SUBSTR(name, INSTR(name, 'id=')) 48 , 4), 49 ')') 50 AS android_input_id, 51 utid 52FROM thread_slice AS slice 53WHERE 54 name GLOB 'UnwantedInteractionBlocker::notifyMotion*'; 55 56-- InputDispatcher is the second step in the input pipeline. 57-- It is responsible for dispatching the input events to the browser process. 58CREATE PERFETTO TABLE _chrome_android_motion_input_dispatcher_step( 59 -- Input dispatcher step timestamp. 60 ts TIMESTAMP, 61 -- Input dispatcher step duration. 62 dur DURATION, 63 -- Input dispatcher step slice id. 64 id LONG, 65 -- Input id. 66 android_input_id STRING, 67 -- Input dispatcher step utid. 68 utid LONG 69) 70AS 71SELECT 72 ts, 73 dur, 74 id, 75 TRIM( 76 SUBSTR( 77 SUBSTR(name, INSTR(name, 'id=')) 78 , 4), ')') 79 AS android_input_id, 80 utid 81FROM thread_slice AS slice 82WHERE 83 name GLOB 'prepareDispatchCycleLocked*chrome*'; 84 85-- DeliverInputEvent is the third step in the input pipeline. 86-- It is responsible for routing the input events within browser process. 87CREATE PERFETTO TABLE chrome_deliver_android_input_event( 88 -- Timestamp. 89 ts TIMESTAMP, 90 -- Touch move processing duration. 91 dur DURATION, 92 -- Utid. 93 utid LONG, 94 -- Input id (assigned by the system, used by InputReader and InputDispatcher) 95 android_input_id STRING 96) AS 97SELECT 98 slice.ts, 99 slice.dur, 100 slice.utid, 101 SUBSTR(SUBSTR(name, INSTR(name, 'id=')), 4) AS android_input_id 102FROM 103 thread_slice AS slice 104WHERE 105 slice.name GLOB 'deliverInputEvent*'; 106 107-- Collects information about input reader, input dispatcher and 108-- DeliverInputEvent steps for the given Android input id. 109CREATE PERFETTO TABLE chrome_android_input( 110 -- Input id. 111 android_input_id STRING, 112 -- Input reader step start timestamp. 113 input_reader_processing_start_ts TIMESTAMP, 114 -- Input reader step end timestamp. 115 input_reader_processing_end_ts TIMESTAMP, 116 -- Input reader step utid. 117 input_reader_utid LONG, 118 -- Input dispatcher step start timestamp. 119 input_dispatcher_processing_start_ts TIMESTAMP, 120 -- Input dispatcher step end timestamp. 121 input_dispatcher_processing_end_ts TIMESTAMP, 122 -- Input dispatcher step utid. 123 input_dispatcher_utid LONG, 124 -- DeliverInputEvent step start timestamp. 125 deliver_input_event_start_ts TIMESTAMP, 126 -- DeliverInputEvent step end timestamp. 127 deliver_input_event_end_ts TIMESTAMP, 128 -- DeliverInputEvent step utid. 129 deliver_input_event_utid LONG 130) AS 131SELECT 132 _chrome_android_motion_input_reader_step.android_input_id, 133 _chrome_android_motion_input_reader_step.ts AS input_reader_processing_start_ts, 134 _chrome_android_motion_input_reader_step.ts + 135 _chrome_android_motion_input_reader_step.dur AS input_reader_processing_end_ts, 136 _chrome_android_motion_input_reader_step.utid AS input_reader_utid, 137 _chrome_android_motion_input_dispatcher_step.ts AS input_dispatcher_processing_start_ts, 138 _chrome_android_motion_input_dispatcher_step.ts + 139 _chrome_android_motion_input_dispatcher_step.dur AS input_dispatcher_processing_end_ts, 140 _chrome_android_motion_input_dispatcher_step.utid AS input_dispatcher_utid, 141 chrome_deliver_android_input_event.ts AS deliver_input_event_start_ts, 142 chrome_deliver_android_input_event.ts + 143 chrome_deliver_android_input_event.dur AS deliver_input_event_end_ts, 144 chrome_deliver_android_input_event.utid AS deliver_input_event_utid 145FROM 146 _chrome_android_motion_input_reader_step 147LEFT JOIN 148 _chrome_android_motion_input_dispatcher_step USING(android_input_id) 149LEFT JOIN 150 chrome_deliver_android_input_event USING(android_input_id) 151