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