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 16CREATE PERFETTO TABLE _input_message_sent 17AS 18SELECT 19 STR_SPLIT(STR_SPLIT(slice.name, '=', 3), ')', 0) AS event_type, 20 STR_SPLIT(STR_SPLIT(slice.name, '=', 2), ',', 0) AS event_seq, 21 STR_SPLIT(STR_SPLIT(slice.name, '=', 1), ',', 0) AS event_channel, 22 thread.tid, 23 thread.name AS thread_name, 24 process.pid, 25 process.name AS process_name, 26 slice.ts, 27 slice.dur, 28 slice.track_id 29FROM slice 30JOIN thread_track 31 ON thread_track.id = slice.track_id 32JOIN thread 33 USING (utid) 34JOIN process 35 USING (upid) 36WHERE slice.name GLOB 'sendMessage(*'; 37 38CREATE PERFETTO TABLE _input_message_received 39AS 40SELECT 41 STR_SPLIT(STR_SPLIT(slice.name, '=', 3), ')', 0) AS event_type, 42 STR_SPLIT(STR_SPLIT(slice.name, '=', 2), ',', 0) AS event_seq, 43 STR_SPLIT(STR_SPLIT(slice.name, '=', 1), ',', 0) AS event_channel, 44 thread.tid, 45 thread.name AS thread_name, 46 process.pid, 47 process.name AS process_name, 48 slice.ts, 49 slice.dur, 50 slice.track_id 51FROM slice 52JOIN thread_track 53 ON thread_track.id = slice.track_id 54JOIN thread 55 USING (utid) 56JOIN process 57 USING (upid) 58WHERE slice.name GLOB 'receiveMessage(*'; 59 60-- All input events with round trip latency breakdown. Input delivery is socket based and every 61-- input event sent from the OS needs to be ACK'ed by the app. This gives us 4 subevents to measure 62-- latencies between: 63-- 1. Input dispatch event sent from OS. 64-- 2. Input dispatch event received in app. 65-- 3. Input ACK event sent from app. 66-- 4. Input ACk event received in OS. 67CREATE PERFETTO TABLE android_input_events ( 68 -- Duration from input dispatch to input received. 69 dispatch_latency_dur INT, 70 -- Duration from input received to input ACK sent. 71 handling_latency_dur INT, 72 -- Duration from input ACK sent to input ACK recieved. 73 ack_latency_dur INT, 74 -- Duration from input dispatch to input event ACK received. 75 total_latency_dur INT, 76 -- Tid of thread receiving the input event. 77 tid INT, 78 -- Name of thread receiving the input event. 79 thread_name INT, 80 -- Pid of process receiving the input event. 81 pid INT, 82 -- Name of process receiving the input event. 83 process_name INT, 84 -- Input event type. See InputTransport.h: InputMessage#Type 85 event_type INT, 86 -- Input event sequence number, monotonically increasing for an event channel and pid. 87 event_seq INT, 88 -- Input event channel name. 89 event_channel INT, 90 -- Thread track id of input event dispatching thread. 91 dispatch_track_id INT, 92 -- Timestamp input event was dispatched. 93 dispatch_ts INT, 94 -- Duration of input event dispatch. 95 dispatch_dur INT, 96 -- Thread track id of input event receiving thread. 97 receive_track_id INT, 98 -- Timestamp input event was received. 99 receive_ts INT, 100 -- Duration of input event receipt. 101 receive_dur INT 102 ) 103AS 104SELECT 105 receive.ts - dispatch.ts AS dispatch_latency_dur, 106 finish.ts - receive.ts AS handling_latency_dur, 107 finish_ack.ts - finish.ts AS ack_latency_dur, 108 finish_ack.ts - dispatch.ts AS total_latency_dur, 109 finish.tid AS tid, 110 finish.thread_name AS thread_name, 111 finish.pid AS pid, 112 finish.process_name AS process_name, 113 dispatch.event_type, 114 dispatch.event_seq, 115 dispatch.event_channel, 116 dispatch.track_id AS dispatch_track_id, 117 dispatch.ts AS dispatch_ts, 118 dispatch.dur AS dispatch_dur, 119 receive.ts AS receive_ts, 120 receive.dur AS receive_dur, 121 receive.track_id AS receive_track_id 122FROM (SELECT * FROM _input_message_sent WHERE thread_name = 'InputDispatcher') dispatch 123JOIN (SELECT * FROM _input_message_received WHERE event_type != '0x2') receive 124 ON 125 REPLACE(receive.event_channel, '(client)', '(server)') = dispatch.event_channel 126 AND dispatch.event_seq = receive.event_seq 127JOIN (SELECT * FROM _input_message_sent WHERE thread_name != 'InputDispatcher') finish 128 ON 129 REPLACE(finish.event_channel, '(client)', '(server)') = dispatch.event_channel 130 AND dispatch.event_seq = finish.event_seq 131JOIN (SELECT * FROM _input_message_received WHERE event_type = '0x2') finish_ack 132 ON finish_ack.event_channel = dispatch.event_channel AND dispatch.event_seq = finish_ack.event_seq; 133 134-- Key events processed by the Android framework (from android.input.inputevent data source). 135CREATE PERFETTO VIEW android_key_events( 136 -- ID of the trace entry 137 id INT, 138 -- The randomly-generated ID associated with each input event processed 139 -- by Android Framework, used to track the event through the input pipeline 140 event_id INT, 141 -- The timestamp of when the input event was processed by the system 142 ts INT, 143 -- Details of the input event parsed from the proto message 144 arg_set_id INT 145) AS 146SELECT 147 id, 148 event_id, 149 ts, 150 arg_set_id 151FROM __intrinsic_android_key_events; 152 153-- Motion events processed by the Android framework (from android.input.inputevent data source). 154CREATE PERFETTO VIEW android_motion_events( 155 -- ID of the trace entry 156 id INT, 157 -- The randomly-generated ID associated with each input event processed 158 -- by Android Framework, used to track the event through the input pipeline 159 event_id INT, 160 -- The timestamp of when the input event was processed by the system 161 ts INT, 162 -- Details of the input event parsed from the proto message 163 arg_set_id INT 164) AS 165SELECT 166 id, 167 event_id, 168 ts, 169 arg_set_id 170FROM __intrinsic_android_motion_events; 171 172-- Input event dispatching information in Android (from android.input.inputevent data source). 173CREATE PERFETTO VIEW android_input_event_dispatch( 174 -- ID of the trace entry 175 id INT, 176 -- Event ID of the input event that was dispatched 177 event_id INT, 178 -- Extra args parsed from the proto message 179 arg_set_id INT, 180 -- Vsync ID that identifies the state of the windows during which the dispatch decision was made 181 vsync_id INT, 182 -- Window ID of the window receiving the event 183 window_id INT 184) AS 185SELECT 186 id, 187 event_id, 188 arg_set_id, 189 vsync_id, 190 window_id 191FROM __intrinsic_android_input_event_dispatch; 192