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-- 16 17INCLUDE PERFETTO MODULE slices.with_context; 18INCLUDE PERFETTO MODULE android.binder; 19INCLUDE PERFETTO MODULE graphs.search; 20 21-- Details of all Service#onBind dispatched events. 22CREATE PERFETTO TABLE _bind_dispatch 23AS 24WITH 25 next_sibling AS MATERIALIZED ( 26 SELECT * 27 FROM 28 graph_next_sibling!( 29 ( 30 SELECT id AS node_id, parent_id AS node_parent_id, ts AS sort_key 31 FROM slice 32 WHERE dur = 0 33 ) 34 ) 35 ), 36 service AS ( 37 SELECT 38 next_slice.id, 39 next_slice.ts, 40 next_slice.dur, 41 next_slice.name, 42 slice.utid, 43 slice.name AS bind_seq_name 44 FROM next_sibling 45 JOIN thread_slice slice 46 ON slice.id = next_sibling.node_id 47 JOIN slice next_slice 48 ON next_slice.id = next_sibling.next_node_id 49 ) 50 SELECT 51 id, 52 ts, 53 dur, 54 utid, 55 CAST(STR_SPLIT(STR_SPLIT(bind_seq_name, 'bindSeq=', 1), ' ', 0) AS INT) AS bind_seq 56FROM service 57WHERE bind_seq_name GLOB 'requestServiceBinding*' AND name = 'binder transaction async'; 58 59-- Details of all Service#onBind received events. 60CREATE PERFETTO TABLE _bind_receive 61AS 62SELECT 63 id, 64 ts, 65 dur, 66 track_id, 67 REPLACE(STR_SPLIT(STR_SPLIT(name, 'token=', 1), ' ', 0), 'ServiceRecord{', '') AS token, 68 STR_SPLIT(STR_SPLIT(name, 'act=', 1), ' ', 0) AS act, 69 STR_SPLIT(STR_SPLIT(name, 'cmp=', 1), ' ', 0) AS cmp, 70 STR_SPLIT(STR_SPLIT(name, 'flg=', 1), ' ', 0) AS flg, 71 CAST(STR_SPLIT(STR_SPLIT(name, 'bindSeq=', 1), '}', 0) AS INT) AS bind_seq 72FROM slice 73WHERE name GLOB 'serviceBind:*'; 74 75-- All service bindings from client app to server app. 76CREATE PERFETTO TABLE android_service_bindings( 77 -- OOM score of client process making the binding. 78 client_oom_score INT, 79 -- Name of client process making the binding. 80 client_process STRING, 81 -- Name of client thread making the binding. 82 client_thread STRING, 83 -- Pid of client process making the binding. 84 client_pid INT, 85 -- Tid of client process making the binding. 86 client_tid INT, 87 -- Upid of client process making the binding. 88 client_upid INT, 89 -- Utid of client thread making the binding. 90 client_utid INT, 91 -- Timestamp the client process made the request. 92 client_ts INT, 93 -- Duration of the client binding request. 94 client_dur INT, 95 -- OOM score of server process getting bound to. 96 server_oom_score INT, 97 -- Name of server process getting bound to 98 server_process STRING, 99 -- Name of server thread getting bound to. 100 server_thread STRING, 101 -- Pid of server process getting bound to. 102 server_pid INT, 103 -- Tid of server process getting bound to. 104 server_tid INT, 105 -- Upid of server process getting bound to. 106 server_upid INT, 107 -- Utid of server process getting bound to. 108 server_utid INT, 109 -- Timestamp the server process got bound to. 110 server_ts INT, 111 -- Duration of the server process handling the binding. 112 server_dur INT, 113 -- Unique binder identifier for the Service binding. 114 token STRING, 115 -- Intent action name for the service binding. 116 act STRING, 117 -- Intent component name for the service binding. 118 cmp STRING, 119 -- Intent flag for the service binding. 120 flg STRING, 121 -- Monotonically increasing id for the service binding. 122 bind_seq INT) 123AS 124SELECT 125 COALESCE(client_binder.client_oom_score, server_binder.client_oom_score) AS client_oom_score, 126 COALESCE(client_binder.client_process, server_binder.client_process) AS client_process, 127 COALESCE(client_binder.client_thread, server_binder.client_thread) AS client_thread, 128 COALESCE(client_binder.client_pid, server_binder.client_pid) AS client_pid, 129 COALESCE(client_binder.client_tid, server_binder.client_tid) AS client_tid, 130 COALESCE(client_binder.client_upid, server_binder.client_upid) AS client_upid, 131 COALESCE(client_binder.client_utid, server_binder.client_utid) AS client_utid, 132 COALESCE(client_binder.client_ts, server_binder.client_ts) AS client_ts, 133 COALESCE(client_binder.client_dur, server_binder.client_dur) AS client_dur, 134 server_binder.server_oom_score, 135 server_binder.server_process, 136 server_binder.server_thread, 137 server_binder.server_pid, 138 server_binder.server_tid, 139 server_binder.server_upid, 140 server_binder.server_utid, 141 receive.ts AS server_ts, 142 receive.dur AS server_dur, 143 receive.token, 144 receive.act, 145 receive.cmp, 146 receive.flg, 147 receive.bind_seq 148FROM _bind_dispatch dispatch 149JOIN _bind_receive receive 150 ON dispatch.bind_seq = receive.bind_seq 151LEFT JOIN android_binder_txns server_binder 152 ON server_binder.binder_txn_id = dispatch.id 153LEFT JOIN ancestor_slice(dispatch.id) anc ON anc.depth = 0 154LEFT JOIN android_binder_txns client_binder 155 ON client_binder.server_ts = anc.ts AND dispatch.utid = client_binder.server_utid; 156