• 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-- Find all long EventLatency slices > 100ms and also get the
17-- type of the event stored as 'debug.event' argument.
18-- In order to group all events
19-- Note that a long latency event is represented by the the ending time
20-- of an EventLatency slice, i.e. the timestamp of the frame presentation
21-- that reflects the event.
22DROP VIEW IF EXISTS long_eventlatency_slice;
23CREATE VIEW long_eventlatency_slice AS
24SELECT
25  ts + dur AS ts,
26  dur,
27  id,
28  track_id,
29  EXTRACT_ARG(arg_set_id, 'debug.event') AS event_type
30FROM slice WHERE name = 'EventLatency' AND dur > 100000000;
31
32-- Find the upid of the proccesses where the long latency occur.
33DROP VIEW IF EXISTS long_latency_with_upid;
34CREATE VIEW long_latency_with_upid AS
35SELECT
36  long_eventlatency_slice.ts,
37  long_eventlatency_slice.event_type,
38  process_track.upid
39FROM long_eventlatency_slice
40INNER JOIN process_track
41ON long_eventlatency_slice.track_id = process_track.id;
42
43-- Find the name and pid of the processes.
44-- Long latency events with the same timestamp and from the same process
45-- are considered one single long latency occurrence.
46DROP VIEW IF EXISTS long_latency_with_process_info;
47CREATE VIEW long_latency_with_process_info AS
48SELECT
49  long_latency_with_upid.ts,
50  GROUP_CONCAT(DISTINCT long_latency_with_upid.event_type) AS event_type,
51  process.name AS process_name,
52  process.pid AS process_id
53FROM long_latency_with_upid
54INNER JOIN process
55ON long_latency_with_upid.upid = process.upid
56GROUP BY ts, process.pid;
57
58-- Create the derived event track for long latency.
59-- All tracks generated from chrome_long_latency_event are
60-- placed under a track group named 'Long Latency', whose summary
61-- track is the first track ('All Processes') in chrome_long_latency_event.
62-- Note that the 'All Processes' track is generated only when there are more
63-- than one source of long latency events.
64DROP VIEW IF EXISTS chrome_long_latency_event;
65CREATE VIEW chrome_long_latency_event AS
66SELECT
67  'slice' AS track_type,
68  'All Processes' AS track_name,
69  ts,
70  0 AS dur,
71  event_type AS slice_name,
72  'Long Latency' AS group_name
73FROM long_latency_with_process_info
74WHERE (SELECT COUNT(DISTINCT process_id)
75       FROM long_latency_with_process_info) > 1
76GROUP BY ts
77UNION ALL
78SELECT
79  'slice' AS track_type,
80  process_name || ' ' || process_id AS track_name,
81  ts,
82  0 AS dur,
83  event_type AS slice_name,
84  'Long Latency' AS group_name
85FROM long_latency_with_process_info
86GROUP BY ts;
87
88-- Create the long latency metric output.
89DROP VIEW IF EXISTS chrome_long_latency_output;
90CREATE VIEW chrome_long_latency_output AS
91SELECT ChromeLongLatency(
92  'long_latency', (
93    SELECT RepeatedField(
94      ChromeLongLatency_LongLatency(
95        'ts', ts,
96        'event_type', event_type,
97        'process_name', process_name,
98        'pid', process_id
99      )
100    )
101    FROM long_latency_with_process_info
102    ORDER BY ts
103  )
104);