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 intervals.intersect; 17 18INCLUDE PERFETTO MODULE linux.cpu.utilization.slice; 19 20-- Time each thread slice spent running on CPU. 21-- Requires scheduling data to be available in the trace. 22CREATE PERFETTO TABLE thread_slice_cpu_time ( 23 -- Slice. 24 id JOINID(slice.id), 25 -- Name of the slice. 26 name STRING, 27 -- Id of the thread the slice is running on. 28 utid JOINID(thread.id), 29 -- Name of the thread. 30 thread_name STRING, 31 -- Id of the process the slice is running on. 32 upid JOINID(process.id), 33 -- Name of the process. 34 process_name STRING, 35 -- Duration of the time the slice was running. 36 cpu_time LONG 37) AS 38SELECT 39 id_0 AS id, 40 name, 41 ts.utid, 42 thread_name, 43 upid, 44 process_name, 45 sum(ii.dur) AS cpu_time 46FROM _interval_intersect!(( 47 (SELECT * FROM thread_slice WHERE utid > 0 AND dur > 0), 48 (SELECT * FROM sched WHERE dur > 0) 49 ), (utid)) AS ii 50JOIN thread_slice AS ts 51 ON ts.id = ii.id_0 52GROUP BY 53 id 54ORDER BY 55 id; 56 57-- CPU cycles per each slice. 58CREATE PERFETTO VIEW thread_slice_cpu_cycles ( 59 -- Id of a slice. 60 id JOINID(slice.id), 61 -- Name of the slice. 62 name STRING, 63 -- Id of the thread the slice is running on. 64 utid JOINID(thread.id), 65 -- Name of the thread. 66 thread_name STRING, 67 -- Id of the process the slice is running on. 68 upid JOINID(process.id), 69 -- Name of the process. 70 process_name STRING, 71 -- Sum of CPU millicycles. Null if frequency couldn't be fetched for any 72 -- period during the runtime of the slice. 73 millicycles LONG, 74 -- Sum of CPU megacycles. Null if frequency couldn't be fetched for any 75 -- period during the runtime of the slice. 76 megacycles LONG 77) AS 78SELECT 79 id, 80 name, 81 utid, 82 thread_name, 83 upid, 84 process_name, 85 millicycles, 86 megacycles 87FROM cpu_cycles_per_thread_slice; 88