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 PERFETTO 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 PERFETTO 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 PERFETTO 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 long latency metric output. 67DROP VIEW IF EXISTS chrome_long_latency_output; 68CREATE PERFETTO VIEW chrome_long_latency_output AS 69SELECT ChromeLongLatency( 70 'long_latency', ( 71 SELECT RepeatedField( 72 ChromeLongLatency_LongLatency( 73 'ts', ts, 74 'event_type', event_type, 75 'process_name', process_name, 76 'pid', process_id 77 ) 78 ) 79 FROM long_latency_with_process_info 80 ORDER BY ts 81 ) 82); 83