• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--
2-- Copyright 2024 The Android Open Source Project
3--
4-- Licensed under the Apache License, Version 2.0 (the "License");
5-- you may not use this file except in compliance with the License.
6-- You may obtain a copy of the License at
7--
8--     https://www.apache.org/licenses/LICENSE-2.0
9--
10-- Unless required by applicable law or agreed to in writing, software
11-- distributed under the License is distributed on an "AS IS" BASIS,
12-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-- See the License for the specific language governing permissions and
14-- limitations under the License.
15
16-- These are the tables for the V8 jit data source
17-- (protos/perfetto/trace/chrome/v8.proto).
18--
19-- All events are associated to a V8 isolate instance. There can be multiple
20-- instances associated to a given thread, although this is rare.
21--
22-- Generated code in V8 is allocated in the V8 heap (in a special executeable
23-- section), this means that code can be garbage collected (when no longer used)
24-- or can be moved around (e.g. during heap compactation). This means that a
25-- given callsite might correspond to function `A` at one point in time and to
26-- function `B` later on.
27-- In addition V8 code has various levels of optimization, so a function might
28-- have multiple associated code snippets.
29--
30-- V8 does not track code deletion, so we have to indirectly infer it by
31-- detecting code overlaps, if a newer code creation event overlaps with older
32-- code we need to asume that the old code was deleted. Code moves are logged,
33-- and there is an event to track those.
34
35-- A V8 Isolate instance. A V8 Isolate represents an isolated instance of the V8
36-- engine.
37CREATE PERFETTO VIEW v8_isolate (
38  -- Unique V8 isolate id.
39  v8_isolate_id LONG,
40  -- Process the isolate was created in.
41  upid JOINID(process.id),
42  -- Internal id used by the v8 engine. Unique in a process.
43  internal_isolate_id LONG,
44  -- Absolute start address of the embedded code blob.
45  embedded_blob_code_start_address LONG,
46  -- Size in bytes of the embedded code blob.
47  embedded_blob_code_size LONG,
48  -- Base address of the code range if the isolate defines one.
49  code_range_base_address LONG,
50  -- Size of a code range if the isolate defines one.
51  code_range_size LONG,
52  -- Whether the code range for this Isolate is shared with others in the same
53  -- process. There is at max one such shared code range per process.
54  shared_code_range LONG,
55  -- Used when short builtin calls are enabled, where embedded builtins are
56  -- copied into the CodeRange so calls can be nearer.
57  embedded_blob_code_copy_start_address LONG
58) AS
59SELECT
60  id AS v8_isolate_id,
61  upid,
62  internal_isolate_id,
63  embedded_blob_code_start_address,
64  embedded_blob_code_size,
65  code_range_base_address,
66  code_range_size,
67  shared_code_range,
68  embedded_blob_code_copy_start_address
69FROM __intrinsic_v8_isolate;
70
71-- Represents a script that was compiled to generate code. Some V8 code is
72-- generated out of scripts and will reference a V8Script other types of code
73-- will not (e.g. builtins).
74CREATE PERFETTO VIEW v8_js_script (
75  -- Unique V8 JS script id.
76  v8_js_script_id LONG,
77  -- V8 isolate this script belongs to (joinable with
78  -- `v8_isolate.v8_isolate_id`).
79  v8_isolate_id LONG,
80  -- Script id used by the V8 engine.
81  internal_script_id LONG,
82  -- Script type.
83  script_type STRING,
84  -- Script name.
85  name STRING,
86  -- Actual contents of the script.
87  source STRING
88) AS
89SELECT
90  id AS v8_js_script_id,
91  v8_isolate_id,
92  internal_script_id,
93  script_type,
94  name,
95  source
96FROM __intrinsic_v8_js_script;
97
98-- Represents one WASM script.
99CREATE PERFETTO VIEW v8_wasm_script (
100  -- Unique V8 WASM script id.
101  v8_wasm_script_id LONG,
102  -- V8 Isolate this script belongs to (joinable with
103  -- `v8_isolate.v8_isolate_id`).
104  v8_isolate_id LONG,
105  -- Script id used by the V8 engine.
106  internal_script_id LONG,
107  -- URL of the source.
108  url STRING,
109  -- Actual contents of the script.
110  source STRING
111) AS
112SELECT
113  id AS v8_wasm_script_id,
114  v8_isolate_id,
115  internal_script_id,
116  url,
117  source
118FROM __intrinsic_v8_wasm_script;
119
120-- Represents a v8 Javascript function.
121CREATE PERFETTO VIEW v8_js_function (
122  -- Unique V8 JS function id.
123  v8_js_function_id LONG,
124  -- Function name.
125  name STRING,
126  -- Script where the function is defined (joinable with
127  -- `v8_js_script.v8_js_script_id`).
128  v8_js_script_id LONG,
129  -- Whether this function represents the top level script.
130  is_toplevel BOOL,
131  -- Function kind (e.g. regular function or constructor).
132  kind STRING,
133  -- Line in script where function is defined. Starts at 1.
134  line LONG,
135  -- Column in script where function is defined. Starts at 1.
136  col LONG
137) AS
138SELECT
139  id AS v8_js_function_id,
140  name,
141  v8_js_script_id,
142  is_toplevel,
143  kind,
144  line,
145  col
146FROM __intrinsic_v8_js_function;
147
148-- Represents a v8 code snippet for a Javascript function. A given function can
149-- have multiple code snippets (e.g. for different compilation tiers, or as the
150-- function moves around the heap).
151-- TODO(carlscab): Make public once `_jit_code` is public too
152CREATE PERFETTO VIEW _v8_js_code (
153  -- Unique id
154  id LONG,
155  -- Associated jit code. Set for all tiers except IGNITION. Joinable with
156  -- `_jit_code.jit_code_id`.
157  jit_code_id LONG,
158  -- JS function for this snippet. Joinable with
159  -- `v8_js_function.v8_js_function_id`.
160  v8_js_function_id LONG,
161  -- Compilation tier
162  tier STRING,
163  -- V8 VM bytecode. Set only for the IGNITION tier.
164  bytecode BYTES
165) AS
166SELECT
167  id,
168  jit_code_id,
169  v8_js_function_id,
170  tier,
171  base64_decode(bytecode_base64) AS bytecode
172FROM __intrinsic_v8_js_code;
173
174-- Represents a v8 code snippet for a v8 internal function.
175-- TODO(carlscab): Make public once `_jit_code` is public too
176CREATE PERFETTO VIEW _v8_internal_code (
177  -- Unique id
178  id LONG,
179  -- Associated jit code. Joinable with `_jit_code.jit_code_id`.
180  jit_code_id LONG,
181  -- V8 Isolate this code was created in. Joinable with
182  -- `v8_isolate.v8_isolate_id`.
183  v8_isolate_id LONG,
184  -- Function name.
185  function_name STRING,
186  -- Type of internal code.
187  code_type STRING
188) AS
189SELECT
190  id,
191  jit_code_id,
192  v8_isolate_id,
193  function_name,
194  code_type
195FROM __intrinsic_v8_internal_code;
196
197-- Represents the code associated to a WASM function.
198-- TODO(carlscab): Make public once `_jit_code` is public too
199CREATE PERFETTO VIEW _v8_wasm_code (
200  -- Unique id
201  id LONG,
202  -- Associated jit code. Joinable with `_jit_code.jit_code_id`.
203  jit_code_id LONG,
204  -- V8 Isolate this code was created in. Joinable with
205  -- `v8_isolate.v8_isolate_id`.
206  v8_isolate_id LONG,
207  -- Script where the function is defined. Joinable with
208  -- `v8_wasm_script.v8_wasm_script_id`.
209  v8_wasm_script_id LONG,
210  -- Function name.
211  function_name STRING,
212  -- Compilation tier.
213  tier STRING,
214  -- Offset into the WASM module where the function starts.
215  code_offset_in_module LONG
216) AS
217SELECT
218  id,
219  jit_code_id,
220  v8_isolate_id,
221  v8_wasm_script_id,
222  function_name,
223  tier,
224  code_offset_in_module
225FROM __intrinsic_v8_wasm_code;
226
227-- Represents the code associated to a regular expression
228-- TODO(carlscab): Make public once `_jit_code` is public too
229CREATE PERFETTO VIEW _v8_regexp_code (
230  -- Unique id
231  id LONG,
232  -- Associated jit code. Joinable with `_jit_code.jit_code_id`.
233  jit_code_id LONG,
234  -- V8 Isolate this code was created in. Joinable with
235  -- `v8_isolate.v8_isolate_id`.
236  v8_isolate_id LONG,
237  -- The pattern the this regular expression was compiled from.
238  pattern STRING
239) AS
240SELECT
241  id,
242  jit_code_id,
243  v8_isolate_id,
244  pattern
245FROM __intrinsic_v8_regexp_code;
246