xref: /aosp_15_r20/external/perfetto/src/trace_processor/tables/sched_tables.py (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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    wrapping_sql_view=WrappingSqlView('sched'),
45    tabledoc=TableDoc(
46        doc='''
47          This table holds slices with kernel thread scheduling information.
48          These slices are collected when the Linux "ftrace" data source is
49          used with the "sched/switch" and "sched/wakeup*" events enabled.
50
51          The rows in this table will always have a matching row in the
52          |thread_state| table with |thread_state.state| = 'Running'
53        ''',
54        group='Events',
55        columns={
56            'ts':
57                '''The timestamp at the start of the slice (in nanoseconds).''',
58            'dur':
59                '''The duration of the slice (in nanoseconds).''',
60            'utid':
61                '''The thread's unique id in the trace.''',
62            'end_state':
63                '''
64                  A string representing the scheduling state of the kernel
65                  thread at the end of the slice.  The individual characters in
66                  the string mean the following: R (runnable), S (awaiting a
67                  wakeup), D (in an uninterruptible sleep), T (suspended),
68                  t (being traced), X (exiting), P (parked), W (waking),
69                  I (idle), N (not contributing to the load average),
70                  K (wakeable on fatal signals) and Z (zombie, awaiting
71                  cleanup).
72                ''',
73            'priority':
74                '''The kernel priority that the thread ran at.''',
75            'ucpu':
76                '''
77                  The unique CPU identifier that the slice executed on.
78                ''',
79        }))
80
81SPURIOUS_SCHED_WAKEUP_TABLE = Table(
82    python_module=__file__,
83    class_name='SpuriousSchedWakeupTable',
84    sql_name='spurious_sched_wakeup',
85    columns=[
86        C('ts', CppInt64(), flags=ColumnFlag.SORTED),
87        C('thread_state_id', CppInt64()),
88        C('irq_context', CppOptional(CppUint32())),
89        C('utid', CppUint32()),
90        C('waker_utid', CppUint32())
91    ],
92    tabledoc=TableDoc(
93        doc='''
94          This table contains the scheduling wakeups that occurred while a
95          thread was not blocked, i.e. running or runnable. Such wakeups are not
96          tracked in the |thread_state_table|.
97        ''',
98        group='Events',
99        columns={
100            'ts':
101                'The timestamp at the start of the slice (in nanoseconds).',
102            'thread_state_id':
103                '''
104                  The id of the row in the thread_state table that this row is
105                  associated with.
106                ''',
107            'irq_context':
108                '''
109                  Whether the wakeup was from interrupt context or process
110                  context.
111                ''',
112            'utid':
113                '''The thread's unique id in the trace..''',
114            'waker_utid':
115                '''
116                  The unique thread id of the thread which caused a wakeup of
117                  this thread.
118                ''',
119        }))
120
121THREAD_STATE_TABLE = Table(
122    python_module=__file__,
123    class_name='ThreadStateTable',
124    sql_name='__intrinsic_thread_state',
125    columns=[
126        C('ts', CppInt64(), flags=ColumnFlag.SORTED),
127        C('dur', CppInt64()),
128        C('utid', CppUint32()),
129        C('state', CppString()),
130        C('io_wait', CppOptional(CppUint32())),
131        C('blocked_function', CppOptional(CppString())),
132        C('waker_utid', CppOptional(CppUint32())),
133        C('waker_id', CppOptional(CppSelfTableId())),
134        C('irq_context', CppOptional(CppUint32())),
135        C('ucpu', CppOptional(CppTableId(CPU_TABLE))),
136    ],
137    wrapping_sql_view=WrappingSqlView('thread_state'),
138    tabledoc=TableDoc(
139        doc='''
140          This table contains the scheduling state of every thread on the
141          system during the trace.
142
143          The rows in this table which have |state| = 'Running', will have a
144          corresponding row in the |sched_slice| table.
145        ''',
146        group='Events',
147        columns={
148            'ts':
149                'The timestamp at the start of the slice (in nanoseconds).',
150            'dur':
151                'The duration of the slice (in nanoseconds).',
152            'utid':
153                '''The thread's unique id in the trace.''',
154            'state':
155                '''
156                  The scheduling state of the thread. Can be "Running" or any
157                  of the states described in |sched_slice.end_state|.
158                ''',
159            'io_wait':
160                'Indicates whether this thread was blocked on IO.',
161            'blocked_function':
162                'The function in the kernel this thread was blocked on.',
163            'waker_utid':
164                '''
165                  The unique thread id of the thread which caused a wakeup of
166                  this thread.
167                ''',
168            'waker_id':
169                '''
170                  The unique thread state id which caused a wakeup of this
171                  thread.
172                ''',
173            'irq_context':
174                '''
175                  Whether the wakeup was from interrupt context or process
176                  context.
177                ''',
178            'ucpu':
179                '''
180                  The unique CPU identifier that the thread executed on.
181                ''',
182        }))
183
184# Keep this list sorted.
185ALL_TABLES = [
186    SCHED_SLICE_TABLE,
187    SPURIOUS_SCHED_WAKEUP_TABLE,
188    THREAD_STATE_TABLE,
189]
190