v8 12.4.254 (node 22.4.1)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
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#include "v8config.h" // NOLINT(build/include_directory)
16
17namespace v8 {
18
19class Context;
20class Isolate;
21
22namespace metrics {
23
30};
31
33 int64_t bytes_before = -1;
34 int64_t bytes_after = -1;
35 int64_t bytes_freed = -1;
36};
37
39 int reason = -1;
59};
60
64};
65
69};
70
71template <typename EventType>
73 std::vector<EventType> events;
74};
75
82
84 int reason = -1;
90#if defined(CPPGC_YOUNG_GENERATION)
92 GarbageCollectionSizes objects_cpp;
93 GarbageCollectionSizes memory_cpp;
94 double collection_rate_cpp_in_percent = -1.0;
95 double efficiency_cpp_in_bytes_per_us = -1.0;
96 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
97#endif // defined(CPPGC_YOUNG_GENERATION)
98};
99
101 WasmModuleDecoded() = default;
105 : async(async),
111
112 bool async = false;
113 bool streamed = false;
114 bool success = false;
116 size_t function_count = 0;
118};
119
122
124 bool lazy, bool success, size_t code_size_in_bytes,
127 : async(async),
129 cached(cached),
131 lazy(lazy),
136
137 bool async = false;
138 bool streamed = false;
139 bool cached = false;
140 bool deserialized = false;
141 bool lazy = false;
142 bool success = false;
146};
147
149 bool async = false;
150 bool success = false;
153};
154
156 size_t count = 0;
157};
158
173 public:
174 // A unique identifier for a context in this Isolate.
175 // It is guaranteed to not be reused throughout the lifetime of the Isolate.
176 class ContextId {
177 public:
178 ContextId() : id_(kEmptyId) {}
179
180 bool IsEmpty() const { return id_ == kEmptyId; }
181 static const ContextId Empty() { return ContextId{kEmptyId}; }
182
183 bool operator==(const ContextId& other) const { return id_ == other.id_; }
184 bool operator!=(const ContextId& other) const { return id_ != other.id_; }
185
186 private:
187 friend class ::v8::Context;
188 friend class ::v8::internal::Isolate;
189
190 explicit ContextId(uintptr_t id) : id_(id) {}
191
192 static constexpr uintptr_t kEmptyId = 0;
193 uintptr_t id_;
194 };
195
196 virtual ~Recorder() = default;
197
198 // Main thread events. Those are only triggered on the main thread, and hence
199 // can access the context.
200#define ADD_MAIN_THREAD_EVENT(E) \
201 virtual void AddMainThreadEvent(const E&, ContextId) {}
202 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullCycle)
203 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalMark)
204 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalMark)
205 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalSweep)
206 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalSweep)
207 ADD_MAIN_THREAD_EVENT(GarbageCollectionYoungCycle)
208 ADD_MAIN_THREAD_EVENT(WasmModuleDecoded)
209 ADD_MAIN_THREAD_EVENT(WasmModuleCompiled)
210 ADD_MAIN_THREAD_EVENT(WasmModuleInstantiated)
211#undef ADD_MAIN_THREAD_EVENT
212
213 // Thread-safe events are not allowed to access the context and therefore do
214 // not carry a context ID with them. These IDs can be generated using
215 // Recorder::GetContextId() and the ID will be valid throughout the lifetime
216 // of the isolate. It is not guaranteed that the ID will still resolve to
217 // a valid context using Recorder::GetContext() at the time the metric is
218 // recorded. In this case, an empty handle will be returned.
219#define ADD_THREAD_SAFE_EVENT(E) \
220 virtual void AddThreadSafeEvent(const E&) {}
221 ADD_THREAD_SAFE_EVENT(WasmModulesPerIsolate)
222#undef ADD_THREAD_SAFE_EVENT
223
224 virtual void NotifyIsolateDisposal() {}
225
226 // Return the context with the given id or an empty handle if the context
227 // was already garbage collected.
229 // Return the unique id corresponding to the given context.
231};
232
245 V8_INLINE static void Reset(Isolate* isolate) {
247 }
248
252 static LongTaskStats Get(Isolate* isolate);
253
254 int64_t gc_full_atomic_wall_clock_duration_us = 0;
255 int64_t gc_full_incremental_wall_clock_duration_us = 0;
256 int64_t gc_young_wall_clock_duration_us = 0;
257 // Only collected with --slow-histograms
258 int64_t v8_execute_us = 0;
259};
260
261} // namespace metrics
262} // namespace v8
263
264#endif // V8_METRICS_H_
static V8_INLINE void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
static const ContextId Empty()
Definition v8-metrics.h:181
bool operator!=(const ContextId &other) const
Definition v8-metrics.h:184
bool operator==(const ContextId &other) const
Definition v8-metrics.h:183
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
static ContextId GetContextId(Local< Context > context)
virtual void NotifyIsolateDisposal()
Definition v8-metrics.h:224
int64_t incremental_marking_start_stop_wall_clock_duration_in_us
Definition v8-metrics.h:58
GarbageCollectionPhases main_thread_incremental
Definition v8-metrics.h:46
GarbageCollectionPhases main_thread_atomic_cpp
Definition v8-metrics.h:45
GarbageCollectionPhases main_thread
Definition v8-metrics.h:42
GarbageCollectionPhases main_thread_incremental_cpp
Definition v8-metrics.h:47
GarbageCollectionPhases main_thread_cpp
Definition v8-metrics.h:43
GarbageCollectionSizes memory_cpp
Definition v8-metrics.h:51
GarbageCollectionPhases total_cpp
Definition v8-metrics.h:41
GarbageCollectionPhases main_thread_atomic
Definition v8-metrics.h:44
GarbageCollectionSizes objects_cpp
Definition v8-metrics.h:49
static V8_INLINE void Reset(Isolate *isolate)
Definition v8-metrics.h:245
static LongTaskStats Get(Isolate *isolate)
WasmModuleCompiled(bool async, bool streamed, bool cached, bool deserialized, bool lazy, bool success, size_t code_size_in_bytes, size_t liftoff_bailout_count, int64_t wall_clock_duration_in_us)
Definition v8-metrics.h:123
WasmModuleDecoded(bool async, bool streamed, bool success, size_t module_size_in_bytes, size_t function_count, int64_t wall_clock_duration_in_us)
Definition v8-metrics.h:102
#define ADD_MAIN_THREAD_EVENT(E)
Definition v8-metrics.h:200
#define ADD_THREAD_SAFE_EVENT(E)
Definition v8-metrics.h:219
#define V8_EXPORT
Definition v8config.h:753
#define V8_INLINE
Definition v8config.h:477