1-- 2-- Copyright 2023 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 17-- List of all ANRs that occurred in the trace (one row per ANR). 18CREATE PERFETTO VIEW android_anrs ( 19 -- Name of the process that triggered the ANR. 20 process_name STRING, 21 -- PID of the process that triggered the ANR. 22 pid LONG, 23 -- UPID of the process that triggered the ANR. 24 upid JOINID(process.id), 25 -- UUID of the ANR (generated on the platform). 26 error_id STRING, 27 -- Timestamp of the ANR. 28 ts TIMESTAMP, 29 -- Subject line of the ANR. 30 subject STRING 31) AS 32-- Process and PID that ANRed. 33WITH 34 anr AS ( 35 SELECT 36 -- Counter formats: 37 -- v1: "ErrorId:<process_name>#<UUID>" 38 -- v2: "ErrorId:<process_name> <pid>#<UUID>" 39 str_split(substr(str_split(process_counter_track.name, '#', 0), 9), ' ', 0) AS process_name, 40 cast_int!(STR_SPLIT(SUBSTR(STR_SPLIT(process_counter_track.name, '#', 0), 9), ' ', 1)) AS pid, 41 str_split(process_counter_track.name, '#', 1) AS error_id, 42 counter.ts 43 FROM process_counter_track 44 JOIN process 45 USING (upid) 46 JOIN counter 47 ON ( 48 counter.track_id = process_counter_track.id 49 ) 50 WHERE 51 process_counter_track.name GLOB 'ErrorId:*' AND process.name = 'system_server' 52 ), 53 -- ANR subject line. 54 subject AS ( 55 --- Counter format: 56 --- "Subject(for ErrorId <UUID>):<subject>" 57 SELECT 58 substr(str_split(process_counter_track.name, ')', 0), 21) AS error_id, 59 substr( 60 process_counter_track.name, 61 length(str_split(process_counter_track.name, ')', 0)) + 3 62 ) AS subject 63 FROM process_counter_track 64 JOIN process 65 USING (upid) 66 WHERE 67 process_counter_track.name GLOB 'Subject(for ErrorId *' 68 AND process.name = 'system_server' 69 ) 70SELECT 71 anr.process_name, 72 anr.pid, 73 process.upid, 74 anr.error_id, 75 anr.ts, 76 subject 77FROM anr 78LEFT JOIN subject 79 USING (error_id) 80LEFT JOIN process 81 ON ( 82 process.pid = anr.pid 83 ); 84