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 16INCLUDE PERFETTO MODULE deprecated.v42.common.timestamps; 17INCLUDE PERFETTO MODULE sched.time_in_state; 18INCLUDE PERFETTO MODULE sched.states; 19INCLUDE PERFETTO MODULE cpu.size; 20 21CREATE PERFETTO FUNCTION _translate_thread_state_name(name STRING) 22RETURNS STRING AS 23SELECT sched_state_to_human_readable_string($name); 24 25 26-- Returns a human-readable name for a thread state. 27CREATE PERFETTO FUNCTION human_readable_thread_state_name( 28 -- Thread state id. 29 id INT) 30-- Human-readable name for the thread state. 31RETURNS STRING AS 32SELECT sched_state_io_to_human_readable_string(state, io_wait) 33FROM thread_state 34WHERE id = $id; 35 36-- Returns an aggregation of thread states (by state and cpu) for a given 37-- interval of time for a given thread. 38CREATE PERFETTO FUNCTION thread_state_summary_for_interval( 39 -- The start of the interval. 40 ts INT, 41 -- The duration of the interval. 42 dur INT, 43 -- The utid of the thread. 44 utid INT) 45RETURNS TABLE( 46 -- Human-readable thread state name. 47 state STRING, 48 -- Raw thread state name, alias of `thread_state.state`. 49 raw_state STRING, 50 -- The type of CPU if available (e.g. "big" / "mid" / "little"). 51 cpu_type STRING, 52 -- The CPU index. 53 cpu INT, 54 -- The name of the kernel function execution is blocked in. 55 blocked_function STRING, 56 -- The total duration. 57 dur INT 58) AS 59SELECT 60 sched_state_io_to_human_readable_string(state, io_wait) as state, 61 state AS raw_state, 62 cpu_guess_core_type(cpu) as cpu_type, 63 cpu, 64 blocked_function, 65 dur 66FROM sched_time_in_state_and_cpu_for_thread_in_interval($ts, $dur, $utid);