1# Copyright (C) 2023 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Contains tables for relevant for sched.""" 15 16from python.generators.trace_processor_table.public import Column as C 17from python.generators.trace_processor_table.public import ColumnDoc 18from python.generators.trace_processor_table.public import ColumnFlag 19from python.generators.trace_processor_table.public import CppInt32 20from python.generators.trace_processor_table.public import CppInt64 21from python.generators.trace_processor_table.public import CppOptional 22from python.generators.trace_processor_table.public import CppSelfTableId 23from python.generators.trace_processor_table.public import CppString 24from python.generators.trace_processor_table.public import CppTableId 25from python.generators.trace_processor_table.public import CppUint32 26from python.generators.trace_processor_table.public import Table 27from python.generators.trace_processor_table.public import TableDoc 28from python.generators.trace_processor_table.public import WrappingSqlView 29 30from src.trace_processor.tables.metadata_tables import MACHINE_TABLE, CPU_TABLE 31 32SCHED_SLICE_TABLE = Table( 33 python_module=__file__, 34 class_name='SchedSliceTable', 35 sql_name='__intrinsic_sched_slice', 36 columns=[ 37 C('ts', CppInt64(), flags=ColumnFlag.SORTED), 38 C('dur', CppInt64()), 39 C('utid', CppUint32()), 40 C('end_state', CppString()), 41 C('priority', CppInt32()), 42 C('ucpu', CppTableId(CPU_TABLE)), 43 ], 44 tabledoc=TableDoc( 45 doc=''' 46 This table holds slices with kernel thread scheduling information. 47 These slices are collected when the Linux "ftrace" data source is 48 used with the "sched/switch" and "sched/wakeup*" events enabled. 49 50 The rows in this table will always have a matching row in the 51 |thread_state| table with |thread_state.state| = 'Running' 52 ''', 53 group='Events', 54 columns={ 55 'ts': 56 '''The timestamp at the start of the slice (in nanoseconds).''', 57 'dur': 58 '''The duration of the slice (in nanoseconds).''', 59 'utid': 60 '''The thread's unique id in the trace.''', 61 'end_state': 62 ''' 63 A string representing the scheduling state of the kernel 64 thread at the end of the slice. The individual characters in 65 the string mean the following: R (runnable), S (awaiting a 66 wakeup), D (in an uninterruptible sleep), T (suspended), 67 t (being traced), X (exiting), P (parked), W (waking), 68 I (idle), N (not contributing to the load average), 69 K (wakeable on fatal signals) and Z (zombie, awaiting 70 cleanup). 71 ''', 72 'priority': 73 '''The kernel priority that the thread ran at.''', 74 'ucpu': 75 ''' 76 The unique CPU identifier that the slice executed on. 77 ''', 78 })) 79 80SPURIOUS_SCHED_WAKEUP_TABLE = Table( 81 python_module=__file__, 82 class_name='SpuriousSchedWakeupTable', 83 sql_name='spurious_sched_wakeup', 84 columns=[ 85 C('ts', CppInt64(), flags=ColumnFlag.SORTED), 86 C('thread_state_id', CppInt64()), 87 C('irq_context', CppOptional(CppUint32())), 88 C('utid', CppUint32()), 89 C('waker_utid', CppUint32()) 90 ], 91 tabledoc=TableDoc( 92 doc=''' 93 This table contains the scheduling wakeups that occurred while a 94 thread was not blocked, i.e. running or runnable. Such wakeups are not 95 tracked in the |thread_state_table|. 96 ''', 97 group='Events', 98 columns={ 99 'ts': 100 'The timestamp at the start of the slice (in nanoseconds).', 101 'thread_state_id': 102 ''' 103 The id of the row in the thread_state table that this row is 104 associated with. 105 ''', 106 'irq_context': 107 ''' 108 Whether the wakeup was from interrupt context or process 109 context. 110 ''', 111 'utid': 112 '''The thread's unique id in the trace..''', 113 'waker_utid': 114 ''' 115 The unique thread id of the thread which caused a wakeup of 116 this thread. 117 ''', 118 })) 119 120THREAD_STATE_TABLE = Table( 121 python_module=__file__, 122 class_name='ThreadStateTable', 123 sql_name='__intrinsic_thread_state', 124 columns=[ 125 C('ts', CppInt64(), flags=ColumnFlag.SORTED), 126 C('dur', CppInt64()), 127 C('utid', CppUint32()), 128 C('state', CppString()), 129 C('io_wait', CppOptional(CppUint32())), 130 C('blocked_function', CppOptional(CppString())), 131 C('waker_utid', CppOptional(CppUint32())), 132 C('waker_id', CppOptional(CppSelfTableId())), 133 C('irq_context', CppOptional(CppUint32())), 134 C('ucpu', CppOptional(CppTableId(CPU_TABLE))), 135 ], 136 tabledoc=TableDoc( 137 doc=''' 138 This table contains the scheduling state of every thread on the 139 system during the trace. 140 141 The rows in this table which have |state| = 'Running', will have a 142 corresponding row in the |sched_slice| table. 143 ''', 144 group='Events', 145 columns={ 146 'ts': 147 'The timestamp at the start of the slice (in nanoseconds).', 148 'dur': 149 'The duration of the slice (in nanoseconds).', 150 'utid': 151 '''The thread's unique id in the trace.''', 152 'state': 153 ''' 154 The scheduling state of the thread. Can be "Running" or any 155 of the states described in |sched_slice.end_state|. 156 ''', 157 'io_wait': 158 'Indicates whether this thread was blocked on IO.', 159 'blocked_function': 160 'The function in the kernel this thread was blocked on.', 161 'waker_utid': 162 ''' 163 The unique thread id of the thread which caused a wakeup of 164 this thread. 165 ''', 166 'waker_id': 167 ''' 168 The unique thread state id which caused a wakeup of this 169 thread. 170 ''', 171 'irq_context': 172 ''' 173 Whether the wakeup was from interrupt context or process 174 context. 175 ''', 176 'ucpu': 177 ''' 178 The unique CPU identifier that the thread executed on. 179 ''', 180 })) 181 182# Keep this list sorted. 183ALL_TABLES = [ 184 SCHED_SLICE_TABLE, 185 SPURIOUS_SCHED_WAKEUP_TABLE, 186 THREAD_STATE_TABLE, 187] 188