1# Copyright (C) 2022 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 tracks.""" 15 16from python.generators.trace_processor_table.public import Column as C 17from python.generators.trace_processor_table.public import CppInt32 18from python.generators.trace_processor_table.public import CppInt64 19from python.generators.trace_processor_table.public import CppOptional 20from python.generators.trace_processor_table.public import CppString 21from python.generators.trace_processor_table.public import Table 22from python.generators.trace_processor_table.public import TableDoc 23from python.generators.trace_processor_table.public import ColumnDoc 24from python.generators.trace_processor_table.public import CppSelfTableId 25from python.generators.trace_processor_table.public import CppUint32 26 27TRACK_TABLE = Table( 28 python_module=__file__, 29 class_name="TrackTable", 30 sql_name="track", 31 columns=[ 32 C("name", CppString()), 33 C("parent_id", CppOptional(CppSelfTableId())), 34 C("source_arg_set_id", CppOptional(CppUint32())), 35 ], 36 tabledoc=TableDoc( 37 doc=''' 38 Tracks are a fundamental concept in trace processor and represent a 39 "timeline" for events of the same type and with the same context. See 40 https://perfetto.dev/docs/analysis/trace-processor#tracks for a more 41 detailed explanation, with examples. 42 ''', 43 group='Tracks', 44 columns={ 45 'name': 46 ''' 47 Name of the track; can be null for some types of tracks (e.g. 48 thread tracks). 49 ''', 50 'parent_id': 51 ''' 52 The track which is the "parent" of this track. Only non-null 53 for tracks created using Perfetto's track_event API. 54 ''', 55 'source_arg_set_id': 56 ColumnDoc( 57 doc=''' 58 Args for this track which store information about "source" 59 of this track in the trace. For example: whether this 60 track orginated from atrace, Chrome tracepoints etc. 61 ''', 62 joinable='args.arg_set_id'), 63 })) 64 65PROCESS_TRACK_TABLE = Table( 66 python_module=__file__, 67 class_name="ProcessTrackTable", 68 sql_name="process_track", 69 columns=[ 70 C("upid", CppUint32()), 71 ], 72 parent=TRACK_TABLE, 73 tabledoc=TableDoc( 74 doc=''' 75 Tracks which are associated to the process given by the |upid| column 76 ''', 77 group='Tracks', 78 columns={ 79 'upid': 80 ColumnDoc( 81 doc='The process associated with this track.', 82 joinable='process.upid'), 83 })) 84 85THREAD_TRACK_TABLE = Table( 86 python_module=__file__, 87 class_name='ThreadTrackTable', 88 sql_name='thread_track', 89 columns=[ 90 C('utid', CppUint32()), 91 ], 92 parent=TRACK_TABLE, 93 tabledoc=TableDoc( 94 doc=''' 95 Tracks which are associated to the thread given by the |utid| column 96 ''', 97 group='Tracks', 98 columns={ 99 'utid': 100 ColumnDoc( 101 doc='The thread associated with this track', 102 joinable='thread.utid', 103 ) 104 })) 105 106CPU_TRACK_TABLE = Table( 107 python_module=__file__, 108 class_name='CpuTrackTable', 109 sql_name='cpu_track', 110 columns=[ 111 C('cpu', CppUint32()), 112 ], 113 parent=TRACK_TABLE, 114 tabledoc=TableDoc( 115 doc='Tracks which are associated to a single CPU', 116 group='Tracks', 117 columns={'cpu': 'The CPU associated with this track'})) 118 119GPU_TRACK_TABLE = Table( 120 python_module=__file__, 121 class_name='GpuTrackTable', 122 sql_name='gpu_track', 123 columns=[ 124 C('scope', CppString()), 125 C('description', CppString()), 126 C('context_id', CppOptional(CppInt64())), 127 ], 128 parent=TRACK_TABLE, 129 tabledoc=TableDoc( 130 doc='Tracks assocaited to a GPU.', 131 group='Tracks', 132 columns={ 133 'scope': 134 'The scope for the track. For debugging purposes only.', 135 'description': 136 'The description of the track. For debugging purposes only.', 137 'context_id': 138 'The context id for the GPU this track is associated to.' 139 })) 140 141COUNTER_TRACK_TABLE = Table( 142 python_module=__file__, 143 class_name='CounterTrackTable', 144 sql_name='counter_track', 145 columns=[ 146 C('unit', CppString()), 147 C('description', CppString()), 148 ], 149 parent=TRACK_TABLE, 150 tabledoc=TableDoc( 151 doc=''' 152 Tracks containing counter-like events. See 153 https://perfetto.dev/docs/analysis/trace-processor#events for a 154 defintion and examples of counters. 155 ''', 156 group='Tracks', 157 columns={ 158 'unit': 159 'The units of the counter. This column is rarely filled.', 160 'description': 161 'The description for this track. For debugging purposes only.' 162 })) 163 164THREAD_COUNTER_TRACK_TABLE = Table( 165 python_module=__file__, 166 class_name='ThreadCounterTrackTable', 167 sql_name='thread_counter_track', 168 columns=[ 169 C('utid', CppUint32()), 170 ], 171 parent=COUNTER_TRACK_TABLE, 172 tabledoc=TableDoc( 173 doc='Tracks containing counter-like events associated to a thread.', 174 group='Tracks', 175 columns={ 176 'utid': 177 ColumnDoc( 178 doc='The thread associated with this track', 179 joinable='thread.utid', 180 ) 181 })) 182 183PROCESS_COUNTER_TRACK_TABLE = Table( 184 python_module=__file__, 185 class_name='ProcessCounterTrackTable', 186 sql_name='process_counter_track', 187 columns=[ 188 C('upid', CppUint32()), 189 ], 190 parent=COUNTER_TRACK_TABLE, 191 tabledoc=TableDoc( 192 doc=''' 193 Tracks containing counter-like events associated to a process. 194 ''', 195 group='Tracks', 196 columns={ 197 'upid': 198 ColumnDoc( 199 doc='The process associated with this track', 200 joinable='process.upid') 201 })) 202 203CPU_COUNTER_TRACK_TABLE = Table( 204 python_module=__file__, 205 class_name='CpuCounterTrackTable', 206 sql_name='cpu_counter_track', 207 columns=[ 208 C('cpu', CppUint32()), 209 ], 210 parent=COUNTER_TRACK_TABLE, 211 tabledoc=TableDoc( 212 doc='Tracks containing counter-like events associated to a CPU.', 213 group='Tracks', 214 columns={'cpu': 'The CPU this track is associated with'})) 215 216IRQ_COUNTER_TRACK_TABLE = Table( 217 python_module=__file__, 218 class_name='IrqCounterTrackTable', 219 sql_name='irq_counter_track', 220 columns=[ 221 C('irq', CppInt32()), 222 ], 223 parent=COUNTER_TRACK_TABLE, 224 tabledoc=TableDoc( 225 doc='Tracks containing counter-like events associated to an hardirq', 226 group='Tracks', 227 columns={'irq': 'The identifier for the hardirq.'})) 228 229SOFTIRQ_COUNTER_TRACK_TABLE = Table( 230 python_module=__file__, 231 class_name='SoftirqCounterTrackTable', 232 sql_name='softirq_counter_track', 233 columns=[ 234 C('softirq', CppInt32()), 235 ], 236 parent=COUNTER_TRACK_TABLE, 237 tabledoc=TableDoc( 238 doc='Tracks containing counter-like events associated to a softirq', 239 group='Tracks', 240 columns={'softirq': 'The identifier for the softirq.'})) 241 242GPU_COUNTER_TRACK_TABLE = Table( 243 python_module=__file__, 244 class_name='GpuCounterTrackTable', 245 sql_name='gpu_counter_track', 246 columns=[ 247 C('gpu_id', CppUint32()), 248 ], 249 parent=COUNTER_TRACK_TABLE, 250 tabledoc=TableDoc( 251 doc='Tracks containing counter-like events associated to a GPU', 252 group='Tracks', 253 columns={'gpu_id': 'The identifier for the GPU.'})) 254 255PERF_COUNTER_TRACK_TABLE = Table( 256 python_module=__file__, 257 class_name='PerfCounterTrackTable', 258 sql_name='perf_counter_track', 259 columns=[ 260 C('perf_session_id', CppUint32()), 261 C('cpu', CppUint32()), 262 C('is_timebase', CppUint32()), 263 ], 264 parent=COUNTER_TRACK_TABLE, 265 tabledoc=TableDoc( 266 doc='Sampled counters\' values for samples in the perf_sample table.', 267 group='Tracks', 268 columns={ 269 'perf_session_id': 270 'id of a distict profiling stream', 271 'cpu': 272 'the core the sample was taken on', 273 'is_timebase': 274 ''' 275 If true, indicates this counter was the sampling timebase for 276 this perf_session_id 277 ''' 278 })) 279 280ENERGY_COUNTER_TRACK_TABLE = Table( 281 python_module=__file__, 282 class_name='EnergyCounterTrackTable', 283 sql_name='energy_counter_track', 284 columns=[ 285 C('consumer_id', CppInt32()), 286 C('consumer_type', CppString()), 287 C('ordinal', CppInt32()), 288 ], 289 parent=COUNTER_TRACK_TABLE, 290 tabledoc=TableDoc( 291 doc=''' 292 Energy consumers' values for energy descriptors in 293 energy_estimation_breakdown packet 294 ''', 295 group='Tracks', 296 columns={ 297 'consumer_id': 'id of a distinct energy consumer', 298 'consumer_type': 'type of energy consumer', 299 'ordinal': 'ordinal of energy consumer' 300 })) 301 302UID_COUNTER_TRACK_TABLE = Table( 303 python_module=__file__, 304 class_name='UidCounterTrackTable', 305 sql_name='uid_counter_track', 306 columns=[ 307 C('uid', CppInt32()), 308 ], 309 parent=COUNTER_TRACK_TABLE, 310 tabledoc=TableDoc( 311 doc='The uid associated with this track', 312 group='Tracks', 313 columns={'uid': 'uid of process for which breakdowns are emitted'})) 314 315ENERGY_PER_UID_COUNTER_TRACK_TABLE = Table( 316 python_module=__file__, 317 class_name='EnergyPerUidCounterTrackTable', 318 sql_name='energy_per_uid_counter_track', 319 columns=[ 320 C('consumer_id', CppInt32()), 321 ], 322 parent=UID_COUNTER_TRACK_TABLE, 323 tabledoc=TableDoc( 324 doc='Energy consumer values for per uid in uid_counter_track', 325 group='Tracks', 326 columns={'consumer_id': 'id of the consumer process'})) 327 328# Keep this list sorted. 329ALL_TABLES = [ 330 COUNTER_TRACK_TABLE, 331 CPU_COUNTER_TRACK_TABLE, 332 CPU_TRACK_TABLE, 333 ENERGY_COUNTER_TRACK_TABLE, 334 ENERGY_PER_UID_COUNTER_TRACK_TABLE, 335 GPU_COUNTER_TRACK_TABLE, 336 GPU_TRACK_TABLE, 337 IRQ_COUNTER_TRACK_TABLE, 338 PERF_COUNTER_TRACK_TABLE, 339 PROCESS_COUNTER_TRACK_TABLE, 340 PROCESS_TRACK_TABLE, 341 SOFTIRQ_COUNTER_TRACK_TABLE, 342 THREAD_COUNTER_TRACK_TABLE, 343 THREAD_TRACK_TABLE, 344 TRACK_TABLE, 345 UID_COUNTER_TRACK_TABLE, 346] 347