• 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--
16INCLUDE PERFETTO MODULE android.slices;
17
18INCLUDE PERFETTO MODULE android.binder;
19
20INCLUDE PERFETTO MODULE slices.with_context;
21
22CREATE PERFETTO FUNCTION _is_relevant_blocking_call(
23    name STRING,
24    depth LONG
25)
26RETURNS BOOL AS
27SELECT
28  $name = 'measure'
29  OR $name = 'layout'
30  OR $name = 'configChanged'
31  OR $name = 'animation'
32  OR $name = 'input'
33  OR $name = 'traversal'
34  OR $name = 'Contending for pthread mutex'
35  OR $name = 'postAndWait'
36  OR $name GLOB 'monitor contention with*'
37  OR $name GLOB 'SuspendThreadByThreadId*'
38  OR $name GLOB 'LoadApkAssetsFd*'
39  OR $name GLOB '*binder transaction*'
40  OR $name GLOB 'inflate*'
41  OR $name GLOB 'Lock contention on*'
42  OR $name GLOB 'android.os.Handler: kotlinx.coroutines*'
43  OR $name GLOB 'relayoutWindow*'
44  OR $name GLOB 'ImageDecoder#decode*'
45  OR $name GLOB 'NotificationStackScrollLayout#onMeasure'
46  OR $name GLOB 'ExpNotRow#*'
47  OR $name GLOB 'GC: Wait For*'
48  OR $name GLOB 'Recomposer:*'
49  OR $name GLOB 'Compose:*'
50  OR (
51    -- Some top level handler slices
52    $depth = 0
53    AND NOT $name GLOB '*Choreographer*'
54    AND NOT $name GLOB '*Input*'
55    AND NOT $name GLOB '*input*'
56    AND NOT $name GLOB 'android.os.Handler: #*'
57    AND (
58      -- Handler pattern heuristics
59      $name GLOB '*Handler: *$*'
60      OR $name GLOB '*.*.*: *$*'
61      OR $name GLOB '*.*$*: #*'
62    )
63  );
64
65--Extract critical blocking calls from all processes.
66CREATE PERFETTO TABLE _android_critical_blocking_calls AS
67SELECT
68  android_standardize_slice_name(s.name) AS name,
69  s.ts,
70  s.dur,
71  s.id,
72  s.process_name,
73  thread.utid,
74  s.upid,
75  s.ts + s.dur AS ts_end
76FROM thread_slice AS s
77JOIN thread
78  USING (utid)
79WHERE
80  _is_relevant_blocking_call(s.name, s.depth)
81UNION ALL
82-- As binder names are not included in slice table, extract these directly from the
83-- android_binder_txns table.
84SELECT
85  tx.aidl_name AS name,
86  tx.client_ts AS ts,
87  tx.client_dur AS dur,
88  tx.binder_txn_id AS id,
89  tx.client_process AS process_name,
90  tx.client_utid AS utid,
91  tx.client_upid AS upid,
92  tx.client_ts + tx.client_dur AS ts_end
93FROM android_binder_txns AS tx
94WHERE
95  NOT aidl_name IS NULL AND is_sync = 1;
96