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', CppOptional(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 123EXPERIMENTAL_FLAT_SLICE_TABLE = Table( 124 python_module=__file__, 125 class_name='ExperimentalFlatSliceTable', 126 sql_name='experimental_flat_slice', 127 columns=[ 128 C('ts', CppInt64()), 129 C('dur', CppInt64()), 130 C('track_id', CppTableId(TRACK_TABLE)), 131 C('category', CppOptional(CppString())), 132 C('name', CppOptional(CppString())), 133 C('arg_set_id', CppOptional(CppUint32())), 134 C('source_id', CppOptional(CppTableId(SLICE_TABLE))), 135 C('start_bound', CppInt64(), flags=ColumnFlag.HIDDEN), 136 C('end_bound', CppInt64(), flags=ColumnFlag.HIDDEN), 137 ], 138 tabledoc=TableDoc( 139 doc=''' 140 An experimental table which "flattens" stacks of slices to contain 141 only the "deepest" slice at any point in time on each track. 142 ''', 143 group='Slice', 144 columns={ 145 'ts': 146 '''The timestamp at the start of the slice (in nanoseconds).''', 147 'dur': 148 '''The duration of the slice (in nanoseconds).''', 149 'track_id': 150 'The id of the track this slice is located on.', 151 'category': 152 ''' 153 The "category" of the slice. If this slice originated with 154 track_event, this column contains the category emitted. 155 Otherwise, it is likely to be null (with limited exceptions). 156 ''', 157 'name': 158 ''' 159 The name of the slice. The name describes what was happening 160 during the slice. 161 ''', 162 'arg_set_id': 163 ColumnDoc( 164 'The id of the argument set associated with this slice.', 165 joinable='args.arg_set_id'), 166 'source_id': 167 'The id of the slice which this row originated from.', 168 })) 169 170ANDROID_NETWORK_PACKETS_TABLE = Table( 171 python_module=__file__, 172 class_name='AndroidNetworkPacketsTable', 173 sql_name='__intrinsic_android_network_packets', 174 columns=[ 175 C('iface', CppString()), 176 C('direction', CppString()), 177 C('packet_transport', CppString()), 178 C('packet_length', CppInt64()), 179 C('packet_count', CppInt64()), 180 C('socket_tag', CppUint32()), 181 C('socket_tag_str', CppString()), 182 C('socket_uid', CppUint32()), 183 C('local_port', CppOptional(CppUint32())), 184 C('remote_port', CppOptional(CppUint32())), 185 C('packet_icmp_type', CppOptional(CppUint32())), 186 C('packet_icmp_code', CppOptional(CppUint32())), 187 C('packet_tcp_flags', CppOptional(CppUint32())), 188 C('packet_tcp_flags_str', CppOptional(CppString())), 189 ], 190 parent=SLICE_TABLE) 191 192# Keep this list sorted. 193ALL_TABLES = [ 194 ANDROID_NETWORK_PACKETS_TABLE, 195 EXPERIMENTAL_FLAT_SLICE_TABLE, 196 SLICE_TABLE, 197] 198