xref: /aosp_15_r20/external/perfetto/src/trace_processor/tables/v8_tables.py (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1# Copyright (C) 2024 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 related to the v8 (Javasrcript Engine) Datasource.
15
16These tables are WIP, the schema is not stable and you should not rely on them
17for any serious business just yet""
18"""
19
20from python.generators.trace_processor_table.public import Alias
21from python.generators.trace_processor_table.public import Column as C
22from python.generators.trace_processor_table.public import ColumnDoc
23from python.generators.trace_processor_table.public import CppInt32
24from python.generators.trace_processor_table.public import CppInt64
25from python.generators.trace_processor_table.public import CppOptional
26from python.generators.trace_processor_table.public import CppString
27from python.generators.trace_processor_table.public import CppTableId
28from python.generators.trace_processor_table.public import CppUint32
29from python.generators.trace_processor_table.public import CppUint32 as CppBool
30from python.generators.trace_processor_table.public import Table
31from python.generators.trace_processor_table.public import TableDoc
32from python.generators.trace_processor_table.public import WrappingSqlView
33
34from .jit_tables import JIT_CODE_TABLE
35
36V8_ISOLATE = Table(
37    python_module=__file__,
38    class_name='V8IsolateTable',
39    sql_name='__intrinsic_v8_isolate',
40    columns=[
41        C('upid', CppUint32()),
42        C('internal_isolate_id', CppInt32()),
43        C('embedded_blob_code_start_address', CppInt64()),
44        C('embedded_blob_code_size', CppInt64()),
45        C('code_range_base_address', CppOptional(CppInt64())),
46        C('code_range_size', CppOptional(CppInt64())),
47        C('shared_code_range', CppOptional(CppBool())),
48        C('embedded_blob_code_copy_start_address', CppOptional(CppInt64())),
49    ],
50    tabledoc=TableDoc(
51        doc='Represents one Isolate instance',
52        group='v8',
53        columns={
54            'upid':
55                'Process the isolate was created in.',
56            'internal_isolate_id':
57                'Internal id used by the v8 engine. Unique in a process.',
58            'embedded_blob_code_start_address':
59                'Absolute start address of the embedded code blob.',
60            'embedded_blob_code_size':
61                'Size in bytes of the embedded code blob.',
62            'code_range_base_address':
63                'If this Isolate defines a CodeRange its base address is stored'
64                ' here',
65            'code_range_size':
66                'If this Isolate defines a CodeRange its size is stored here',
67            'shared_code_range':
68                'Whether the code range for this Isolate is shared with others'
69                ' in the same process. There is at max one such shared code'
70                ' range per process.',
71            'embedded_blob_code_copy_start_address':
72                'Used when short builtin calls are enabled, where embedded'
73                ' builtins are copied into the CodeRange so calls can be'
74                ' nearer.',
75        },
76    ),
77)
78
79V8_JS_SCRIPT = Table(
80    python_module=__file__,
81    class_name='V8JsScriptTable',
82    sql_name='__intrinsic_v8_js_script',
83    columns=[
84        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
85        C('internal_script_id', CppInt32()),
86        C('script_type', CppString()),
87        C('name', CppString()),
88        C('source', CppOptional(CppString())),
89    ],
90    tabledoc=TableDoc(
91        doc='Represents one Javascript script',
92        group='v8',
93        columns={
94            'v8_isolate_id': 'V8 Isolate',
95            'internal_script_id': 'Script id used by the V8 engine',
96            'script_type': '',
97            'name': '',
98            'source': 'Actual contents of the script.',
99        },
100    ),
101)
102
103V8_WASM_SCRIPT = Table(
104    python_module=__file__,
105    class_name='V8WasmScriptTable',
106    sql_name='__intrinsic_v8_wasm_script',
107    columns=[
108        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
109        C('internal_script_id', CppInt32()),
110        C('url', CppString()),
111        C('source', CppOptional(CppString())),
112    ],
113    tabledoc=TableDoc(
114        doc='Represents one WASM script',
115        group='v8',
116        columns={
117            'v8_isolate_id': 'V8 Isolate',
118            'internal_script_id': 'Script id used by the V8 engine',
119            'url': 'URL of the source',
120            'source': 'Actual contents of the script.',
121        },
122    ),
123)
124
125V8_JS_FUNCTION = Table(
126    python_module=__file__,
127    class_name='V8JsFunctionTable',
128    sql_name='__intrinsic_v8_js_function',
129    columns=[
130        C('name', CppString()),
131        C('v8_js_script_id', CppTableId(V8_JS_SCRIPT)),
132        C('is_toplevel', CppBool()),
133        C('kind', CppString()),
134        C('line', CppOptional(CppUint32())),
135        C('col', CppOptional(CppUint32())),
136    ],
137    tabledoc=TableDoc(
138        doc='Represents a v8 Javascript function',
139        group='v8',
140        columns={
141            'name':
142                '',
143            'v8_js_script_id':
144                ColumnDoc(
145                    doc='Script where the function is defined.',
146                    joinable='v8_js_script.id',
147                ),
148            'is_toplevel':
149                'Whether this function represents the top level script',
150            'kind':
151                'Function kind (e.g. regular function or constructor)',
152            'line':
153                'Line in script where function is defined. Starts at 1',
154            'col':
155                'Column in script where function is defined. Starts at 1',
156        },
157    ),
158)
159
160V8_JS_CODE = Table(
161    python_module=__file__,
162    class_name='V8JsCodeTable',
163    sql_name='__intrinsic_v8_js_code',
164    columns=[
165        C('jit_code_id', CppOptional(CppTableId(JIT_CODE_TABLE))),
166        C('v8_js_function_id', CppTableId(V8_JS_FUNCTION)),
167        C('tier', CppString()),
168        C('bytecode_base64', CppOptional(CppString())),
169    ],
170    tabledoc=TableDoc(
171        doc="""
172          Represents a v8 code snippet for a Javascript function. A given
173          function can have multiple code snippets (e.g. for different
174          compilation tiers, or as the function moves around the heap)
175        """,
176        group='v8',
177        columns={
178            'jit_code_id':
179                ColumnDoc(
180                    doc="""
181                  Set for all tiers except IGNITION.
182                    """,
183                    joinable='__intrinsic_jit_code.id',
184                ),
185            'v8_js_function_id':
186                ColumnDoc(
187                    doc='JS function for this snippet.',
188                    joinable='__intrinsic_v8_js_function.id',
189                ),
190            'tier':
191                'Compilation tier',
192            'bytecode_base64':
193                'Set only for the IGNITION tier (base64 encoded)',
194        },
195    ),
196)
197
198V8_INTERNAL_CODE = Table(
199    python_module=__file__,
200    class_name='V8InternalCodeTable',
201    sql_name='__intrinsic_v8_internal_code',
202    columns=[
203        C('jit_code_id', CppTableId(JIT_CODE_TABLE)),
204        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
205        C('function_name', CppString()),
206        C('code_type', CppString()),
207    ],
208    tabledoc=TableDoc(
209        doc="""
210          Represents a v8 code snippet for a v8 internal function.
211        """,
212        group='v8',
213        columns={
214            'jit_code_id':
215                ColumnDoc(
216                    doc='Associated JitCode.',
217                    joinable='__intrinsic_jit_code.id',
218                ),
219            'v8_isolate_id':
220                ColumnDoc(
221                    doc="""
222                  V8 Isolate this code was created in.
223                    """,
224                    joinable='__intrinsic_v8_isolate.id'),
225            'function_name':
226                'Function name.',
227            'code_type':
228                'Type of internal function (e.g. BYTECODE_HANDLER, BUILTIN)',
229        },
230    ),
231)
232
233V8_WASM_CODE = Table(
234    python_module=__file__,
235    class_name='V8WasmCodeTable',
236    sql_name='__intrinsic_v8_wasm_code',
237    columns=[
238        C('jit_code_id', CppTableId(JIT_CODE_TABLE)),
239        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
240        C('v8_wasm_script_id', CppTableId(V8_WASM_SCRIPT)),
241        C('function_name', CppString()),
242        C('tier', CppString()),
243        C('code_offset_in_module', CppInt32()),
244    ],
245    tabledoc=TableDoc(
246        doc="""
247          Represents the code associated to a WASM function
248        """,
249        group='v8',
250        columns={
251            'jit_code_id':
252                ColumnDoc(
253                    doc='Associated JitCode.',
254                    joinable='__intrinsic_jit_code.id',
255                ),
256            'v8_isolate_id':
257                ColumnDoc(
258                    doc="""
259                  V8 Isolate this code was created in.
260                    """,
261                    joinable='__intrinsic_v8_isolate.id'),
262            'v8_wasm_script_id':
263                ColumnDoc(
264                    doc="""
265                  Script where the function is defined.
266                    """,
267                    joinable='v8_wasm_script.id',
268                ),
269            'function_name':
270                'Function name.',
271            'tier':
272                'Compilation tier',
273            'code_offset_in_module':
274                """Offset into the WASM module where the function starts""",
275        },
276    ),
277)
278
279V8_REGEXP_CODE = Table(
280    python_module=__file__,
281    class_name='V8RegexpCodeTable',
282    sql_name='__intrinsic_v8_regexp_code',
283    columns=[
284        C('jit_code_id', CppTableId(JIT_CODE_TABLE)),
285        C('v8_isolate_id', CppTableId(V8_ISOLATE)),
286        C('pattern', CppString()),
287    ],
288    tabledoc=TableDoc(
289        doc="""
290          Represents the code associated to a regular expression
291        """,
292        group='v8',
293        columns={
294            'jit_code_id':
295                ColumnDoc(
296                    doc='Associated JitCode.',
297                    joinable='__intrinsic_jit_code.id',
298                ),
299            'v8_isolate_id':
300                ColumnDoc(
301                    doc="""
302                  V8 Isolate this code was created in.
303                    """,
304                    joinable='__intrinsic_v8_isolate.id'),
305            'pattern':
306                """The pattern the this regular expression was compiled from""",
307        },
308    ),
309)
310
311# Keep this list sorted.
312ALL_TABLES = [
313    V8_ISOLATE,
314    V8_JS_SCRIPT,
315    V8_WASM_SCRIPT,
316    V8_JS_FUNCTION,
317    V8_JS_CODE,
318    V8_INTERNAL_CODE,
319    V8_WASM_CODE,
320    V8_REGEXP_CODE,
321]
322