xref: /aosp_15_r20/external/perfetto/src/trace_processor/tables/metadata_tables.py (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 metadata tables for a wide range of usecases."""
15
16from python.generators.trace_processor_table.public import Alias
17from python.generators.trace_processor_table.public import Column as C
18from python.generators.trace_processor_table.public import ColumnDoc
19from python.generators.trace_processor_table.public import ColumnFlag
20from python.generators.trace_processor_table.public import CppDouble
21from python.generators.trace_processor_table.public import CppInt64
22from python.generators.trace_processor_table.public import CppOptional
23from python.generators.trace_processor_table.public import CppString
24from python.generators.trace_processor_table.public import Table
25from python.generators.trace_processor_table.public import TableDoc
26from python.generators.trace_processor_table.public import CppTableId
27from python.generators.trace_processor_table.public import CppUint32
28from python.generators.trace_processor_table.public import CppSelfTableId
29from python.generators.trace_processor_table.public import WrappingSqlView
30
31MACHINE_TABLE = Table(
32    python_module=__file__,
33    class_name='MachineTable',
34    sql_name='machine',
35    columns=[
36        C('raw_id', CppUint32()),
37    ],
38    tabledoc=TableDoc(
39        doc='''
40          Contains raw machine_id of trace packets emitted from remote machines.
41        ''',
42        group='Metadata',
43        columns={
44            'raw_id':
45                '''
46                  Raw machine identifier in the trace packet, non-zero for
47                  remote machines.
48                '''
49        }))
50
51PROCESS_TABLE = Table(
52    python_module=__file__,
53    class_name='ProcessTable',
54    sql_name='__intrinsic_process',
55    columns=[
56        C('upid', Alias(underlying_column='id')),
57        C('pid', CppUint32()),
58        C('name', CppOptional(CppString())),
59        C('start_ts', CppOptional(CppInt64())),
60        C('end_ts', CppOptional(CppInt64())),
61        C('parent_upid', CppOptional(CppSelfTableId())),
62        C('uid', CppOptional(CppUint32())),
63        C('android_appid', CppOptional(CppUint32())),
64        C('cmdline', CppOptional(CppString())),
65        C('arg_set_id', CppUint32()),
66        C('machine_id', CppOptional(CppTableId(MACHINE_TABLE))),
67    ],
68    wrapping_sql_view=WrappingSqlView(view_name='process',),
69    tabledoc=TableDoc(
70        doc='Contains information of processes seen during the trace',
71        group='Metadata',
72        skip_id_and_type=True,
73        columns={
74            'upid':
75                '''
76                   Unique process id. This is != the OS pid. This is a
77                   monotonic number associated to each process. The OS process
78                   id (pid) cannot be used as primary key because tids and pids
79                   are recycled by most kernels.
80                ''',
81            'pid':
82                '''
83                  The OS id for this process. Note: this is *not* unique
84                  over the lifetime of the trace so cannot be used as a
85                  primary key. Use |upid| instead.
86                ''',
87            'name':
88                '''
89                  The name of the process. Can be populated from many sources
90                  (e.g. ftrace, /proc scraping, track event etc).
91                ''',
92            'start_ts':
93                '''
94                  The start timestamp of this process (if known). Is null
95                  in most cases unless a process creation event is enabled
96                  (e.g. task_newtask ftrace event on Linux/Android).
97                ''',
98            'end_ts':
99                '''
100                  The end timestamp of this process (if known). Is null in
101                  most cases unless a process destruction event is enabled
102                  (e.g. sched_process_free ftrace event on Linux/Android).
103                ''',
104            'parent_upid':
105                ColumnDoc(
106                    '''
107                  The upid of the process which caused this process to be
108                  spawned.
109                ''',
110                    joinable='process.upid'),
111            'uid':
112                ColumnDoc(
113                    'The Unix user id of the process.',
114                    joinable='package_list.uid'),
115            'android_appid':
116                'Android appid of this process.',
117            'cmdline':
118                '/proc/cmdline for this process.',
119            'arg_set_id':
120                ColumnDoc(
121                    'Extra args for this process.', joinable='args.arg_set_id'),
122            'machine_id':
123                '''
124                  Machine identifier, non-null for processes on a remote
125                  machine.
126                ''',
127        }))
128
129THREAD_TABLE = Table(
130    python_module=__file__,
131    class_name='ThreadTable',
132    sql_name='__intrinsic_thread',
133    columns=[
134        C('utid', Alias(underlying_column='id')),
135        C('tid', CppUint32()),
136        C('name', CppOptional(CppString())),
137        C('start_ts', CppOptional(CppInt64())),
138        C('end_ts', CppOptional(CppInt64())),
139        C('upid', CppOptional(CppTableId(PROCESS_TABLE))),
140        C('is_main_thread', CppOptional(CppUint32())),
141        C('machine_id', CppOptional(CppTableId(MACHINE_TABLE))),
142    ],
143    wrapping_sql_view=WrappingSqlView(view_name='thread',),
144    tabledoc=TableDoc(
145        doc='Contains information of threads seen during the trace',
146        group='Metadata',
147        skip_id_and_type=True,
148        columns={
149            'utid':
150                '''
151                  Unique thread id. This is != the OS tid. This is a monotonic
152                  number associated to each thread. The OS thread id (tid)
153                  cannot be used as primary key because tids and pids are
154                  recycled by most kernels.
155                ''',
156            'tid':
157                '''
158                  The OS id for this thread. Note: this is *not* unique over the
159                  lifetime of the trace so cannot be used as a primary key. Use
160                  |utid| instead.
161                ''',
162            'name':
163                '''
164                  The name of the thread. Can be populated from many sources
165                  (e.g. ftrace, /proc scraping, track event etc).
166                ''',
167            'start_ts':
168                '''
169                  The start timestamp of this thread (if known). Is null in most
170                  cases unless a thread creation event is enabled (e.g.
171                  task_newtask ftrace event on Linux/Android).
172                ''',
173            'end_ts':
174                '''
175                  The end timestamp of this thread (if known). Is null in most
176                  cases unless a thread destruction event is enabled (e.g.
177                  sched_process_free ftrace event on Linux/Android).
178                ''',
179            'upid':
180                ColumnDoc(
181                    'The process hosting this thread.',
182                    joinable='process.upid'),
183            'is_main_thread':
184                '''
185                  Boolean indicating if this thread is the main thread
186                  in the process.
187                ''',
188            'machine_id':
189                '''
190                  Machine identifier, non-null for threads on a remote machine.
191                ''',
192        }))
193
194CPU_TABLE = Table(
195    python_module=__file__,
196    class_name='CpuTable',
197    sql_name='__intrinsic_cpu',
198    columns=[
199        C('cpu', CppOptional(CppUint32())),
200        C('cluster_id', CppUint32()),
201        C('processor', CppString()),
202        C('machine_id', CppOptional(CppTableId(MACHINE_TABLE))),
203        C('capacity', CppOptional(CppUint32())),
204        C('arg_set_id', CppOptional(CppUint32())),
205    ],
206    wrapping_sql_view=WrappingSqlView('cpu'),
207    tabledoc=TableDoc(
208        doc='''
209          Contains information of processes seen during the trace
210        ''',
211        group='Misc',
212        columns={
213            'cpu':
214                '''the index (0-based) of the CPU core on the device''',
215            'cluster_id':
216                '''the cluster id is shared by CPUs in the same cluster''',
217            'processor':
218                '''a string describing this core''',
219            'machine_id':
220                '''
221                  Machine identifier, non-null for CPUs on a remote machine.
222                ''',
223            'capacity':
224                '''
225                  Capacity of a CPU of a device, a metric which indicates the
226                  relative performance of a CPU on a device
227                  For details see:
228                  https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/cpu-capacity.txt
229                ''',
230            'arg_set_id':
231                '''Extra args associated with the CPU''',
232        }))
233
234RAW_TABLE = Table(
235    python_module=__file__,
236    class_name='RawTable',
237    sql_name='__intrinsic_raw',
238    columns=[
239        C('ts', CppInt64(), flags=ColumnFlag.SORTED),
240        C('name', CppString()),
241        C('utid', CppTableId(THREAD_TABLE)),
242        C('arg_set_id', CppUint32()),
243        C('common_flags', CppUint32()),
244        C('ucpu', CppTableId(CPU_TABLE))
245    ],
246    wrapping_sql_view=WrappingSqlView('track'),
247    tabledoc=TableDoc(
248        doc='''
249          Contains 'raw' events from the trace for some types of events. This
250          table only exists for debugging purposes and should not be relied on
251          in production usecases (i.e. metrics, standard library etc).
252
253          If you are looking for ftrace_events: please use the ftrace_event table.
254        ''',
255        group='Events',
256        columns={
257            'arg_set_id':
258                ColumnDoc(
259                    'The set of key/value pairs associated with this event.',
260                    joinable='args.arg_set_id'),
261            'ts':
262                'The timestamp of this event.',
263            'name':
264                '''
265                  The name of the event. For ftrace events, this will be the
266                  ftrace event name.
267                ''',
268            'utid':
269                'The thread this event was emitted on.',
270            'common_flags':
271                '''
272                  Ftrace event flags for this event. Currently only emitted for
273                  sched_waking events.
274                ''',
275            'ucpu':
276                '''
277                  The unique CPU indentifier.
278                ''',
279        }))
280
281FTRACE_EVENT_TABLE = Table(
282    python_module=__file__,
283    class_name='FtraceEventTable',
284    sql_name='__intrinsic_ftrace_event',
285    parent=RAW_TABLE,
286    columns=[],
287    wrapping_sql_view=WrappingSqlView('ftrace_event'),
288    tabledoc=TableDoc(
289        doc='''
290          Contains all the ftrace events in the trace. This table exists only
291          for debugging purposes and should not be relied on in production
292          usecases (i.e. metrics, standard library etc). Note also that this
293          table might be empty if raw ftrace parsing has been disabled.
294        ''',
295        group='Events',
296        columns={}))
297
298ARG_TABLE = Table(
299    python_module=__file__,
300    class_name='ArgTable',
301    sql_name='__intrinsic_args',
302    columns=[
303        C('arg_set_id', CppUint32(), flags=ColumnFlag.SORTED),
304        C('flat_key', CppString()),
305        C('key', CppString()),
306        C('int_value', CppOptional(CppInt64())),
307        C('string_value', CppOptional(CppString())),
308        C('real_value', CppOptional(CppDouble())),
309        C('value_type', CppString()),
310    ],
311    wrapping_sql_view=WrappingSqlView(view_name='args'),
312    tabledoc=TableDoc(
313        doc='''''',
314        group='Misc',
315        columns={
316            'arg_set_id': '''''',
317            'flat_key': '''''',
318            'key': '''''',
319            'int_value': '''''',
320            'string_value': '''''',
321            'real_value': '''''',
322            'value_type': ''''''
323        }))
324
325METADATA_TABLE = Table(
326    python_module=__file__,
327    class_name='MetadataTable',
328    sql_name='metadata',
329    columns=[
330        C('name', CppString()),
331        C('key_type', CppString()),
332        C('int_value', CppOptional(CppInt64())),
333        C('str_value', CppOptional(CppString())),
334    ],
335    tabledoc=TableDoc(
336        doc='''''',
337        group='Metadata',
338        columns={
339            'name': '''''',
340            'key_type': '''''',
341            'int_value': '''''',
342            'str_value': ''''''
343        }))
344
345FILEDESCRIPTOR_TABLE = Table(
346    python_module=__file__,
347    class_name='FiledescriptorTable',
348    sql_name='filedescriptor',
349    columns=[
350        C('ufd', CppInt64()),
351        C('fd', CppInt64()),
352        C('ts', CppOptional(CppInt64())),
353        C('upid', CppOptional(CppUint32())),
354        C('path', CppOptional(CppString())),
355    ],
356    tabledoc=TableDoc(
357        doc='''
358          Contains information of filedescriptors collected during the trace
359        ''',
360        group='Metadata',
361        columns={
362            'ufd':
363                '''Unique fd. This is != the OS fd.
364This is a monotonic number associated to each
365filedescriptor. The OS assigned fd cannot be used as
366primary key because fds are recycled by most kernels.''',
367            'fd':
368                '''The OS id for this process. Note: this is *not*
369unique over the lifetime of the trace so cannot be
370used as a primary key. Use |ufd| instead.''',
371            'ts':
372                '''The timestamp for when the fd was collected.''',
373            'upid':
374                ''' The upid of the process which
375opened the filedescriptor.''',
376            'path':
377                '''The path to the file or device backing the fd
378In case this was a socket the path will be the port
379number.'''
380        }))
381
382EXP_MISSING_CHROME_PROC_TABLE = Table(
383    python_module=__file__,
384    class_name='ExpMissingChromeProcTable',
385    sql_name='experimental_missing_chrome_processes',
386    columns=[
387        C('upid', CppUint32()),
388        C('reliable_from', CppOptional(CppInt64())),
389    ],
390    tabledoc=TableDoc(
391        doc='''
392          Experimental table, subject to arbitrary breaking changes.
393        ''',
394        group='Chrome',
395        columns={
396            'upid': '''''',
397            'reliable_from': ''''''
398        }))
399
400CPU_FREQ_TABLE = Table(
401    python_module=__file__,
402    class_name='CpuFreqTable',
403    sql_name='__intrinsic_cpu_freq',
404    columns=[
405        C('ucpu', CppTableId(CPU_TABLE)),
406        C('freq', CppUint32()),
407    ],
408    wrapping_sql_view=WrappingSqlView('cpu_freq'),
409    tabledoc=TableDoc(
410        doc='''''', group='Misc', columns={
411            'ucpu': '''''',
412            'freq': '''''',
413        }))
414
415CLOCK_SNAPSHOT_TABLE = Table(
416    python_module=__file__,
417    class_name='ClockSnapshotTable',
418    sql_name='clock_snapshot',
419    columns=[
420        C('ts', CppInt64()),
421        C('clock_id', CppInt64()),
422        C('clock_name', CppOptional(CppString())),
423        C('clock_value', CppInt64()),
424        C('snapshot_id', CppUint32()),
425        C('machine_id', CppOptional(CppTableId(MACHINE_TABLE))),
426    ],
427    tabledoc=TableDoc(
428        doc='''
429          Contains all the mapping between clock snapshots and trace time.
430
431NOTE: this table is not sorted by timestamp; this is why we omit the
432sorted flag on the ts column.
433        ''',
434        group='Misc',
435        columns={
436            'ts':
437                '''timestamp of the snapshot in trace time.''',
438            'clock_id':
439                '''id of the clock (corresponds to the id in the trace).''',
440            'clock_name':
441                '''the name of the clock for builtin clocks or null
442otherwise.''',
443            'clock_value':
444                '''timestamp of the snapshot in clock time.''',
445            'snapshot_id':
446                '''the index of this snapshot (only useful for debugging)''',
447            'machine_id':
448                '''
449                  Machine identifier, non-null for clock snapshots on a remote
450                  machine.
451                ''',
452        }))
453
454TRACE_FILE_TABLE = Table(
455    python_module=__file__,
456    class_name='TraceFileTable',
457    sql_name='__intrinsic_trace_file',
458    columns=[
459        C('parent_id', CppOptional(CppSelfTableId())),
460        C('name', CppOptional(CppString())),
461        C('size', CppInt64()),
462        C('trace_type', CppString()),
463        C('processing_order', CppOptional(CppInt64())),
464    ],
465    wrapping_sql_view=WrappingSqlView('trace_file'),
466    tabledoc=TableDoc(
467        doc='''
468            Metadata related to the trace file parsed. Note the order in which
469            the files appear in this table corresponds to the order in which
470            they are read and sent to the tokenization stage.
471        ''',
472        group='Misc',
473        columns={
474            'parent_id':
475                '''
476                  Parent file. E.g. files contained in a zip file will point to
477                  the zip file.
478                ''',
479            'name':
480                '''File name, if known, NULL otherwise''',
481            'size':
482                '''Size in bytes''',
483            'trace_type':
484                '''Trace type''',
485            'processing_order':
486                '''In which order where the files were processed.''',
487        }))
488
489# Keep this list sorted.
490ALL_TABLES = [
491    ARG_TABLE,
492    CLOCK_SNAPSHOT_TABLE,
493    CPU_FREQ_TABLE,
494    CPU_TABLE,
495    EXP_MISSING_CHROME_PROC_TABLE,
496    FILEDESCRIPTOR_TABLE,
497    FTRACE_EVENT_TABLE,
498    MACHINE_TABLE,
499    METADATA_TABLE,
500    PROCESS_TABLE,
501    RAW_TABLE,
502    THREAD_TABLE,
503    TRACE_FILE_TABLE,
504]
505