• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
34  CASE $short_name
35    WHEN 'Running'
36    THEN 'Running'
37    WHEN 'R'
38    THEN 'Runnable'
39    WHEN 'R+'
40    THEN 'Runnable (Preempted)'
41    WHEN 'S'
42    THEN 'Sleeping'
43    WHEN 'D'
44    THEN 'Uninterruptible Sleep'
45    WHEN 'T'
46    THEN 'Stopped'
47    WHEN 't'
48    THEN 'Traced'
49    WHEN 'X'
50    THEN 'Exit (Dead)'
51    WHEN 'Z'
52    THEN 'Exit (Zombie)'
53    WHEN 'x'
54    THEN 'Task Dead'
55    WHEN 'I'
56    THEN 'Idle'
57    WHEN 'K'
58    THEN 'Wakekill'
59    WHEN 'W'
60    THEN 'Waking'
61    WHEN 'P'
62    THEN 'Parked'
63    WHEN 'N'
64    THEN 'No Load'
65    -- ETW SPECIFIC STATES
66    WHEN 'Stand By'
67    THEN 'Stand By'
68    WHEN 'Initialized'
69    THEN 'Initialized'
70    WHEN 'Waiting'
71    THEN 'Waiting'
72    WHEN 'Transition'
73    THEN 'Transition'
74    WHEN 'Deferred Ready'
75    THEN 'Deferred Ready'
76    ELSE $short_name
77  END;
78
79-- Translates a single-letter scheduling state and IO wait information to
80-- a human-readable string.
81CREATE PERFETTO FUNCTION sched_state_io_to_human_readable_string(
82    -- An individual character string representing the scheduling state of the
83    -- kernel thread at the end of the slice.
84    sched_state STRING,
85    -- A (posssibly NULL) boolean indicating, if the device was in uninterruptible
86    -- sleep, if it was an IO sleep.
87    io_wait BOOL
88)
89-- A human readable string with information about the scheduling state and IO wait.
90RETURNS STRING AS
91SELECT
92  printf(
93    '%s%s',
94    sched_state_to_human_readable_string($sched_state),
95    CASE $io_wait WHEN 1 THEN ' (IO)' WHEN 0 THEN ' (non-IO)' ELSE '' END
96  );
97