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.freezer; 18 19CREATE PERFETTO FUNCTION _extract_broadcast_process_name(name STRING) 20RETURNS INT 21AS 22WITH 23 pid_and_name AS ( 24 SELECT STR_SPLIT(STR_SPLIT($name, '/', 0), ' ', 1) AS value 25 ), 26 start AS ( 27 SELECT CAST(INSTR(value, ':') AS INT) + 1 AS value FROM pid_and_name 28 ) 29SELECT SUBSTR(pid_and_name.value, start.value) FROM pid_and_name, start; 30 31-- Provides a list of broadcast names and processes they were sent to by the 32-- system_server process on U+ devices. 33CREATE PERFETTO TABLE _android_broadcasts_minsdk_u( 34 -- Intent action of the broadcast. 35 intent_action STRING, 36 -- Name of the process the broadcast was sent to. 37 process_name STRING, 38 -- Pid of the process the broadcast was sent to. 39 pid STRING, 40 -- Upid of the process the broadcast was sent to. 41 upid STRING, 42 -- Id of the broacast queue the broadcast was dispatched from. 43 queue_id INT, 44 -- Slice id of the broadcast dispatch. 45 id INT, 46 -- Timestamp the broadcast was dispatched. 47 ts INT, 48 -- Duration to dispatch the broadcast. 49 dur INT, 50 -- Track id the broadcast was dispatched from. 51 track_id INT 52) AS 53WITH 54 broadcast_queues AS ( 55 SELECT 56 process_track.id, 57 CAST(replace(str_split(process_track.name, '[', 1), ']', '') AS INT) AS queue_id 58 FROM process_track 59 JOIN process 60 USING (upid) 61 WHERE 62 process_track.name GLOB 'BroadcastQueue.mRunning*' 63 AND process.name = 'system_server' 64 ), 65 broadcast_process_running AS ( 66 SELECT 67 slice.id AS id, 68 slice.ts, 69 slice.dur, 70 broadcast_queues.queue_id, 71 _extract_broadcast_process_name(slice.name) AS process_name, 72 CAST(str_split(str_split(str_split(slice.name, '/', 0), ' ', 1), ':', 0) AS INT) AS pid, 73 queue_id 74 FROM slice 75 JOIN broadcast_queues 76 ON broadcast_queues.id = slice.track_id 77 WHERE slice.name GLOB '* running' 78 ), 79 broadcast_intent_action AS ( 80 SELECT 81 str_split(str_split(slice.name, '/', 0), ' ', 1) AS intent_action, 82 slice.parent_id, 83 slice.id AS intent_id, 84 slice.ts AS intent_ts, 85 slice.track_id AS track_id, 86 slice.dur AS intent_dur 87 FROM slice 88 WHERE slice.name GLOB '* scheduled' 89 ) 90 SELECT 91 broadcast_intent_action.intent_action, 92 broadcast_process_running.process_name, 93 broadcast_process_running.pid, 94 _pid_to_upid(broadcast_process_running.pid, broadcast_intent_action.intent_ts) AS upid, 95 broadcast_process_running.queue_id, 96 broadcast_intent_action.intent_id AS id, 97 broadcast_intent_action.intent_ts AS ts, 98 broadcast_intent_action.intent_dur AS dur, 99 broadcast_intent_action.track_id 100 FROM broadcast_intent_action 101 JOIN broadcast_process_running 102 ON parent_id = id; 103