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