• 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 UINT,
40  -- Process the isolate was created in.
41  upid UINT,
42  -- Internal id used by the v8 engine. Unique in a process.
43  internal_isolate_id UINT,
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
70  __intrinsic_v8_isolate;
71
72
73-- Represents a script that was compiled to generate code. Some V8 code is
74-- generated out of scripts and will reference a V8Script other types of code
75-- will not (e.g. builtins).
76CREATE PERFETTO VIEW v8_js_script (
77  -- Unique V8 JS script id.
78  v8_js_script_id UINT,
79  -- V8 isolate this script belongs to (joinable with
80  -- `v8_isolate.v8_isolate_id`).
81  v8_isolate_id UINT,
82  -- Script id used by the V8 engine.
83  internal_script_id UINT,
84  -- Script type.
85  script_type STRING,
86  -- Script name.
87  name STRING,
88  -- Actual contents of the script.
89  source STRING
90) AS
91SELECT
92  id AS v8_js_script_id,
93  v8_isolate_id,
94  internal_script_id,
95  script_type,
96  name,
97  source
98FROM
99  __intrinsic_v8_js_script;
100
101
102-- Represents one WASM script.
103CREATE PERFETTO VIEW v8_wasm_script (
104  -- Unique V8 WASM script id.
105  v8_wasm_script_id UINT,
106  -- V8 Isolate this script belongs to (joinable with
107  -- `v8_isolate.v8_isolate_id`).
108  v8_isolate_id UINT,
109  -- Script id used by the V8 engine.
110  internal_script_id UINT,
111  -- URL of the source.
112  url STRING,
113  -- Actual contents of the script.
114  source STRING
115) AS
116SELECT
117  id AS v8_wasm_script_id,
118  v8_isolate_id,
119  internal_script_id,
120  url,
121  source
122FROM
123  __intrinsic_v8_wasm_script;
124
125
126-- Represents a v8 Javascript function.
127CREATE PERFETTO VIEW v8_js_function (
128  -- Unique V8 JS function id.
129  v8_js_function_id UINT,
130  -- Function name.
131  name STRING,
132  -- Script where the function is defined (joinable with
133  -- `v8_js_script.v8_js_script_id`).
134  v8_js_script_id UINT,
135  -- Whether this function represents the top level script.
136  is_toplevel BOOL,
137  -- Function kind (e.g. regular function or constructor).
138  kind STRING,
139  -- Line in script where function is defined. Starts at 1.
140  line UINT,
141  -- Column in script where function is defined. Starts at 1.
142  col UINT
143) AS
144SELECT
145  id AS v8_js_function_id,
146  name,
147  v8_js_script_id,
148  is_toplevel,
149  kind,
150  line,
151  col
152FROM
153  __intrinsic_v8_js_function;
154
155
156-- Represents a v8 code snippet for a Javascript function. A given function can
157-- have multiple code snippets (e.g. for different compilation tiers, or as the
158-- function moves around the heap).
159-- TODO(carlscab): Make public once `_jit_code` is public too
160CREATE PERFETTO VIEW _v8_js_code(
161  -- Unique id
162  id UINT,
163  -- Associated jit code. Set for all tiers except IGNITION. Joinable with
164  -- `_jit_code.jit_code_id`.
165  jit_code_id UINT,
166  -- JS function for this snippet. Joinable with
167  -- `v8_js_function.v8_js_function_id`.
168  v8_js_function_id UINT,
169  -- Compilation tier
170  tier STRING,
171  -- V8 VM bytecode. Set only for the IGNITION tier.
172  bytecode BYTES
173) AS
174SELECT
175  id,
176  jit_code_id,
177  v8_js_function_id,
178  tier,
179  base64_decode(bytecode_base64) AS bytecode
180FROM
181  __intrinsic_v8_js_code;
182
183
184-- Represents a v8 code snippet for a v8 internal function.
185-- TODO(carlscab): Make public once `_jit_code` is public too
186CREATE PERFETTO VIEW _v8_internal_code(
187  -- Unique id
188  id UINT,
189  -- Associated jit code. Joinable with `_jit_code.jit_code_id`.
190  jit_code_id UINT,
191  -- V8 Isolate this code was created in. Joinable with
192  -- `v8_isolate.v8_isolate_id`.
193  v8_isolate_id UINT,
194  -- Function name.
195  function_name STRING,
196  -- Type of internal code.
197  code_type STRING
198) AS
199SELECT
200  id,
201  jit_code_id,
202  v8_isolate_id,
203  function_name,
204  code_type
205FROM
206  __intrinsic_v8_internal_code;
207
208-- Represents the code associated to a WASM function.
209-- TODO(carlscab): Make public once `_jit_code` is public too
210CREATE PERFETTO VIEW _v8_wasm_code(
211  -- Unique id
212  id UINT,
213  -- Associated jit code. Joinable with `_jit_code.jit_code_id`.
214  jit_code_id UINT,
215  -- V8 Isolate this code was created in. Joinable with
216  -- `v8_isolate.v8_isolate_id`.
217  v8_isolate_id UINT,
218  -- Script where the function is defined. Joinable with
219  -- `v8_wasm_script.v8_wasm_script_id`.
220  v8_wasm_script_id UINT,
221  -- Function name.
222  function_name STRING,
223  -- Compilation tier.
224  tier STRING,
225  -- Offset into the WASM module where the function starts.
226  code_offset_in_module INT
227 ) AS
228SELECT
229  id,
230  jit_code_id,
231  v8_isolate_id,
232  v8_wasm_script_id,
233  function_name,
234  tier,
235  code_offset_in_module
236FROM
237  __intrinsic_v8_wasm_code;
238
239-- Represents the code associated to a regular expression
240-- TODO(carlscab): Make public once `_jit_code` is public too
241CREATE PERFETTO VIEW _v8_regexp_code(
242  -- Unique id
243  id UINT,
244  -- Associated jit code. Joinable with `_jit_code.jit_code_id`.
245  jit_code_id UINT,
246  -- V8 Isolate this code was created in. Joinable with
247  -- `v8_isolate.v8_isolate_id`.
248  v8_isolate_id UINT,
249  -- The pattern the this regular expression was compiled from.
250  pattern STRING
251) AS
252SELECT
253  id,
254  jit_code_id,
255  v8_isolate_id,
256  pattern
257FROM
258  __intrinsic_v8_regexp_code;
259