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 16-- TODO(altimin): `sched_humanly_readable_name` doesn't handle some corner 17-- cases which thread_state.ts handles (as complex strings manipulations in 18-- SQL are pretty painful), but they are pretty niche. 19 20-- Translates a single-letter scheduling state to a human-readable string. 21CREATE PERFETTO FUNCTION sched_state_to_human_readable_string( 22 -- An individual character string representing the scheduling state of the 23 -- kernel thread at the end of the slice. 24 short_name STRING 25) 26-- Humanly readable string representing the scheduling state of the kernel 27-- thread. The individual characters in the string mean the following: R 28-- (runnable), S (awaiting a wakeup), D (in an uninterruptible sleep), T 29-- (suspended), t (being traced), X (exiting), P (parked), W (waking), I 30-- (idle), N (not contributing to the load average), K (wakeable on fatal 31-- signals) and Z (zombie, awaiting cleanup). 32RETURNS STRING AS 33SELECT CASE $short_name 34WHEN 'Running' THEN 'Running' 35WHEN 'R' THEN 'Runnable' 36WHEN 'R+' THEN 'Runnable (Preempted)' 37WHEN 'S' THEN 'Sleeping' 38WHEN 'D' THEN 'Uninterruptible Sleep' 39WHEN 'T' THEN 'Stopped' 40WHEN 't' THEN 'Traced' 41WHEN 'X' THEN 'Exit (Dead)' 42WHEN 'Z' THEN 'Exit (Zombie)' 43WHEN 'x' THEN 'Task Dead' 44WHEN 'I' THEN 'Idle' 45WHEN 'K' THEN 'Wakekill' 46WHEN 'W' THEN 'Waking' 47WHEN 'P' THEN 'Parked' 48WHEN 'N' THEN 'No Load' 49-- ETW SPECIFIC STATES 50WHEN 'Stand By' THEN 'Stand By' 51WHEN 'Initialized' THEN 'Initialized' 52WHEN 'Waiting' THEN 'Waiting' 53WHEN 'Transition' THEN 'Transition' 54WHEN 'Deferred Ready' THEN 'Deferred Ready' 55ELSE $short_name 56END; 57 58-- Translates a single-letter scheduling state and IO wait information to 59-- a human-readable string. 60CREATE PERFETTO FUNCTION sched_state_io_to_human_readable_string( 61 -- An individual character string representing the scheduling state of the 62 -- kernel thread at the end of the slice. 63 sched_state STRING, 64 -- A (posssibly NULL) boolean indicating, if the device was in uninterruptible 65 -- sleep, if it was an IO sleep. 66 io_wait BOOL 67) 68-- A human readable string with information about the scheduling state and IO wait. 69RETURNS STRING AS 70SELECT printf( 71 '%s%s', 72 sched_state_to_human_readable_string($sched_state), 73 CASE $io_wait 74 WHEN 1 THEN ' (IO)' 75 WHEN 0 THEN ' (non-IO)' 76 ELSE '' 77 END 78); 79