v8 10.2.154 (node 18.16.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
16namespace v8 {
17
18class Context;
19class Isolate;
20
21namespace metrics {
22
29};
30
32 int64_t bytes_before = -1;
33 int64_t bytes_after = -1;
34 int64_t bytes_freed = -1;
35};
36
38 int reason = -1;
57};
58
62};
63
67};
68
69template <typename EventType>
71 std::vector<EventType> events;
72};
73
80
82 int reason = -1;
88#if defined(CPPGC_YOUNG_GENERATION)
90 GarbageCollectionSizes objects_cpp;
91 GarbageCollectionSizes memory_cpp;
92 double collection_rate_cpp_in_percent = -1.0;
93 double efficiency_cpp_in_bytes_per_us = -1.0;
94 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
95#endif // defined(CPPGC_YOUNG_GENERATION)
96};
97
99 bool async = false;
100 bool streamed = false;
101 bool success = false;
103 size_t function_count = 0;
105 int64_t cpu_duration_in_us = -1;
106};
107
109 bool async = false;
110 bool streamed = false;
111 bool cached = false;
112 bool deserialized = false;
113 bool lazy = false;
114 bool success = false;
118 int64_t cpu_duration_in_us = -1;
119};
120
122 bool async = false;
123 bool success = false;
126};
127
129 bool lazy = false;
132 int64_t cpu_duration_in_us = -1;
133};
134
136 size_t count = 0;
137};
138
139#define V8_MAIN_THREAD_METRICS_EVENTS(V) \
140 V(GarbageCollectionFullCycle) \
141 V(GarbageCollectionFullMainThreadIncrementalMark) \
142 V(GarbageCollectionFullMainThreadBatchedIncrementalMark) \
143 V(GarbageCollectionFullMainThreadIncrementalSweep) \
144 V(GarbageCollectionFullMainThreadBatchedIncrementalSweep) \
145 V(GarbageCollectionYoungCycle) \
146 V(WasmModuleDecoded) \
147 V(WasmModuleCompiled) \
148 V(WasmModuleInstantiated) \
149 V(WasmModuleTieredUp)
150
151#define V8_THREAD_SAFE_METRICS_EVENTS(V) V(WasmModulesPerIsolate)
152
180 public:
181 // A unique identifier for a context in this Isolate.
182 // It is guaranteed to not be reused throughout the lifetime of the Isolate.
183 class ContextId {
184 public:
185 ContextId() : id_(kEmptyId) {}
186
187 bool IsEmpty() const { return id_ == kEmptyId; }
188 static const ContextId Empty() { return ContextId{kEmptyId}; }
189
190 bool operator==(const ContextId& other) const { return id_ == other.id_; }
191 bool operator!=(const ContextId& other) const { return id_ != other.id_; }
192
193 private:
194 friend class ::v8::Context;
195 friend class ::v8::internal::Isolate;
196
197 explicit ContextId(uintptr_t id) : id_(id) {}
198
199 static constexpr uintptr_t kEmptyId = 0;
200 uintptr_t id_;
201 };
202
203 virtual ~Recorder() = default;
204
205#define ADD_MAIN_THREAD_EVENT(E) \
206 virtual void AddMainThreadEvent(const E& event, ContextId context_id) {}
208#undef ADD_MAIN_THREAD_EVENT
209
210#define ADD_THREAD_SAFE_EVENT(E) \
211 virtual void AddThreadSafeEvent(const E& event) {}
213#undef ADD_THREAD_SAFE_EVENT
214
215 virtual void NotifyIsolateDisposal() {}
216
217 // Return the context with the given id or an empty handle if the context
218 // was already garbage collected.
220 // Return the unique id corresponding to the given context.
222};
223
236 V8_INLINE static void Reset(Isolate* isolate) {
238 }
239
243 static LongTaskStats Get(Isolate* isolate);
244
245 int64_t gc_full_atomic_wall_clock_duration_us = 0;
246 int64_t gc_full_incremental_wall_clock_duration_us = 0;
247 int64_t gc_young_wall_clock_duration_us = 0;
248 // Only collected with --slow-histograms
249 int64_t v8_execute_us = 0;
250};
251
252} // namespace metrics
253} // namespace v8
254
255#endif // V8_METRICS_H_
static V8_INLINE void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
static const ContextId Empty()
Definition v8-metrics.h:188
bool operator!=(const ContextId &other) const
Definition v8-metrics.h:191
bool operator==(const ContextId &other) const
Definition v8-metrics.h:190
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
static ContextId GetContextId(Local< Context > context)
virtual void NotifyIsolateDisposal()
Definition v8-metrics.h:215
GarbageCollectionPhases main_thread_incremental
Definition v8-metrics.h:45
GarbageCollectionPhases main_thread_atomic_cpp
Definition v8-metrics.h:44
GarbageCollectionPhases main_thread
Definition v8-metrics.h:41
GarbageCollectionPhases main_thread_incremental_cpp
Definition v8-metrics.h:46
GarbageCollectionPhases main_thread_cpp
Definition v8-metrics.h:42
GarbageCollectionSizes memory_cpp
Definition v8-metrics.h:50
GarbageCollectionPhases total_cpp
Definition v8-metrics.h:40
GarbageCollectionPhases main_thread_atomic
Definition v8-metrics.h:43
GarbageCollectionSizes objects_cpp
Definition v8-metrics.h:48
static V8_INLINE void Reset(Isolate *isolate)
Definition v8-metrics.h:236
static LongTaskStats Get(Isolate *isolate)
#define V8_MAIN_THREAD_METRICS_EVENTS(V)
Definition v8-metrics.h:139
#define ADD_MAIN_THREAD_EVENT(E)
Definition v8-metrics.h:205
#define V8_THREAD_SAFE_METRICS_EVENTS(V)
Definition v8-metrics.h:151
#define ADD_THREAD_SAFE_EVENT(E)
Definition v8-metrics.h:210
#define V8_EXPORT
Definition v8config.h:578
#define V8_INLINE
Definition v8config.h:425