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 android.binder; 18 19DROP TABLE IF EXISTS android_binder_process_incoming_serial_count_per_second; 20CREATE PERFETTO TABLE android_binder_process_incoming_serial_count_per_second 21AS 22WITH unagg AS ( 23 SELECT 24 server_process AS process_name, 25 server_pid AS pid, 26 server_ts AS ts, 27 COUNT() 28 OVER ( 29 PARTITION BY server_upid 30 ORDER BY server_ts 31 RANGE BETWEEN cast_int!(1e9) PRECEDING AND CURRENT ROW 32 ) AS count_per_second 33 FROM android_binder_txns 34) SELECT process_name, pid, MAX(count_per_second) AS max_count_per_second 35 FROM unagg GROUP BY pid; 36 37DROP TABLE IF EXISTS android_binder_process_outgoing_serial_count_per_second; 38CREATE PERFETTO TABLE android_binder_process_outgoing_serial_count_per_second 39AS 40WITH unagg AS ( 41 SELECT 42 client_process AS process_name, 43 client_pid AS pid, 44 client_ts AS ts, 45 COUNT() 46 OVER ( 47 PARTITION BY client_upid 48 ORDER BY client_ts 49 RANGE BETWEEN cast_int!(1e9) PRECEDING AND CURRENT ROW 50 ) AS count_per_second 51 FROM android_binder_txns 52) SELECT process_name, pid, MAX(count_per_second) AS max_count_per_second 53 FROM unagg GROUP BY pid; 54 55DROP VIEW IF EXISTS android_anomaly_output; 56CREATE PERFETTO VIEW android_anomaly_output AS 57SELECT AndroidAnomalyMetric( 58 'binder', (SELECT AndroidAnomalyMetric_Binder( 59 'max_incoming_process_count_per_second', ( 60 SELECT RepeatedField( 61 AndroidAnomalyMetric_ProcessAnomaly( 62 'process_name', process_name, 63 'pid', pid, 64 'unit', 'COUNT_PER_SECOND', 65 'value', max_count_per_second 66 ) 67 ) 68 FROM android_binder_process_incoming_serial_count_per_second 69 ), 70 'max_outgoing_process_count_per_second', ( 71 SELECT RepeatedField( 72 AndroidAnomalyMetric_ProcessAnomaly( 73 'process_name', process_name, 74 'pid', pid, 75 'unit', 'COUNT_PER_SECOND', 76 'value', max_count_per_second 77 ) 78 ) 79 FROM android_binder_process_outgoing_serial_count_per_second 80 ) 81 )) 82); 83