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 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 40JOIN process_track 41 ON 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. 46-- If the process name represents a file's pathname, the path part will be 47-- removed from the display name of the process. 48DROP VIEW IF EXISTS long_latency_with_process_info; 49CREATE VIEW long_latency_with_process_info AS 50SELECT 51 long_latency_with_upid.ts, 52 GROUP_CONCAT(DISTINCT long_latency_with_upid.event_type) AS event_type, 53 REPLACE( 54 process.name, 55 RTRIM( 56 process.name, 57 REPLACE(process.name, '/', '') 58 ), 59 '') AS process_name, 60 process.pid AS process_id 61FROM long_latency_with_upid 62JOIN process 63 ON long_latency_with_upid.upid = process.upid 64GROUP BY ts, process.pid; 65 66-- Create the derived event track for long latency. 67-- All tracks generated from chrome_long_latency_event are 68-- placed under a track group named 'Long Latency', whose summary 69-- track is the first track ('All Processes') in chrome_long_latency_event. 70-- Note that the 'All Processes' track is generated only when there are more 71-- than one source of long latency events. 72DROP VIEW IF EXISTS chrome_long_latency_event; 73CREATE VIEW chrome_long_latency_event AS 74SELECT 75 'slice' AS track_type, 76 'All Processes' AS track_name, 77 ts, 78 0 AS dur, 79 event_type AS slice_name, 80 'Long Latency' AS group_name 81FROM long_latency_with_process_info 82WHERE (SELECT COUNT(DISTINCT process_id) 83 FROM long_latency_with_process_info) > 1 84GROUP BY ts 85UNION ALL 86SELECT 87 'slice' AS track_type, 88 process_name || ' ' || process_id AS track_name, 89 ts, 90 0 AS dur, 91 event_type AS slice_name, 92 'Long Latency' AS group_name 93FROM long_latency_with_process_info 94GROUP BY ts; 95 96-- Create the long latency metric output. 97DROP VIEW IF EXISTS chrome_long_latency_output; 98CREATE VIEW chrome_long_latency_output AS 99SELECT ChromeLongLatency( 100 'long_latency', ( 101 SELECT RepeatedField( 102 ChromeLongLatency_LongLatency( 103 'ts', ts, 104 'event_type', event_type, 105 'process_name', process_name, 106 'pid', process_id 107 ) 108 ) 109 FROM long_latency_with_process_info 110 ORDER BY ts 111 ) 112); 113