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) {}
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&) {}
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_
Definition: v8-isolate.h:210
Definition: v8-local-handle.h:258
Definition: v8-local-handle.h:619
static void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
Definition: v8-internal.h:1041
Definition: v8-metrics.h:176
ContextId()
Definition: v8-metrics.h:178
bool operator==(const ContextId &other) const
Definition: v8-metrics.h:183
static const ContextId Empty()
Definition: v8-metrics.h:181
bool operator!=(const ContextId &other) const
Definition: v8-metrics.h:184
bool IsEmpty() const
Definition: v8-metrics.h:180
Definition: v8-metrics.h:172
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
virtual void NotifyIsolateDisposal()
Definition: v8-metrics.h:224
static ContextId GetContextId(Local< Context > context)
Definition: libplatform.h:15
std::vector< EventType > events
Definition: v8-metrics.h:73
Definition: v8-metrics.h:38
GarbageCollectionPhases main_thread_incremental
Definition: v8-metrics.h:46
double main_thread_efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:57
double collection_rate_cpp_in_percent
Definition: v8-metrics.h:53
GarbageCollectionSizes memory_cpp
Definition: v8-metrics.h:51
GarbageCollectionPhases main_thread_cpp
Definition: v8-metrics.h:43
double efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:55
GarbageCollectionSizes memory
Definition: v8-metrics.h:50
GarbageCollectionPhases main_thread_incremental_cpp
Definition: v8-metrics.h:47
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:56
GarbageCollectionSizes objects
Definition: v8-metrics.h:48
int64_t incremental_marking_start_stop_wall_clock_duration_in_us
Definition: v8-metrics.h:58
GarbageCollectionPhases main_thread_atomic_cpp
Definition: v8-metrics.h:45
double collection_rate_in_percent
Definition: v8-metrics.h:52
GarbageCollectionPhases main_thread
Definition: v8-metrics.h:42
GarbageCollectionPhases total_cpp
Definition: v8-metrics.h:41
GarbageCollectionPhases total
Definition: v8-metrics.h:40
GarbageCollectionPhases main_thread_atomic
Definition: v8-metrics.h:44
int reason
Definition: v8-metrics.h:39
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:54
GarbageCollectionSizes objects_cpp
Definition: v8-metrics.h:49
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:63
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:62
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:67
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:68
Definition: v8-metrics.h:24
int64_t sweep_wall_clock_duration_in_us
Definition: v8-metrics.h:28
int64_t weak_wall_clock_duration_in_us
Definition: v8-metrics.h:29
int64_t total_wall_clock_duration_in_us
Definition: v8-metrics.h:25
int64_t mark_wall_clock_duration_in_us
Definition: v8-metrics.h:27
int64_t compact_wall_clock_duration_in_us
Definition: v8-metrics.h:26
Definition: v8-metrics.h:32
int64_t bytes_freed
Definition: v8-metrics.h:35
int64_t bytes_after
Definition: v8-metrics.h:34
int64_t bytes_before
Definition: v8-metrics.h:33
Definition: v8-metrics.h:83
int64_t main_thread_wall_clock_duration_in_us
Definition: v8-metrics.h:86
double collection_rate_in_percent
Definition: v8-metrics.h:87
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:88
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:89
int reason
Definition: v8-metrics.h:84
int64_t total_wall_clock_duration_in_us
Definition: v8-metrics.h:85
Definition: v8-metrics.h:241
static void Reset(Isolate *isolate)
Definition: v8-metrics.h:245
static LongTaskStats Get(Isolate *isolate)
Definition: v8-metrics.h:120
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
bool cached
Definition: v8-metrics.h:139
size_t liftoff_bailout_count
Definition: v8-metrics.h:144
bool lazy
Definition: v8-metrics.h:141
bool async
Definition: v8-metrics.h:137
bool deserialized
Definition: v8-metrics.h:140
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:145
bool success
Definition: v8-metrics.h:142
size_t code_size_in_bytes
Definition: v8-metrics.h:143
bool streamed
Definition: v8-metrics.h:138
Definition: v8-metrics.h:100
size_t module_size_in_bytes
Definition: v8-metrics.h:115
bool async
Definition: v8-metrics.h:112
size_t function_count
Definition: v8-metrics.h:116
bool success
Definition: v8-metrics.h:114
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:117
bool streamed
Definition: v8-metrics.h:113
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
Definition: v8-metrics.h:148
bool async
Definition: v8-metrics.h:149
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:152
bool success
Definition: v8-metrics.h:150
size_t imported_function_count
Definition: v8-metrics.h:151
Definition: v8-metrics.h:155
size_t count
Definition: v8-metrics.h:156
#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:762
#define V8_INLINE
Definition: v8config.h:477