v8 11.3.244 (node 20.3.0)
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;
58};
59
63};
64
68};
69
70template <typename EventType>
72 std::vector<EventType> events;
73};
74
81
83 int reason = -1;
89#if defined(CPPGC_YOUNG_GENERATION)
91 GarbageCollectionSizes objects_cpp;
92 GarbageCollectionSizes memory_cpp;
93 double collection_rate_cpp_in_percent = -1.0;
94 double efficiency_cpp_in_bytes_per_us = -1.0;
95 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
96#endif // defined(CPPGC_YOUNG_GENERATION)
97};
98
100 WasmModuleDecoded() = default;
104 : async(async),
110
111 bool async = false;
112 bool streamed = false;
113 bool success = false;
115 size_t function_count = 0;
117};
118
121
123 bool lazy, bool success, size_t code_size_in_bytes,
126 : async(async),
128 cached(cached),
130 lazy(lazy),
135
136 bool async = false;
137 bool streamed = false;
138 bool cached = false;
139 bool deserialized = false;
140 bool lazy = false;
141 bool success = false;
145};
146
148 bool async = false;
149 bool success = false;
152};
153
155 size_t count = 0;
156};
157
172 public:
173 // A unique identifier for a context in this Isolate.
174 // It is guaranteed to not be reused throughout the lifetime of the Isolate.
175 class ContextId {
176 public:
177 ContextId() : id_(kEmptyId) {}
178
179 bool IsEmpty() const { return id_ == kEmptyId; }
180 static const ContextId Empty() { return ContextId{kEmptyId}; }
181
182 bool operator==(const ContextId& other) const { return id_ == other.id_; }
183 bool operator!=(const ContextId& other) const { return id_ != other.id_; }
184
185 private:
186 friend class ::v8::Context;
187 friend class ::v8::internal::Isolate;
188
189 explicit ContextId(uintptr_t id) : id_(id) {}
190
191 static constexpr uintptr_t kEmptyId = 0;
192 uintptr_t id_;
193 };
194
195 virtual ~Recorder() = default;
196
197 // Main thread events. Those are only triggered on the main thread, and hence
198 // can access the context.
199#define ADD_MAIN_THREAD_EVENT(E) \
200 virtual void AddMainThreadEvent(const E&, ContextId) {}
201 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullCycle)
202 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalMark)
203 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalMark)
204 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalSweep)
205 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalSweep)
206 ADD_MAIN_THREAD_EVENT(GarbageCollectionYoungCycle)
207 ADD_MAIN_THREAD_EVENT(WasmModuleDecoded)
208 ADD_MAIN_THREAD_EVENT(WasmModuleCompiled)
209 ADD_MAIN_THREAD_EVENT(WasmModuleInstantiated)
210#undef ADD_MAIN_THREAD_EVENT
211
212 // Thread-safe events are not allowed to access the context and therefore do
213 // not carry a context ID with them. These IDs can be generated using
214 // Recorder::GetContextId() and the ID will be valid throughout the lifetime
215 // of the isolate. It is not guaranteed that the ID will still resolve to
216 // a valid context using Recorder::GetContext() at the time the metric is
217 // recorded. In this case, an empty handle will be returned.
218#define ADD_THREAD_SAFE_EVENT(E) \
219 virtual void AddThreadSafeEvent(const E&) {}
220 ADD_THREAD_SAFE_EVENT(WasmModulesPerIsolate)
221#undef ADD_THREAD_SAFE_EVENT
222
223 virtual void NotifyIsolateDisposal() {}
224
225 // Return the context with the given id or an empty handle if the context
226 // was already garbage collected.
228 // Return the unique id corresponding to the given context.
230};
231
244 V8_INLINE static void Reset(Isolate* isolate) {
246 }
247
251 static LongTaskStats Get(Isolate* isolate);
252
253 int64_t gc_full_atomic_wall_clock_duration_us = 0;
254 int64_t gc_full_incremental_wall_clock_duration_us = 0;
255 int64_t gc_young_wall_clock_duration_us = 0;
256 // Only collected with --slow-histograms
257 int64_t v8_execute_us = 0;
258};
259
260} // namespace metrics
261} // namespace v8
262
263#endif // V8_METRICS_H_
static V8_INLINE void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
static const ContextId Empty()
Definition v8-metrics.h:180
bool operator!=(const ContextId &other) const
Definition v8-metrics.h:183
bool operator==(const ContextId &other) const
Definition v8-metrics.h:182
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
static ContextId GetContextId(Local< Context > context)
virtual void NotifyIsolateDisposal()
Definition v8-metrics.h:223
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:244
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:122
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:101
#define ADD_MAIN_THREAD_EVENT(E)
Definition v8-metrics.h:199
#define ADD_THREAD_SAFE_EVENT(E)
Definition v8-metrics.h:218
#define V8_EXPORT
Definition v8config.h:719
#define V8_INLINE
Definition v8config.h:460