• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2022 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 android.binder_breakdown;
18
19-- Count Binder transactions per process
20DROP VIEW IF EXISTS binder_metrics_by_process;
21CREATE PERFETTO VIEW binder_metrics_by_process AS
22SELECT * FROM android_binder_metrics_by_process;
23
24DROP TABLE IF EXISTS logical_binder_breakdown;
25CREATE PERFETTO TABLE logical_binder_breakdown AS
26SELECT binder_txn_id, 'binder_txn' AS thread_state_type, reason, SUM(dur) AS reason_dur
27FROM android_binder_client_breakdown GROUP BY binder_txn_id, reason
28UNION ALL
29SELECT binder_txn_id, 'binder_reply' AS thread_state_type, reason, SUM(dur) AS reason_dur
30FROM android_binder_server_breakdown GROUP BY binder_txn_id, reason;
31
32DROP VIEW IF EXISTS android_binder_output;
33CREATE PERFETTO VIEW android_binder_output AS
34SELECT AndroidBinderMetric(
35  'process_breakdown', (
36    SELECT RepeatedField(
37      AndroidBinderMetric_PerProcessBreakdown(
38        'process_name', process_name,
39        'pid', pid,
40        'slice_name', slice_name,
41        'count', event_count
42      )
43    )
44    FROM android_binder_metrics_by_process
45  ),
46  'unaggregated_txn_breakdown', (
47    SELECT RepeatedField(
48      AndroidBinderMetric_UnaggregatedTxnBreakdown(
49        'aidl_name', aidl_name,
50        'aidl_ts', aidl_ts,
51        'aidl_dur', aidl_dur,
52        'client_process', client_process,
53        'client_thread', client_thread,
54        'is_main_thread', is_main_thread,
55        'client_ts', client_ts,
56        'client_dur', client_dur,
57        'client_tid', client_tid,
58        'client_pid', client_pid,
59        'client_oom_score', client_oom_score,
60        'server_process', server_process,
61        'server_thread', server_thread,
62        'server_ts', server_ts,
63        'server_dur', server_dur,
64        'server_tid', server_tid,
65        'server_pid', server_pid,
66        'server_oom_score', server_oom_score,
67        'is_sync', is_sync,
68        'client_monotonic_dur', client_monotonic_dur,
69        'server_monotonic_dur', server_monotonic_dur,
70        'client_package_version_code', client_package_version_code,
71        'server_package_version_code', server_package_version_code,
72        'is_client_package_debuggable', is_client_package_debuggable,
73        'is_server_package_debuggable', is_server_package_debuggable,
74        'thread_states', (
75          SELECT RepeatedField(
76            AndroidBinderMetric_ThreadStateBreakdown(
77              'thread_state_type', thread_state_type,
78              'thread_state', thread_state,
79              'thread_state_dur', thread_state_dur,
80              'thread_state_count', thread_state_count
81            )
82          ) FROM android_sync_binder_thread_state_by_txn t
83            WHERE t.binder_txn_id = android_binder_txns.binder_txn_id
84        ),
85        'blocked_functions', (
86          SELECT RepeatedField(
87            AndroidBinderMetric_BlockedFunctionBreakdown(
88              'thread_state_type', thread_state_type,
89              'blocked_function', blocked_function,
90              'blocked_function_dur', blocked_function_dur,
91              'blocked_function_count', blocked_function_count
92            )
93          ) FROM android_sync_binder_blocked_functions_by_txn b
94            WHERE b.binder_txn_id = android_binder_txns.binder_txn_id
95        ),
96        'logical_reasons', (
97          SELECT RepeatedField(
98            AndroidBinderMetric_LogicalReasonBreakdown(
99              'thread_state_type', thread_state_type,
100              'reason', reason,
101              'reason_dur', reason_dur
102            )
103          ) FROM logical_binder_breakdown b
104            WHERE b.binder_txn_id = android_binder_txns.binder_txn_id
105        )
106      )
107    )
108    FROM android_binder_txns
109  )
110);
111