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 int64_t bytes_baseline = -1;
42 int64_t bytes_limit = -1;
43 int64_t bytes_current = -1;
44 int64_t growing_bytes = -1;
45 double growing_factor = -1;
46};
47
49 int reason = -1;
50 // The priority of the isolate during the GC cycle. A nullopt value denotes a
51 // mixed priority cycle, meaning the Isolate's priority was changed while the
52 // cycle was in progress.
53 std::optional<v8::Isolate::Priority> priority = std::nullopt;
54 bool reduce_memory = false;
55 bool is_loading = false;
82};
83
87};
88
92};
93
94template <typename EventType>
96 std::vector<EventType> events;
97};
98
105
107 int reason = -1;
108 // The priority of the isolate during the GC cycle. A nullopt value denotes a
109 // mixed priority cycle, meaning the Isolate's priority was changed while the
110 // cycle was in progress.
111 std::optional<v8::Isolate::Priority> priority = std::nullopt;
117#if defined(CPPGC_YOUNG_GENERATION)
118 GarbageCollectionPhases total_cpp;
119 GarbageCollectionSizes objects_cpp;
120 GarbageCollectionSizes memory_cpp;
121 double collection_rate_cpp_in_percent = -1.0;
122 double efficiency_cpp_in_bytes_per_us = -1.0;
123 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
124#endif // defined(CPPGC_YOUNG_GENERATION)
125};
126
128 WasmModuleDecoded() = default;
132 : async(async),
138
139 bool async = false;
140 bool streamed = false;
141 bool success = false;
143 size_t function_count = 0;
145};
146
149
151 bool lazy, bool success, size_t code_size_in_bytes,
154 : async(async),
156 cached(cached),
158 lazy(lazy),
163
164 bool async = false;
165 bool streamed = false;
166 bool cached = false;
167 bool deserialized = false;
168 bool lazy = false;
169 bool success = false;
173};
174
176 bool async = false;
177 bool success = false;
180};
181
183 size_t count = 0;
184};
185
200 public:
201 // A unique identifier for a context in this Isolate.
202 // It is guaranteed to not be reused throughout the lifetime of the Isolate.
203 class ContextId {
204 public:
205 ContextId() : id_(kEmptyId) {}
206
207 bool IsEmpty() const { return id_ == kEmptyId; }
208 static const ContextId Empty() { return ContextId{kEmptyId}; }
209
210 bool operator==(const ContextId& other) const { return id_ == other.id_; }
211 bool operator!=(const ContextId& other) const { return id_ != other.id_; }
212
213 private:
214 friend class ::v8::Context;
215 friend class ::v8::internal::Isolate;
216
217 explicit ContextId(uintptr_t id) : id_(id) {}
218
219 static constexpr uintptr_t kEmptyId = 0;
220 uintptr_t id_;
221 };
222
223 virtual ~Recorder() = default;
224
225 // Main thread events. Those are only triggered on the main thread, and hence
226 // can access the context.
227#define ADD_MAIN_THREAD_EVENT(E) \
228 virtual void AddMainThreadEvent(const E&, ContextId) {}
238#undef ADD_MAIN_THREAD_EVENT
239
240 // Thread-safe events are not allowed to access the context and therefore do
241 // not carry a context ID with them. These IDs can be generated using
242 // Recorder::GetContextId() and the ID will be valid throughout the lifetime
243 // of the isolate. It is not guaranteed that the ID will still resolve to
244 // a valid context using Recorder::GetContext() at the time the metric is
245 // recorded. In this case, an empty handle will be returned.
246#define ADD_THREAD_SAFE_EVENT(E) \
247 virtual void AddThreadSafeEvent(const E&) {}
249#undef ADD_THREAD_SAFE_EVENT
250
251 virtual void NotifyIsolateDisposal() {}
252
253 // Return the context with the given id or an empty handle if the context
254 // was already garbage collected.
256 // Return the unique id corresponding to the given context.
258};
259
272 V8_INLINE static void Reset(Isolate* isolate) {
274 }
275
279 static LongTaskStats Get(Isolate* isolate);
280
281 int64_t gc_full_atomic_wall_clock_duration_us = 0;
282 int64_t gc_full_incremental_wall_clock_duration_us = 0;
283 int64_t gc_young_wall_clock_duration_us = 0;
284 // Only collected with --slow-histograms
285 int64_t v8_execute_us = 0;
286};
287
288} // namespace metrics
289} // namespace v8
290
291#endif // V8_METRICS_H_
Definition: v8-isolate.h:290
Definition: v8-local-handle.h:366
Definition: v8-local-handle.h:734
static void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
Definition: v8-internal.h:1231
Definition: v8-metrics.h:203
ContextId()
Definition: v8-metrics.h:205
bool operator==(const ContextId &other) const
Definition: v8-metrics.h:210
static const ContextId Empty()
Definition: v8-metrics.h:208
bool operator!=(const ContextId &other) const
Definition: v8-metrics.h:211
bool IsEmpty() const
Definition: v8-metrics.h:207
Definition: v8-metrics.h:199
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
virtual void NotifyIsolateDisposal()
Definition: v8-metrics.h:251
static ContextId GetContextId(Local< Context > context)
Definition: libplatform.h:15
std::vector< EventType > events
Definition: v8-metrics.h:96
Definition: v8-metrics.h:48
GarbageCollectionPhases main_thread_incremental
Definition: v8-metrics.h:62
double collection_weight_in_percent
Definition: v8-metrics.h:76
double collection_weight_cpp_in_percent
Definition: v8-metrics.h:77
double main_thread_efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:75
GarbageCollectionLimits global_consumed
Definition: v8-metrics.h:69
double collection_rate_cpp_in_percent
Definition: v8-metrics.h:71
GarbageCollectionSizes memory_cpp
Definition: v8-metrics.h:67
GarbageCollectionPhases main_thread_cpp
Definition: v8-metrics.h:59
GarbageCollectionLimits old_generation_consumed
Definition: v8-metrics.h:68
double efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:73
GarbageCollectionSizes memory
Definition: v8-metrics.h:66
int64_t total_duration_since_last_mark_compact
Definition: v8-metrics.h:81
bool reduce_memory
Definition: v8-metrics.h:54
GarbageCollectionPhases main_thread_incremental_cpp
Definition: v8-metrics.h:63
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:74
GarbageCollectionSizes objects
Definition: v8-metrics.h:64
int64_t incremental_marking_start_stop_wall_clock_duration_in_us
Definition: v8-metrics.h:80
GarbageCollectionPhases main_thread_atomic_cpp
Definition: v8-metrics.h:61
double collection_rate_in_percent
Definition: v8-metrics.h:70
bool is_loading
Definition: v8-metrics.h:55
GarbageCollectionPhases main_thread
Definition: v8-metrics.h:58
std::optional< v8::Isolate::Priority > priority
Definition: v8-metrics.h:53
GarbageCollectionPhases total_cpp
Definition: v8-metrics.h:57
GarbageCollectionPhases total
Definition: v8-metrics.h:56
double main_thread_collection_weight_in_percent
Definition: v8-metrics.h:78
GarbageCollectionPhases main_thread_atomic
Definition: v8-metrics.h:60
int reason
Definition: v8-metrics.h:49
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:72
GarbageCollectionSizes objects_cpp
Definition: v8-metrics.h:65
double main_thread_collection_weight_cpp_in_percent
Definition: v8-metrics.h:79
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:86
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:85
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:90
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:91
Definition: v8-metrics.h:40
int64_t bytes_limit
Definition: v8-metrics.h:42
int64_t growing_bytes
Definition: v8-metrics.h:44
double growing_factor
Definition: v8-metrics.h:45
int64_t bytes_current
Definition: v8-metrics.h:43
int64_t bytes_baseline
Definition: v8-metrics.h:41
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:106
int64_t main_thread_wall_clock_duration_in_us
Definition: v8-metrics.h:113
double collection_rate_in_percent
Definition: v8-metrics.h:114
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:115
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:116
int reason
Definition: v8-metrics.h:107
int64_t total_wall_clock_duration_in_us
Definition: v8-metrics.h:112
std::optional< v8::Isolate::Priority > priority
Definition: v8-metrics.h:111
Definition: v8-metrics.h:268
static void Reset(Isolate *isolate)
Definition: v8-metrics.h:272
static LongTaskStats Get(Isolate *isolate)
Definition: v8-metrics.h:147
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:150
bool cached
Definition: v8-metrics.h:166
size_t liftoff_bailout_count
Definition: v8-metrics.h:171
bool lazy
Definition: v8-metrics.h:168
bool async
Definition: v8-metrics.h:164
bool deserialized
Definition: v8-metrics.h:167
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:172
bool success
Definition: v8-metrics.h:169
size_t code_size_in_bytes
Definition: v8-metrics.h:170
bool streamed
Definition: v8-metrics.h:165
Definition: v8-metrics.h:127
size_t module_size_in_bytes
Definition: v8-metrics.h:142
bool async
Definition: v8-metrics.h:139
size_t function_count
Definition: v8-metrics.h:143
bool success
Definition: v8-metrics.h:141
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:144
bool streamed
Definition: v8-metrics.h:140
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:129
Definition: v8-metrics.h:175
bool async
Definition: v8-metrics.h:176
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:179
bool success
Definition: v8-metrics.h:177
size_t imported_function_count
Definition: v8-metrics.h:178
Definition: v8-metrics.h:182
size_t count
Definition: v8-metrics.h:183
#define ADD_MAIN_THREAD_EVENT(E)
Definition: v8-metrics.h:227
#define ADD_THREAD_SAFE_EVENT(E)
Definition: v8-metrics.h:246
#define V8_EXPORT
Definition: v8config.h:860
#define V8_INLINE
Definition: v8config.h:513