• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
31PROCESS_TABLE = Table(
32    python_module=__file__,
33    class_name='ProcessTable',
34    sql_name='internal_process',
35    columns=[
36        C('upid', Alias(underlying_column='id')),
37        C('pid', CppUint32()),
38        C('name', CppOptional(CppString())),
39        C('start_ts', CppOptional(CppInt64())),
40        C('end_ts', CppOptional(CppInt64())),
41        C('parent_upid', CppOptional(CppSelfTableId())),
42        C('uid', CppOptional(CppUint32())),
43        C('android_appid', CppOptional(CppUint32())),
44        C('cmdline', CppOptional(CppString())),
45        C('arg_set_id', CppUint32()),
46    ],
47    wrapping_sql_view=WrappingSqlView(view_name='process',),
48    tabledoc=TableDoc(
49        doc='Contains information of processes seen during the trace',
50        group='Misc',
51        skip_id_and_type=True,
52        columns={
53            'upid':
54                '''
55                   Unique process id. This is != the OS pid. This is a
56                   monotonic number associated to each process. The OS process
57                   id (pid) cannot be used as primary key because tids and pids
58                   are recycled by most kernels.
59                ''',
60            'pid':
61                '''
62                  The OS id for this process. Note: this is *not* unique
63                  over the lifetime of the trace so cannot be used as a
64                  primary key. Use |upid| instead.
65                ''',
66            'name':
67                '''
68                  The name of the process. Can be populated from many sources
69                  (e.g. ftrace, /proc scraping, track event etc).
70                ''',
71            'start_ts':
72                '''
73                  The start timestamp of this process (if known). Is null
74                  in most cases unless a process creation event is enabled
75                  (e.g. task_newtask ftrace event on Linux/Android).
76                ''',
77            'end_ts':
78                '''
79                  The end timestamp of this process (if known). Is null in
80                  most cases unless a process destruction event is enabled
81                  (e.g. sched_process_free ftrace event on Linux/Android).
82                ''',
83            'parent_upid':
84                ColumnDoc(
85                    '''
86                  The upid of the process which caused this process to be
87                  spawned.
88                ''',
89                    joinable='process.upid'),
90            'uid':
91                ColumnDoc(
92                    'The Unix user id of the process.',
93                    joinable='package_list.uid'),
94            'android_appid':
95                'Android appid of this process.',
96            'cmdline':
97                '/proc/cmdline for this process.',
98            'arg_set_id':
99                ColumnDoc(
100                    'Extra args for this process.', joinable='args.arg_set_id'),
101        }))
102
103THREAD_TABLE = Table(
104    python_module=__file__,
105    class_name='ThreadTable',
106    sql_name='internal_thread',
107    columns=[
108        C('utid', Alias(underlying_column='id')),
109        C('tid', CppUint32()),
110        C('name', CppOptional(CppString())),
111        C('start_ts', CppOptional(CppInt64())),
112        C('end_ts', CppOptional(CppInt64())),
113        C('upid', CppOptional(CppTableId(PROCESS_TABLE))),
114        C('is_main_thread', CppOptional(CppUint32())),
115    ],
116    wrapping_sql_view=WrappingSqlView(view_name='thread',),
117    tabledoc=TableDoc(
118        doc='Contains information of threads seen during the trace',
119        group='Misc',
120        skip_id_and_type=True,
121        columns={
122            'utid':
123                '''
124                  Unique thread id. This is != the OS tid. This is a monotonic
125                  number associated to each thread. The OS thread id (tid)
126                  cannot be used as primary key because tids and pids are
127                  recycled by most kernels.
128                ''',
129            'tid':
130                '''
131                  The OS id for this thread. Note: this is *not* unique over the
132                  lifetime of the trace so cannot be used as a primary key. Use
133                  |utid| instead.
134                ''',
135            'name':
136                '''
137                  The name of the thread. Can be populated from many sources
138                  (e.g. ftrace, /proc scraping, track event etc).
139                ''',
140            'start_ts':
141                '''
142                  The start timestamp of this thread (if known). Is null in most
143                  cases unless a thread creation event is enabled (e.g.
144                  task_newtask ftrace event on Linux/Android).
145                ''',
146            'end_ts':
147                '''
148                  The end timestamp of this thread (if known). Is null in most
149                  cases unless a thread destruction event is enabled (e.g.
150                  sched_process_free ftrace event on Linux/Android).
151                ''',
152            'upid':
153                ColumnDoc(
154                    'The process hosting this thread.',
155                    joinable='process.upid'),
156            'is_main_thread':
157                '''
158                  Boolean indicating if this thread is the main thread
159                  in the process.
160                '''
161        }))
162
163RAW_TABLE = Table(
164    python_module=__file__,
165    class_name='RawTable',
166    sql_name='raw',
167    columns=[
168        C('ts', CppInt64(), flags=ColumnFlag.SORTED),
169        C('name', CppString()),
170        C('cpu', CppUint32()),
171        C('utid', CppTableId(THREAD_TABLE)),
172        C('arg_set_id', CppUint32()),
173    ],
174    tabledoc=TableDoc(
175        doc='''
176          Contains 'raw' events from the trace for some types of events. This
177          table only exists for debugging purposes and should not be relied on
178          in production usecases (i.e. metrics, standard library etc).
179        ''',
180        group='Misc',
181        columns={
182            'arg_set_id':
183                ColumnDoc(
184                    'The set of key/value pairs associated with this event.',
185                    joinable='args.arg_set_id'),
186            'ts':
187                'The timestamp of this event.',
188            'name':
189                '''
190                  The name of the event. For ftrace events, this will be the
191                  ftrace event name.
192                ''',
193            'cpu':
194                'The CPU this event was emitted on.',
195            'utid':
196                'The thread this event was emitted on.'
197        }))
198
199FTRACE_EVENT_TABLE = Table(
200    python_module=__file__,
201    class_name='FtraceEventTable',
202    sql_name='ftrace_event',
203    parent=RAW_TABLE,
204    columns=[],
205    tabledoc=TableDoc(
206        doc='''
207      Contains all the ftrace events in the trace. This table exists only for
208      debugging purposes and should not be relied on in production usecases
209      (i.e. metrics, standard library etc). Note also that this table might
210      be empty if raw ftrace parsing has been disabled.
211    ''',
212        group='Misc',
213        columns={}))
214
215ARG_TABLE = Table(
216    python_module=__file__,
217    class_name='ArgTable',
218    sql_name='internal_args',
219    columns=[
220        C('arg_set_id', CppUint32(), flags=ColumnFlag.SORTED),
221        C('flat_key', CppString()),
222        C('key', CppString()),
223        C('int_value', CppOptional(CppInt64())),
224        C('string_value', CppOptional(CppString())),
225        C('real_value', CppOptional(CppDouble())),
226        C('value_type', CppString()),
227    ],
228    wrapping_sql_view=WrappingSqlView(view_name='args'),
229    tabledoc=TableDoc(
230        doc='''''',
231        group='Misc',
232        columns={
233            'arg_set_id': '''''',
234            'flat_key': '''''',
235            'key': '''''',
236            'int_value': '''''',
237            'string_value': '''''',
238            'real_value': '''''',
239            'value_type': ''''''
240        }))
241
242METADATA_TABLE = Table(
243    python_module=__file__,
244    class_name='MetadataTable',
245    sql_name='metadata',
246    columns=[
247        C('name', CppString()),
248        C('key_type', CppString()),
249        C('int_value', CppOptional(CppInt64())),
250        C('str_value', CppOptional(CppString())),
251    ],
252    tabledoc=TableDoc(
253        doc='''''',
254        group='Misc',
255        columns={
256            'name': '''''',
257            'key_type': '''''',
258            'int_value': '''''',
259            'str_value': ''''''
260        }))
261
262FILEDESCRIPTOR_TABLE = Table(
263    python_module=__file__,
264    class_name='FiledescriptorTable',
265    sql_name='filedescriptor',
266    columns=[
267        C('ufd', CppInt64()),
268        C('fd', CppInt64()),
269        C('ts', CppOptional(CppInt64())),
270        C('upid', CppOptional(CppUint32())),
271        C('path', CppOptional(CppString())),
272    ],
273    tabledoc=TableDoc(
274        doc='''
275          Contains information of filedescriptors collected during the trace
276        ''',
277        group='Misc',
278        columns={
279            'ufd':
280                '''Unique fd. This is != the OS fd.
281This is a monotonic number associated to each
282filedescriptor. The OS assigned fd cannot be used as
283primary key because fds are recycled by most kernels.''',
284            'fd':
285                '''The OS id for this process. Note: this is *not*
286unique over the lifetime of the trace so cannot be
287used as a primary key. Use |ufd| instead.''',
288            'ts':
289                '''The timestamp for when the fd was collected.''',
290            'upid':
291                ''' The upid of the process which
292opened the filedescriptor.''',
293            'path':
294                '''The path to the file or device backing the fd
295In case this was a socket the path will be the port
296number.'''
297        }))
298
299EXP_MISSING_CHROME_PROC_TABLE = Table(
300    python_module=__file__,
301    class_name='ExpMissingChromeProcTable',
302    sql_name='experimental_missing_chrome_processes',
303    columns=[
304        C('upid', CppUint32()),
305        C('reliable_from', CppOptional(CppInt64())),
306    ],
307    tabledoc=TableDoc(
308        doc='''
309          Experimental table, subject to arbitrary breaking changes.
310        ''',
311        group='Misc',
312        columns={
313            'upid': '''''',
314            'reliable_from': ''''''
315        }))
316
317CPU_TABLE = Table(
318    python_module=__file__,
319    class_name='CpuTable',
320    sql_name='cpu',
321    columns=[
322        C('cluster_id', CppUint32()),
323        C('processor', CppString()),
324    ],
325    tabledoc=TableDoc(
326        doc='''
327          Contains information of processes seen during the trace
328        ''',
329        group='Misc',
330        columns={
331            'cluster_id':
332                '''the cluster id is shared by CPUs in
333the same cluster''',
334            'processor':
335                '''a string describing this core'''
336        }))
337
338CPU_FREQ_TABLE = Table(
339    python_module=__file__,
340    class_name='CpuFreqTable',
341    sql_name='cpu_freq',
342    columns=[
343        C('cpu_id', CppTableId(CPU_TABLE)),
344        C('freq', CppUint32()),
345    ],
346    tabledoc=TableDoc(
347        doc='''''', group='Misc', columns={
348            'cpu_id': '''''',
349            'freq': ''''''
350        }))
351
352CLOCK_SNAPSHOT_TABLE = Table(
353    python_module=__file__,
354    class_name='ClockSnapshotTable',
355    sql_name='clock_snapshot',
356    columns=[
357        C('ts', CppInt64()),
358        C('clock_id', CppInt64()),
359        C('clock_name', CppOptional(CppString())),
360        C('clock_value', CppInt64()),
361        C('snapshot_id', CppUint32()),
362    ],
363    tabledoc=TableDoc(
364        doc='''
365          Contains all the mapping between clock snapshots and trace time.
366
367NOTE: this table is not sorted by timestamp; this is why we omit the
368sorted flag on the ts column.
369        ''',
370        group='Misc',
371        columns={
372            'ts':
373                '''timestamp of the snapshot in trace time.''',
374            'clock_id':
375                '''id of the clock (corresponds to the id in the trace).''',
376            'clock_name':
377                '''the name of the clock for builtin clocks or null
378otherwise.''',
379            'clock_value':
380                '''timestamp of the snapshot in clock time.''',
381            'snapshot_id':
382                '''the index of this snapshot (only useful for debugging)'''
383        }))
384
385# Keep this list sorted.
386ALL_TABLES = [
387    ARG_TABLE,
388    CLOCK_SNAPSHOT_TABLE,
389    CPU_FREQ_TABLE,
390    CPU_TABLE,
391    EXP_MISSING_CHROME_PROC_TABLE,
392    FILEDESCRIPTOR_TABLE,
393    METADATA_TABLE,
394    PROCESS_TABLE,
395    RAW_TABLE,
396    THREAD_TABLE,
397    FTRACE_EVENT_TABLE,
398]
399