xref: /aosp_15_r20/external/perfetto/src/trace_processor/perfetto_sql/stdlib/android/anrs.sql (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 anr AS (
34  SELECT
35    -- Counter formats:
36    -- v1: "ErrorId:<process_name>#<UUID>"
37    -- v2: "ErrorId:<process_name> <pid>#<UUID>"
38    STR_SPLIT(SUBSTR(STR_SPLIT(process_counter_track.name, '#', 0), 9), ' ', 0) AS process_name,
39    cast_int!(STR_SPLIT(SUBSTR(STR_SPLIT(process_counter_track.name, '#', 0), 9), ' ', 1)) AS pid,
40    STR_SPLIT(process_counter_track.name, '#', 1) AS error_id,
41    counter.ts
42  FROM process_counter_track
43  JOIN process USING (upid)
44  JOIN counter ON (counter.track_id = process_counter_track.id)
45  WHERE process_counter_track.name GLOB 'ErrorId:*'
46    AND process.name = 'system_server'
47),
48-- ANR subject line.
49subject AS (
50  --- Counter format:
51  --- "Subject(for ErrorId <UUID>):<subject>"
52  SELECT
53    SUBSTR(STR_SPLIT(process_counter_track.name, ')', 0), 21) AS error_id,
54    SUBSTR(process_counter_track.name, length(STR_SPLIT(process_counter_track.name, ')', 0)) + 3) AS subject
55  FROM process_counter_track
56  JOIN process
57  USING (upid)
58  WHERE process_counter_track.name GLOB 'Subject(for ErrorId *'
59  AND process.name = 'system_server'
60)
61SELECT
62    anr.process_name,
63    anr.pid,
64    process.upid,
65    anr.error_id,
66    anr.ts,
67    subject
68FROM anr
69LEFT JOIN subject USING (error_id)
70LEFT JOIN process ON (process.pid = anr.pid);