1-- 2-- Copyright 2024 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 16INCLUDE PERFETTO MODULE viz.summary.slices; 17 18CREATE PERFETTO TABLE _sched_summary AS 19SELECT 20 utid, 21 MAX(dur) AS max_running_dur, 22 SUM(dur) AS sum_running_dur, 23 COUNT() AS running_count 24FROM sched 25WHERE utid != 0 AND dur != -1 26GROUP BY utid; 27 28CREATE PERFETTO TABLE _thread_track_summary AS 29SELECT utid, SUM(cnt) AS slice_count 30FROM thread_track 31JOIN _slice_track_summary USING (id) 32GROUP BY utid; 33 34CREATE PERFETTO TABLE _perf_sample_summary AS 35SELECT utid, count() AS perf_sample_cnt 36FROM perf_sample 37WHERE callsite_id IS NOT NULL 38GROUP BY utid; 39 40CREATE PERFETTO TABLE _thread_available_info_summary AS 41WITH raw AS ( 42 SELECT 43 utid, 44 ss.max_running_dur, 45 ss.sum_running_dur, 46 ss.running_count, 47 ( 48 SELECT slice_count 49 FROM _thread_track_summary 50 WHERE utid = t.utid 51 ) AS slice_count, 52 ( 53 SELECT perf_sample_cnt 54 FROM _perf_sample_summary 55 WHERE utid = t.utid 56 ) AS perf_sample_count 57 FROM thread t 58 LEFT JOIN _sched_summary ss USING (utid) 59) 60SELECT 61 utid, 62 IFNULL(max_running_dur, 0) AS max_running_dur, 63 IFNULL(sum_running_dur, 0) AS sum_running_dur, 64 IFNULL(running_count, 0) AS running_count, 65 IFNULL(slice_count, 0) AS slice_count, 66 IFNULL(perf_sample_count, 0) AS perf_sample_count 67FROM raw r 68WHERE 69 NOT ( 70 r.max_running_dur IS NULL 71 AND r.sum_running_dur IS NULL 72 AND r.running_count IS NULL 73 AND r.slice_count IS NULL 74 AND r.perf_sample_count IS NULL 75 ) 76 OR utid IN (SELECT utid FROM cpu_profile_stack_sample) 77 OR utid IN (SELECT utid FROM thread_counter_track); 78