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