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 <optional>
12#include <vector>
13
14#include "v8-internal.h" // NOLINT(build/include_directory)
15#include "v8-isolate.h" // NOLINT(build/include_directory)
16#include "v8-local-handle.h" // NOLINT(build/include_directory)
17#include "v8config.h" // NOLINT(build/include_directory)
18
19namespace v8 {
20
21class Context;
22class Isolate;
23
24namespace metrics {
25
32};
33
35 int64_t bytes_before = -1;
36 int64_t bytes_after = -1;
37 int64_t bytes_freed = -1;
38};
39
41 int reason = -1;
42 // The priority of the isolate during the GC cycle. A nullopt value denotes a
43 // mixed priority cycle, meaning the Isolate's priority was changed while the
44 // cycle was in progress.
45 std::optional<v8::Isolate::Priority> priority = std::nullopt;
69};
70
74};
75
79};
80
81template <typename EventType>
83 std::vector<EventType> events;
84};
85
92
94 int reason = -1;
95 // The priority of the isolate during the GC cycle. A nullopt value denotes a
96 // mixed priority cycle, meaning the Isolate's priority was changed while the
97 // cycle was in progress.
98 std::optional<v8::Isolate::Priority> priority = std::nullopt;
104#if defined(CPPGC_YOUNG_GENERATION)
105 GarbageCollectionPhases total_cpp;
106 GarbageCollectionSizes objects_cpp;
107 GarbageCollectionSizes memory_cpp;
108 double collection_rate_cpp_in_percent = -1.0;
109 double efficiency_cpp_in_bytes_per_us = -1.0;
110 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
111#endif // defined(CPPGC_YOUNG_GENERATION)
112};
113
115 WasmModuleDecoded() = default;
119 : async(async),
125
126 bool async = false;
127 bool streamed = false;
128 bool success = false;
130 size_t function_count = 0;
132};
133
136
138 bool lazy, bool success, size_t code_size_in_bytes,
141 : async(async),
143 cached(cached),
145 lazy(lazy),
150
151 bool async = false;
152 bool streamed = false;
153 bool cached = false;
154 bool deserialized = false;
155 bool lazy = false;
156 bool success = false;
160};
161
163 bool async = false;
164 bool success = false;
167};
168
170 size_t count = 0;
171};
172
187 public:
188 // A unique identifier for a context in this Isolate.
189 // It is guaranteed to not be reused throughout the lifetime of the Isolate.
190 class ContextId {
191 public:
192 ContextId() : id_(kEmptyId) {}
193
194 bool IsEmpty() const { return id_ == kEmptyId; }
195 static const ContextId Empty() { return ContextId{kEmptyId}; }
196
197 bool operator==(const ContextId& other) const { return id_ == other.id_; }
198 bool operator!=(const ContextId& other) const { return id_ != other.id_; }
199
200 private:
201 friend class ::v8::Context;
202 friend class ::v8::internal::Isolate;
203
204 explicit ContextId(uintptr_t id) : id_(id) {}
205
206 static constexpr uintptr_t kEmptyId = 0;
207 uintptr_t id_;
208 };
209
210 virtual ~Recorder() = default;
211
212 // Main thread events. Those are only triggered on the main thread, and hence
213 // can access the context.
214#define ADD_MAIN_THREAD_EVENT(E) \
215 virtual void AddMainThreadEvent(const E&, ContextId) {}
225#undef ADD_MAIN_THREAD_EVENT
226
227 // Thread-safe events are not allowed to access the context and therefore do
228 // not carry a context ID with them. These IDs can be generated using
229 // Recorder::GetContextId() and the ID will be valid throughout the lifetime
230 // of the isolate. It is not guaranteed that the ID will still resolve to
231 // a valid context using Recorder::GetContext() at the time the metric is
232 // recorded. In this case, an empty handle will be returned.
233#define ADD_THREAD_SAFE_EVENT(E) \
234 virtual void AddThreadSafeEvent(const E&) {}
236#undef ADD_THREAD_SAFE_EVENT
237
238 virtual void NotifyIsolateDisposal() {}
239
240 // Return the context with the given id or an empty handle if the context
241 // was already garbage collected.
243 // Return the unique id corresponding to the given context.
245};
246
259 V8_INLINE static void Reset(Isolate* isolate) {
261 }
262
266 static LongTaskStats Get(Isolate* isolate);
267
268 int64_t gc_full_atomic_wall_clock_duration_us = 0;
269 int64_t gc_full_incremental_wall_clock_duration_us = 0;
270 int64_t gc_young_wall_clock_duration_us = 0;
271 // Only collected with --slow-histograms
272 int64_t v8_execute_us = 0;
273};
274
275} // namespace metrics
276} // namespace v8
277
278#endif // V8_METRICS_H_
Definition: v8-isolate.h:212
Definition: v8-local-handle.h:266
Definition: v8-local-handle.h:632
static void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
Definition: v8-internal.h:1196
Definition: v8-metrics.h:190
ContextId()
Definition: v8-metrics.h:192
bool operator==(const ContextId &other) const
Definition: v8-metrics.h:197
static const ContextId Empty()
Definition: v8-metrics.h:195
bool operator!=(const ContextId &other) const
Definition: v8-metrics.h:198
bool IsEmpty() const
Definition: v8-metrics.h:194
Definition: v8-metrics.h:186
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
virtual void NotifyIsolateDisposal()
Definition: v8-metrics.h:238
static ContextId GetContextId(Local< Context > context)
Definition: libplatform.h:15
std::vector< EventType > events
Definition: v8-metrics.h:83
Definition: v8-metrics.h:40
GarbageCollectionPhases main_thread_incremental
Definition: v8-metrics.h:52
double collection_weight_in_percent
Definition: v8-metrics.h:64
double collection_weight_cpp_in_percent
Definition: v8-metrics.h:65
double main_thread_efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:63
double collection_rate_cpp_in_percent
Definition: v8-metrics.h:59
GarbageCollectionSizes memory_cpp
Definition: v8-metrics.h:57
GarbageCollectionPhases main_thread_cpp
Definition: v8-metrics.h:49
double efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:61
GarbageCollectionSizes memory
Definition: v8-metrics.h:56
GarbageCollectionPhases main_thread_incremental_cpp
Definition: v8-metrics.h:53
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:62
GarbageCollectionSizes objects
Definition: v8-metrics.h:54
int64_t incremental_marking_start_stop_wall_clock_duration_in_us
Definition: v8-metrics.h:68
GarbageCollectionPhases main_thread_atomic_cpp
Definition: v8-metrics.h:51
double collection_rate_in_percent
Definition: v8-metrics.h:58
GarbageCollectionPhases main_thread
Definition: v8-metrics.h:48
std::optional< v8::Isolate::Priority > priority
Definition: v8-metrics.h:45
GarbageCollectionPhases total_cpp
Definition: v8-metrics.h:47
GarbageCollectionPhases total
Definition: v8-metrics.h:46
double main_thread_collection_weight_in_percent
Definition: v8-metrics.h:66
GarbageCollectionPhases main_thread_atomic
Definition: v8-metrics.h:50
int reason
Definition: v8-metrics.h:41
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:60
GarbageCollectionSizes objects_cpp
Definition: v8-metrics.h:55
double main_thread_collection_weight_cpp_in_percent
Definition: v8-metrics.h:67
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:73
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:72
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:77
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:78
Definition: v8-metrics.h:26
int64_t sweep_wall_clock_duration_in_us
Definition: v8-metrics.h:30
int64_t weak_wall_clock_duration_in_us
Definition: v8-metrics.h:31
int64_t total_wall_clock_duration_in_us
Definition: v8-metrics.h:27
int64_t mark_wall_clock_duration_in_us
Definition: v8-metrics.h:29
int64_t compact_wall_clock_duration_in_us
Definition: v8-metrics.h:28
Definition: v8-metrics.h:34
int64_t bytes_freed
Definition: v8-metrics.h:37
int64_t bytes_after
Definition: v8-metrics.h:36
int64_t bytes_before
Definition: v8-metrics.h:35
Definition: v8-metrics.h:93
int64_t main_thread_wall_clock_duration_in_us
Definition: v8-metrics.h:100
double collection_rate_in_percent
Definition: v8-metrics.h:101
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:102
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:103
int reason
Definition: v8-metrics.h:94
int64_t total_wall_clock_duration_in_us
Definition: v8-metrics.h:99
std::optional< v8::Isolate::Priority > priority
Definition: v8-metrics.h:98
Definition: v8-metrics.h:255
static void Reset(Isolate *isolate)
Definition: v8-metrics.h:259
static LongTaskStats Get(Isolate *isolate)
Definition: v8-metrics.h:134
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:137
bool cached
Definition: v8-metrics.h:153
size_t liftoff_bailout_count
Definition: v8-metrics.h:158
bool lazy
Definition: v8-metrics.h:155
bool async
Definition: v8-metrics.h:151
bool deserialized
Definition: v8-metrics.h:154
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:159
bool success
Definition: v8-metrics.h:156
size_t code_size_in_bytes
Definition: v8-metrics.h:157
bool streamed
Definition: v8-metrics.h:152
Definition: v8-metrics.h:114
size_t module_size_in_bytes
Definition: v8-metrics.h:129
bool async
Definition: v8-metrics.h:126
size_t function_count
Definition: v8-metrics.h:130
bool success
Definition: v8-metrics.h:128
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:131
bool streamed
Definition: v8-metrics.h:127
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:116
Definition: v8-metrics.h:162
bool async
Definition: v8-metrics.h:163
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:166
bool success
Definition: v8-metrics.h:164
size_t imported_function_count
Definition: v8-metrics.h:165
Definition: v8-metrics.h:169
size_t count
Definition: v8-metrics.h:170
#define ADD_MAIN_THREAD_EVENT(E)
Definition: v8-metrics.h:214
#define ADD_THREAD_SAFE_EVENT(E)
Definition: v8-metrics.h:233
#define V8_EXPORT
Definition: v8config.h:793
#define V8_INLINE
Definition: v8config.h:499