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