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 slices.""" 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.track_tables import TRACK_TABLE 31 32SLICE_TABLE = Table( 33 python_module=__file__, 34 class_name='SliceTable', 35 sql_name='internal_slice', 36 columns=[ 37 C('ts', CppInt64(), flags=ColumnFlag.SORTED), 38 C('dur', CppInt64()), 39 C('track_id', CppTableId(TRACK_TABLE)), 40 C('category', CppOptional(CppString())), 41 C('name', CppOptional(CppString())), 42 C('depth', CppUint32()), 43 C('stack_id', CppInt64()), 44 C('parent_stack_id', CppInt64()), 45 C('parent_id', CppOptional(CppSelfTableId())), 46 C('arg_set_id', CppUint32()), 47 C('thread_ts', CppOptional(CppInt64())), 48 C('thread_dur', CppOptional(CppInt64())), 49 C('thread_instruction_count', CppOptional(CppInt64())), 50 C('thread_instruction_delta', CppOptional(CppInt64())), 51 ], 52 wrapping_sql_view=WrappingSqlView('slice'), 53 tabledoc=TableDoc( 54 doc=''' 55 Contains slices from userspace which explains what threads were doing 56 during the trace. 57 ''', 58 group='Events', 59 columns={ 60 'ts': 61 'The timestamp at the start of the slice (in nanoseconds).', 62 'dur': 63 'The duration of the slice (in nanoseconds).', 64 'track_id': 65 'The id of the track this slice is located on.', 66 'category': 67 ''' 68 The "category" of the slice. If this slice originated with 69 track_event, this column contains the category emitted. 70 Otherwise, it is likely to be null (with limited exceptions). 71 ''', 72 'name': 73 ''' 74 The name of the slice. The name describes what was happening 75 during the slice. 76 ''', 77 'depth': 78 'The depth of the slice in the current stack of slices.', 79 'stack_id': 80 ''' 81 A unique identifier obtained from the names of all slices 82 in this stack. This is rarely useful and kept around only 83 for legacy reasons. 84 ''', 85 'parent_stack_id': 86 'The stack_id for the parent of this slice. Rarely useful.', 87 'parent_id': 88 ''' 89 The id of the parent (i.e. immediate ancestor) slice for this 90 slice 91 ''', 92 'arg_set_id': 93 ColumnDoc( 94 'The id of the argument set associated with this slice', 95 joinable='args.arg_set_id'), 96 'thread_ts': 97 ''' 98 The thread timestamp at the start of the slice. This column 99 will only be populated if thread timestamp collection is 100 enabled with track_event. 101 ''', 102 'thread_dur': 103 '''' 104 The thread time used by this slice. This column will only be 105 populated if thread timestamp collection is enabled with 106 track_event. 107 ''', 108 'thread_instruction_count': 109 ''' 110 The value of the CPU instruction counter at the start of the 111 slice. This column will only be populated if thread 112 instruction collection is enabled with track_event. 113 ''', 114 'thread_instruction_delta': 115 ''' 116 The change in value of the CPU instruction counter between the 117 start and end of the slice. This column will only be 118 populated if thread instruction collection is enabled with 119 track_event. 120 ''', 121 })) 122 123SCHED_SLICE_TABLE = Table( 124 python_module=__file__, 125 class_name='SchedSliceTable', 126 sql_name='sched_slice', 127 columns=[ 128 C('ts', CppInt64(), flags=ColumnFlag.SORTED), 129 C('dur', CppInt64()), 130 C('cpu', CppUint32()), 131 C('utid', CppUint32()), 132 C('end_state', CppString()), 133 C('priority', CppInt32()), 134 ], 135 tabledoc=TableDoc( 136 doc=''' 137 This table holds slices with kernel thread scheduling information. 138 These slices are collected when the Linux "ftrace" data source is 139 used with the "sched/switch" and "sched/wakeup*" events enabled. 140 ''', 141 group='Events', 142 columns={ 143 'ts': 144 '''The timestamp at the start of the slice (in nanoseconds).''', 145 'dur': 146 '''The duration of the slice (in nanoseconds).''', 147 'utid': 148 '''The thread's unique id in the trace..''', 149 'cpu': 150 '''The CPU that the slice executed on.''', 151 'end_state': 152 ''' 153 A string representing the scheduling state of the kernel 154 thread at the end of the slice. The individual characters in 155 the string mean the following: R (runnable), S (awaiting a 156 wakeup), D (in an uninterruptible sleep), T (suspended), 157 t (being traced), X (exiting), P (parked), W (waking), 158 I (idle), N (not contributing to the load average), 159 K (wakeable on fatal signals) and Z (zombie, awaiting 160 cleanup). 161 ''', 162 'priority': 163 '''The kernel priority that the thread ran at.''' 164 })) 165 166THREAD_STATE_TABLE = Table( 167 python_module=__file__, 168 class_name='ThreadStateTable', 169 sql_name='thread_state', 170 columns=[ 171 C('ts', CppInt64()), 172 C('dur', CppInt64()), 173 C('cpu', CppOptional(CppUint32())), 174 C('utid', CppUint32()), 175 C('state', CppString()), 176 C('io_wait', CppOptional(CppUint32())), 177 C('blocked_function', CppOptional(CppString())), 178 C('waker_utid', CppOptional(CppUint32())), 179 ], 180 tabledoc=TableDoc( 181 doc=''' 182 This table contains the scheduling state of every thread on the 183 system during the trace. It is a subset of the |sched_slice| (sched) 184 table which only contains the times where threads were actually 185 scheduled. 186 ''', 187 group='Events', 188 columns={ 189 'ts': 190 'The timestamp at the start of the slice (in nanoseconds).', 191 'dur': 192 'The duration of the slice (in nanoseconds).', 193 'cpu': 194 '''The CPU that the slice executed on.''', 195 'utid': 196 '''The thread's unique id in the trace..''', 197 'state': 198 ''' 199 The scheduling state of the thread. Can be "Running" or any 200 of the states described in |sched_slice.end_state|. 201 ''', 202 'io_wait': 203 'Indicates whether this thread was blocked on IO.', 204 'blocked_function': 205 'The function in the kernel this thread was blocked on.', 206 'waker_utid': 207 ''' 208 The unique thread id of the thread which caused a wakeup of 209 this thread. 210 ''' 211 })) 212 213GPU_SLICE_TABLE = Table( 214 python_module=__file__, 215 class_name='GpuSliceTable', 216 sql_name='gpu_slice', 217 columns=[ 218 C('context_id', CppOptional(CppInt64())), 219 C('render_target', CppOptional(CppInt64())), 220 C('render_target_name', CppString()), 221 C('render_pass', CppOptional(CppInt64())), 222 C('render_pass_name', CppString()), 223 C('command_buffer', CppOptional(CppInt64())), 224 C('command_buffer_name', CppString()), 225 C('frame_id', CppOptional(CppUint32())), 226 C('submission_id', CppOptional(CppUint32())), 227 C('hw_queue_id', CppOptional(CppInt64())), 228 C('render_subpasses', CppString()), 229 ], 230 parent=SLICE_TABLE, 231 tabledoc=TableDoc( 232 doc='''''', 233 group='Events', 234 columns={ 235 'context_id': '''''', 236 'render_target': '''''', 237 'render_target_name': '''''', 238 'render_pass': '''''', 239 'render_pass_name': '''''', 240 'command_buffer': '''''', 241 'command_buffer_name': '''''', 242 'frame_id': '''''', 243 'submission_id': '''''', 244 'hw_queue_id': '''''', 245 'render_subpasses': '''''' 246 })) 247 248GRAPHICS_FRAME_SLICE_TABLE = Table( 249 python_module=__file__, 250 class_name='GraphicsFrameSliceTable', 251 sql_name='frame_slice', 252 columns=[ 253 C('frame_number', CppUint32()), 254 C('layer_name', CppString()), 255 C('queue_to_acquire_time', CppInt64()), 256 C('acquire_to_latch_time', CppInt64()), 257 C('latch_to_present_time', CppInt64()), 258 ], 259 parent=SLICE_TABLE, 260 tabledoc=TableDoc( 261 doc='''''', 262 group='Events', 263 columns={ 264 'frame_number': '''''', 265 'layer_name': '''''', 266 'queue_to_acquire_time': '''''', 267 'acquire_to_latch_time': '''''', 268 'latch_to_present_time': '''''' 269 })) 270 271EXPECTED_FRAME_TIMELINE_SLICE_TABLE = Table( 272 python_module=__file__, 273 class_name='ExpectedFrameTimelineSliceTable', 274 sql_name='expected_frame_timeline_slice', 275 columns=[ 276 C('display_frame_token', CppInt64()), 277 C('surface_frame_token', CppInt64()), 278 C('upid', CppUint32()), 279 C('layer_name', CppString()), 280 ], 281 parent=SLICE_TABLE, 282 tabledoc=TableDoc( 283 doc='''''', 284 group='Events', 285 columns={ 286 'display_frame_token': '''''', 287 'surface_frame_token': '''''', 288 'upid': '''''', 289 'layer_name': '''''' 290 })) 291 292ACTUAL_FRAME_TIMELINE_SLICE_TABLE = Table( 293 python_module=__file__, 294 class_name='ActualFrameTimelineSliceTable', 295 sql_name='actual_frame_timeline_slice', 296 columns=[ 297 C('display_frame_token', CppInt64()), 298 C('surface_frame_token', CppInt64()), 299 C('upid', CppUint32()), 300 C('layer_name', CppString()), 301 C('present_type', CppString()), 302 C('on_time_finish', CppInt32()), 303 C('gpu_composition', CppInt32()), 304 C('jank_type', CppString()), 305 C('prediction_type', CppString()), 306 C('jank_tag', CppString()), 307 ], 308 parent=SLICE_TABLE, 309 tabledoc=TableDoc( 310 doc='''''', 311 group='Events', 312 columns={ 313 'display_frame_token': '''''', 314 'surface_frame_token': '''''', 315 'upid': '''''', 316 'layer_name': '''''', 317 'present_type': '''''', 318 'on_time_finish': '''''', 319 'gpu_composition': '''''', 320 'jank_type': '''''', 321 'prediction_type': '''''', 322 'jank_tag': '''''' 323 })) 324 325EXPERIMENTAL_FLAT_SLICE_TABLE = Table( 326 python_module=__file__, 327 class_name='ExperimentalFlatSliceTable', 328 sql_name='experimental_flat_slice', 329 columns=[ 330 C('ts', CppInt64()), 331 C('dur', CppInt64()), 332 C('track_id', CppTableId(TRACK_TABLE)), 333 C('category', CppOptional(CppString())), 334 C('name', CppOptional(CppString())), 335 C('arg_set_id', CppUint32()), 336 C('source_id', CppOptional(CppTableId(SLICE_TABLE))), 337 C('start_bound', CppInt64(), flags=ColumnFlag.HIDDEN), 338 C('end_bound', CppInt64(), flags=ColumnFlag.HIDDEN), 339 ], 340 tabledoc=TableDoc( 341 doc=''' 342 An experimental table which "flattens" stacks of slices to contain 343 only the "deepest" slice at any point in time on each track. 344 ''', 345 group='Misc', 346 columns={ 347 'ts': 348 '''The timestamp at the start of the slice (in nanoseconds).''', 349 'dur': 350 '''The duration of the slice (in nanoseconds).''', 351 'track_id': 352 'The id of the track this slice is located on.', 353 'category': 354 ''' 355 The "category" of the slice. If this slice originated with 356 track_event, this column contains the category emitted. 357 Otherwise, it is likely to be null (with limited exceptions). 358 ''', 359 'name': 360 ''' 361 The name of the slice. The name describes what was happening 362 during the slice. 363 ''', 364 'arg_set_id': 365 ColumnDoc( 366 'The id of the argument set associated with this slice', 367 joinable='args.arg_set_id'), 368 'source_id': 369 'The id of the slice which this row originated from.', 370 })) 371 372# Keep this list sorted. 373ALL_TABLES = [ 374 ACTUAL_FRAME_TIMELINE_SLICE_TABLE, 375 EXPECTED_FRAME_TIMELINE_SLICE_TABLE, 376 EXPERIMENTAL_FLAT_SLICE_TABLE, 377 GPU_SLICE_TABLE, 378 GRAPHICS_FRAME_SLICE_TABLE, 379 SCHED_SLICE_TABLE, 380 SLICE_TABLE, 381 THREAD_STATE_TABLE, 382] 383