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='__intrinsic_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 123GPU_SLICE_TABLE = Table( 124 python_module=__file__, 125 class_name='GpuSliceTable', 126 sql_name='gpu_slice', 127 columns=[ 128 C('context_id', CppOptional(CppInt64())), 129 C('render_target', CppOptional(CppInt64())), 130 C('render_target_name', CppString()), 131 C('render_pass', CppOptional(CppInt64())), 132 C('render_pass_name', CppString()), 133 C('command_buffer', CppOptional(CppInt64())), 134 C('command_buffer_name', CppString()), 135 C('frame_id', CppOptional(CppUint32())), 136 C('submission_id', CppOptional(CppUint32())), 137 C('hw_queue_id', CppOptional(CppInt64())), 138 C('upid', CppOptional(CppUint32())), 139 C('render_subpasses', CppString()), 140 ], 141 parent=SLICE_TABLE, 142 tabledoc=TableDoc( 143 doc='''''', 144 group='Slice', 145 columns={ 146 'context_id': 147 '''''', 148 'render_target': 149 '''''', 150 'render_target_name': 151 '''''', 152 'render_pass': 153 '''''', 154 'render_pass_name': 155 '''''', 156 'command_buffer': 157 '''''', 158 'command_buffer_name': 159 '''''', 160 'frame_id': 161 '''''', 162 'submission_id': 163 '''''', 164 'hw_queue_id': 165 '''''', 166 'upid': 167 ''' 168 Unique process id of the app that generates this gpu render 169 stage event. 170 ''', 171 'render_subpasses': 172 '''''' 173 })) 174 175GRAPHICS_FRAME_SLICE_TABLE = Table( 176 python_module=__file__, 177 class_name='GraphicsFrameSliceTable', 178 sql_name='frame_slice', 179 columns=[ 180 C('frame_number', CppUint32()), 181 C('layer_name', CppString()), 182 C('queue_to_acquire_time', CppInt64()), 183 C('acquire_to_latch_time', CppInt64()), 184 C('latch_to_present_time', CppInt64()), 185 ], 186 parent=SLICE_TABLE, 187 tabledoc=TableDoc( 188 doc='''''', 189 group='Slice', 190 columns={ 191 'frame_number': '''''', 192 'layer_name': '''''', 193 'queue_to_acquire_time': '''''', 194 'acquire_to_latch_time': '''''', 195 'latch_to_present_time': '''''' 196 })) 197 198EXPECTED_FRAME_TIMELINE_SLICE_TABLE = Table( 199 python_module=__file__, 200 class_name='ExpectedFrameTimelineSliceTable', 201 sql_name='expected_frame_timeline_slice', 202 columns=[ 203 C('display_frame_token', CppInt64()), 204 C('surface_frame_token', CppInt64()), 205 C('upid', CppUint32()), 206 C('layer_name', CppString()), 207 ], 208 parent=SLICE_TABLE, 209 tabledoc=TableDoc( 210 doc=''' 211 This table contains information on the expected timeline of either 212 a display frame or a surface frame. 213 ''', 214 group='Slice', 215 columns={ 216 'display_frame_token': 217 'Display frame token (vsync id).', 218 'surface_frame_token': 219 ''' 220 Surface frame token (vsync id), null if this is a display frame. 221 ''', 222 'upid': 223 ''' 224 Unique process id of the app that generates the surface frame. 225 ''', 226 'layer_name': 227 'Layer name if this is a surface frame.', 228 })) 229 230ACTUAL_FRAME_TIMELINE_SLICE_TABLE = Table( 231 python_module=__file__, 232 class_name='ActualFrameTimelineSliceTable', 233 sql_name='actual_frame_timeline_slice', 234 columns=[ 235 C('display_frame_token', CppInt64()), 236 C('surface_frame_token', CppInt64()), 237 C('upid', CppUint32()), 238 C('layer_name', CppString()), 239 C('present_type', CppString()), 240 C('on_time_finish', CppInt32()), 241 C('gpu_composition', CppInt32()), 242 C('jank_type', CppString()), 243 C('jank_severity_type', CppString()), 244 C('prediction_type', CppString()), 245 C('jank_tag', CppString()), 246 ], 247 parent=SLICE_TABLE, 248 tabledoc=TableDoc( 249 doc=''' 250 This table contains information on the actual timeline and additional 251 analysis related to the performance of either a display frame or a 252 surface frame. 253 ''', 254 group='Slice', 255 columns={ 256 'display_frame_token': 257 'Display frame token (vsync id).', 258 'surface_frame_token': 259 ''' 260 Surface frame token (vsync id), null if this is a display frame. 261 ''', 262 'upid': 263 ''' 264 Unique process id of the app that generates the surface frame. 265 ''', 266 'layer_name': 267 'Layer name if this is a surface frame.', 268 'present_type': 269 'Frame\'s present type (eg. on time / early / late).', 270 'on_time_finish': 271 'Whether the frame finishes on time.', 272 'gpu_composition': 273 'Whether the frame used gpu composition.', 274 'jank_type': 275 ''' 276 Specify the jank types for this frame if there's jank, or 277 none if no jank occurred. 278 ''', 279 'jank_severity_type': 280 'Severity of the jank: none if no jank.', 281 'prediction_type': 282 'Frame\'s prediction type (eg. valid / expired).', 283 'jank_tag': 284 'Jank tag based on jank type, used for slice visualization.' 285 })) 286 287EXPERIMENTAL_FLAT_SLICE_TABLE = Table( 288 python_module=__file__, 289 class_name='ExperimentalFlatSliceTable', 290 sql_name='experimental_flat_slice', 291 columns=[ 292 C('ts', CppInt64()), 293 C('dur', CppInt64()), 294 C('track_id', CppTableId(TRACK_TABLE)), 295 C('category', CppOptional(CppString())), 296 C('name', CppOptional(CppString())), 297 C('arg_set_id', CppUint32()), 298 C('source_id', CppOptional(CppTableId(SLICE_TABLE))), 299 C('start_bound', CppInt64(), flags=ColumnFlag.HIDDEN), 300 C('end_bound', CppInt64(), flags=ColumnFlag.HIDDEN), 301 ], 302 tabledoc=TableDoc( 303 doc=''' 304 An experimental table which "flattens" stacks of slices to contain 305 only the "deepest" slice at any point in time on each track. 306 ''', 307 group='Slice', 308 columns={ 309 'ts': 310 '''The timestamp at the start of the slice (in nanoseconds).''', 311 'dur': 312 '''The duration of the slice (in nanoseconds).''', 313 'track_id': 314 'The id of the track this slice is located on.', 315 'category': 316 ''' 317 The "category" of the slice. If this slice originated with 318 track_event, this column contains the category emitted. 319 Otherwise, it is likely to be null (with limited exceptions). 320 ''', 321 'name': 322 ''' 323 The name of the slice. The name describes what was happening 324 during the slice. 325 ''', 326 'arg_set_id': 327 ColumnDoc( 328 'The id of the argument set associated with this slice.', 329 joinable='args.arg_set_id'), 330 'source_id': 331 'The id of the slice which this row originated from.', 332 })) 333 334ANDROID_NETWORK_PACKETS_TABLE = Table( 335 python_module=__file__, 336 class_name='AndroidNetworkPacketsTable', 337 sql_name='__intrinsic_android_network_packets', 338 columns=[ 339 C('iface', CppString()), 340 C('direction', CppString()), 341 C('packet_transport', CppString()), 342 C('packet_length', CppInt64()), 343 C('packet_count', CppInt64()), 344 C('socket_tag', CppUint32()), 345 C('socket_tag_str', CppString()), 346 C('socket_uid', CppUint32()), 347 C('local_port', CppOptional(CppUint32())), 348 C('remote_port', CppOptional(CppUint32())), 349 C('packet_icmp_type', CppOptional(CppUint32())), 350 C('packet_icmp_code', CppOptional(CppUint32())), 351 C('packet_tcp_flags', CppOptional(CppUint32())), 352 C('packet_tcp_flags_str', CppOptional(CppString())), 353 ], 354 parent=SLICE_TABLE, 355 wrapping_sql_view=WrappingSqlView('android_network_packets'), 356 tabledoc=TableDoc( 357 doc=""" 358 This table contains details on Android Network activity. 359 """, 360 group='Slice', 361 columns={ 362 'iface': 363 'The name of the network interface used', 364 'direction': 365 'The direction of traffic (Received or Transmitted)', 366 'packet_transport': 367 'The transport protocol of packets in this event', 368 'packet_length': 369 'The length (in bytes) of packets in this event', 370 'packet_count': 371 'The number of packets contained in this event', 372 'socket_tag': 373 'The Android network tag of the socket', 374 'socket_tag_str': 375 'The socket tag formatted as a hex string', 376 'socket_uid': 377 'The Linux user id of the socket', 378 'local_port': 379 'The local udp/tcp port', 380 'remote_port': 381 'The remote udp/tcp port', 382 'packet_icmp_type': 383 'The 1-byte ICMP type identifier', 384 'packet_icmp_code': 385 'The 1-byte ICMP code identifier', 386 'packet_tcp_flags': 387 'The TCP flags as an integer bitmask (FIN=0x1, SYN=0x2, etc)', 388 'packet_tcp_flags_str': 389 ''' 390 The TCP flags formatted as a string bitmask (e.g. "f...a..." for 391 FIN & ACK) 392 ''', 393 }, 394 ), 395) 396 397# Keep this list sorted. 398ALL_TABLES = [ 399 ACTUAL_FRAME_TIMELINE_SLICE_TABLE, 400 ANDROID_NETWORK_PACKETS_TABLE, 401 EXPECTED_FRAME_TIMELINE_SLICE_TABLE, 402 EXPERIMENTAL_FLAT_SLICE_TABLE, 403 GPU_SLICE_TABLE, 404 GRAPHICS_FRAME_SLICE_TABLE, 405 SLICE_TABLE, 406] 407