v8
10.1.124 (node 18.2.0)
V8 is Google's open source JavaScript engine
v8-metrics.h
Go to the documentation of this file.
1
// Copyright 2020 the V8 project authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#
ifndef
V8_METRICS_H_
6
#
define
V8_METRICS_H_
7
8
#
include
<
stddef
.
h
>
9
#
include
<
stdint
.
h
>
10
11
#
include
<
vector
>
12
13
#
include
"v8-internal.h"
// NOLINT(build/include_directory)
14
#
include
"v8-local-handle.h"
// NOLINT(build/include_directory)
15
16
namespace
v8
{
17
18
class
Context
;
19
class
Isolate
;
20
21
namespace
metrics
{
22
23
struct
GarbageCollectionPhases
{
24
int64_t
total_wall_clock_duration_in_us
= -1;
25
int64_t
compact_wall_clock_duration_in_us
= -1;
26
int64_t
mark_wall_clock_duration_in_us
= -1;
27
int64_t
sweep_wall_clock_duration_in_us
= -1;
28
int64_t
weak_wall_clock_duration_in_us
= -1;
29
};
30
31
struct
GarbageCollectionSizes
{
32
int64_t
bytes_before
= -1;
33
int64_t
bytes_after
= -1;
34
int64_t
bytes_freed
= -1;
35
};
36
37
struct
GarbageCollectionFullCycle
{
38
int
reason
= -1;
39
GarbageCollectionPhases
total
;
40
GarbageCollectionPhases
total_cpp
;
41
GarbageCollectionPhases
main_thread
;
42
GarbageCollectionPhases
main_thread_cpp
;
43
GarbageCollectionPhases
main_thread_atomic
;
44
GarbageCollectionPhases
main_thread_atomic_cpp
;
45
GarbageCollectionPhases
main_thread_incremental
;
46
GarbageCollectionPhases
main_thread_incremental_cpp
;
47
GarbageCollectionSizes
objects
;
48
GarbageCollectionSizes
objects_cpp
;
49
GarbageCollectionSizes
memory
;
50
GarbageCollectionSizes
memory_cpp
;
51
double
collection_rate_in_percent
= -1.0;
52
double
collection_rate_cpp_in_percent
= -1.0;
53
double
efficiency_in_bytes_per_us
= -1.0;
54
double
efficiency_cpp_in_bytes_per_us
= -1.0;
55
double
main_thread_efficiency_in_bytes_per_us
= -1.0;
56
double
main_thread_efficiency_cpp_in_bytes_per_us
= -1.0;
57
};
58
59
struct
GarbageCollectionFullMainThreadIncrementalMark
{
60
int64_t
wall_clock_duration_in_us
= -1;
61
int64_t
cpp_wall_clock_duration_in_us
= -1;
62
};
63
64
struct
GarbageCollectionFullMainThreadBatchedIncrementalMark
{
65
std::vector<
GarbageCollectionFullMainThreadIncrementalMark
>
events
;
66
};
67
68
struct
GarbageCollectionFullMainThreadIncrementalSweep
{
69
int64_t
wall_clock_duration_in_us
= -1;
70
int64_t
cpp_wall_clock_duration_in_us
= -1;
71
};
72
73
struct
GarbageCollectionFullMainThreadBatchedIncrementalSweep
{
74
std::vector<
GarbageCollectionFullMainThreadIncrementalSweep
>
events
;
75
};
76
77
struct
GarbageCollectionYoungCycle
{
78
int
reason
= -1;
79
int64_t
total_wall_clock_duration_in_us
= -1;
80
int64_t
main_thread_wall_clock_duration_in_us
= -1;
81
double
collection_rate_in_percent
;
82
double
efficiency_in_bytes_per_us
;
83
double
main_thread_efficiency_in_bytes_per_us
;
84
};
85
86
struct
WasmModuleDecoded
{
87
bool
async
=
false
;
88
bool
streamed
=
false
;
89
bool
success
=
false
;
90
size_t
module_size_in_bytes
= 0;
91
size_t
function_count
= 0;
92
int64_t
wall_clock_duration_in_us
= -1;
93
int64_t
cpu_duration_in_us
= -1;
94
};
95
96
struct
WasmModuleCompiled
{
97
bool
async
=
false
;
98
bool
streamed
=
false
;
99
bool
cached
=
false
;
100
bool
deserialized
=
false
;
101
bool
lazy
=
false
;
102
bool
success
=
false
;
103
size_t
code_size_in_bytes
= 0;
104
size_t
liftoff_bailout_count
= 0;
105
int64_t
wall_clock_duration_in_us
= -1;
106
int64_t
cpu_duration_in_us
= -1;
107
};
108
109
struct
WasmModuleInstantiated
{
110
bool
async
=
false
;
111
bool
success
=
false
;
112
size_t
imported_function_count
= 0;
113
int64_t
wall_clock_duration_in_us
= -1;
114
};
115
116
struct
WasmModuleTieredUp
{
117
bool
lazy
=
false
;
118
size_t
code_size_in_bytes
= 0;
119
int64_t
wall_clock_duration_in_us
= -1;
120
int64_t
cpu_duration_in_us
= -1;
121
};
122
123
struct
WasmModulesPerIsolate
{
124
size_t
count
= 0;
125
};
126
127
#
define
V8_MAIN_THREAD_METRICS_EVENTS
(
V
)
128
V
(
GarbageCollectionFullCycle
)
129
V
(
GarbageCollectionFullMainThreadIncrementalMark
)
130
V
(
GarbageCollectionFullMainThreadBatchedIncrementalMark
)
131
V
(
GarbageCollectionFullMainThreadIncrementalSweep
)
132
V
(
GarbageCollectionFullMainThreadBatchedIncrementalSweep
)
133
V
(
GarbageCollectionYoungCycle
)
134
V
(
WasmModuleDecoded
)
135
V
(
WasmModuleCompiled
)
136
V
(
WasmModuleInstantiated
)
137
V
(
WasmModuleTieredUp
)
138
139
#
define
V8_THREAD_SAFE_METRICS_EVENTS
(
V
)
V
(
WasmModulesPerIsolate
)
140
141
/**
142
* This class serves as a base class for recording event-based metrics in V8.
143
* There a two kinds of metrics, those which are expected to be thread-safe and
144
* whose implementation is required to fulfill this requirement and those whose
145
* implementation does not have that requirement and only needs to be
146
* executable on the main thread. If such an event is triggered from a
147
* background thread, it will be delayed and executed by the foreground task
148
* runner.
149
*
150
* The thread-safe events are listed in the V8_THREAD_SAFE_METRICS_EVENTS
151
* macro above while the main thread event are listed in
152
* V8_MAIN_THREAD_METRICS_EVENTS above. For the former, a virtual method
153
* AddMainThreadEvent(const E& event, v8::Context::Token token) will be
154
* generated and for the latter AddThreadSafeEvent(const E& event).
155
*
156
* Thread-safe events are not allowed to access the context and therefore do
157
* not carry a context ID with them. These IDs can be generated using
158
* Recorder::GetContextId() and the ID will be valid throughout the lifetime
159
* of the isolate. It is not guaranteed that the ID will still resolve to
160
* a valid context using Recorder::GetContext() at the time the metric is
161
* recorded. In this case, an empty handle will be returned.
162
*
163
* The embedder is expected to call v8::Isolate::SetMetricsRecorder()
164
* providing its implementation and have the virtual methods overwritten
165
* for the events it cares about.
166
*/
167
class
V8_EXPORT
Recorder
{
168
public
:
169
// A unique identifier for a context in this Isolate.
170
// It is guaranteed to not be reused throughout the lifetime of the Isolate.
171
class
ContextId
{
172
public
:
173
ContextId
() : id_(kEmptyId) {}
174
175
bool
IsEmpty
()
const
{
return
id_ == kEmptyId; }
176
static
const
ContextId
Empty
() {
return
ContextId
{kEmptyId}; }
177
178
bool
operator
==(
const
ContextId
& other)
const
{
return
id_ == other.id_; }
179
bool
operator
!=(
const
ContextId
& other)
const
{
return
id_ != other.id_; }
180
181
private
:
182
friend
class
::
v8
::
Context
;
183
friend
class
::
v8
::
internal
::Isolate;
184
185
explicit
ContextId(uintptr_t id) : id_(id) {}
186
187
static
constexpr
uintptr_t kEmptyId = 0;
188
uintptr_t id_;
189
};
190
191
virtual
~
Recorder
() =
default
;
192
193
#
define
ADD_MAIN_THREAD_EVENT
(
E
)
194
virtual
void
AddMainThreadEvent
(
const
E
&
event
,
ContextId
context_id
)
{
}
195
V8_MAIN_THREAD_METRICS_EVENTS
(
ADD_MAIN_THREAD_EVENT
)
196
#
undef
ADD_MAIN_THREAD_EVENT
197
198
#
define
ADD_THREAD_SAFE_EVENT
(
E
)
199
virtual
void
AddThreadSafeEvent
(
const
E
&
event
)
{
}
200
V8_THREAD_SAFE_METRICS_EVENTS
(
ADD_THREAD_SAFE_EVENT
)
201
#
undef
ADD_THREAD_SAFE_EVENT
202
203
virtual
void
NotifyIsolateDisposal
() {}
204
205
// Return the context with the given id or an empty handle if the context
206
// was already garbage collected.
207
static
MaybeLocal
<
Context
>
GetContext
(
Isolate
* isolate,
ContextId
id);
208
// Return the unique id corresponding to the given context.
209
static
ContextId
GetContextId
(
Local
<
Context
> context);
210
};
211
212
/**
213
* Experimental API intended for the LongTasks UKM (crbug.com/1173527).
214
* The Reset() method should be called at the start of a potential
215
* long task. The Get() method returns durations of V8 work that
216
* happened during the task.
217
*
218
* This API is experimental and may be removed/changed in the future.
219
*/
220
struct
V8_EXPORT
LongTaskStats
{
221
/**
222
* Resets durations of V8 work for the new task.
223
*/
224
V8_INLINE
static
void
Reset
(
Isolate
* isolate) {
225
v8
::
internal
::
Internals
::
IncrementLongTasksStatsCounter
(
isolate
)
;
226
}
227
228
/**
229
* Returns durations of V8 work that happened since the last Reset().
230
*/
231
static
LongTaskStats
Get
(
Isolate
* isolate);
232
233
int64_t
gc_full_atomic_wall_clock_duration_us
= 0;
234
int64_t
gc_full_incremental_wall_clock_duration_us
= 0;
235
int64_t
gc_young_wall_clock_duration_us
= 0;
236
// Only collected with --slow-histograms
237
int64_t
v8_execute_us
= 0;
238
};
239
240
}
// namespace metrics
241
}
// namespace v8
242
243
#
endif
// V8_METRICS_H_
include
v8-metrics.h
Generated on Tue May 24 2022 19:29:00 for v8 by
1.9.1