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 bytes_max = -1;
45};
46
48 int reason = -1;
50 int growing_mode = -1;
51 // The priority of the isolate during the GC cycle. A nullopt value denotes a
52 // mixed priority cycle, meaning the Isolate's priority was changed while the
53 // cycle was in progress.
54 std::optional<v8::Isolate::Priority> priority = std::nullopt;
55 bool reduce_memory = false;
56 bool is_loading = false;
57 bool is_input_handling = false;
86};
87
91};
92
96};
97
98template <typename EventType>
100 std::vector<EventType> events;
101};
102
109
111 int reason = -1;
112 // The priority of the isolate during the GC cycle. A nullopt value denotes a
113 // mixed priority cycle, meaning the Isolate's priority was changed while the
114 // cycle was in progress.
115 std::optional<v8::Isolate::Priority> priority = std::nullopt;
121#if defined(CPPGC_YOUNG_GENERATION)
122 GarbageCollectionPhases total_cpp;
123 GarbageCollectionSizes objects_cpp;
124 GarbageCollectionSizes memory_cpp;
125 double collection_rate_cpp_in_percent = -1.0;
126 double efficiency_cpp_in_bytes_per_us = -1.0;
127 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0;
128#endif // defined(CPPGC_YOUNG_GENERATION)
129};
130
131// Note: These structs do not define any constructor, and declare most fields as
132// const, to force initializing them when using aggregate (designated)
133// initialization.
134// Those structs are meant to be created in V8 and read by embedders.
136 const bool async;
137 const bool streamed;
138 const bool success;
140 const size_t function_count;
141 // Optional field; only set if a high-resolution clock is available.
143};
144
146 const bool async;
147 const bool streamed;
148 const bool cached;
149 const bool deserialized;
150 const bool lazy;
151 const bool success;
152 const size_t code_size_in_bytes;
154 // Optional field; only set if a high-resolution clock is available.
156};
157
159 const bool async;
160 const bool success;
162 // Optional field; only set if a high-resolution clock is available.
164};
165
167 const size_t count;
168};
169
184 public:
185 // A unique identifier for a context in this Isolate.
186 // It is guaranteed to not be reused throughout the lifetime of the Isolate.
187 class ContextId {
188 public:
189 ContextId() : id_(kEmptyId) {}
190
191 bool IsEmpty() const { return id_ == kEmptyId; }
192 static const ContextId Empty() { return ContextId{kEmptyId}; }
193
194 bool operator==(const ContextId& other) const { return id_ == other.id_; }
195 bool operator!=(const ContextId& other) const { return id_ != other.id_; }
196
197 private:
198 friend class ::v8::Context;
199 friend class ::v8::internal::Isolate;
200
201 explicit ContextId(uintptr_t id) : id_(id) {}
202
203 static constexpr uintptr_t kEmptyId = 0;
204 uintptr_t id_;
205 };
206
207 virtual ~Recorder() = default;
208
209 // Main thread events. Those are only triggered on the main thread, and hence
210 // can access the context.
211#define ADD_MAIN_THREAD_EVENT(E) \
212 virtual void AddMainThreadEvent(const E&, ContextId) {}
222#undef ADD_MAIN_THREAD_EVENT
223
224 // Thread-safe events are not allowed to access the context and therefore do
225 // not carry a context ID with them. These IDs can be generated using
226 // Recorder::GetContextId() and the ID will be valid throughout the lifetime
227 // of the isolate. It is not guaranteed that the ID will still resolve to
228 // a valid context using Recorder::GetContext() at the time the metric is
229 // recorded. In this case, an empty handle will be returned.
230#define ADD_THREAD_SAFE_EVENT(E) \
231 virtual void AddThreadSafeEvent(const E&) {}
233#undef ADD_THREAD_SAFE_EVENT
234
235 virtual void NotifyIsolateDisposal() {}
236
237 // Return the context with the given id or an empty handle if the context
238 // was already garbage collected.
240 // Return the unique id corresponding to the given context.
242};
243
256 V8_INLINE static void Reset(Isolate* isolate) {
258 }
259
263 static LongTaskStats Get(Isolate* isolate);
264
265 int64_t gc_full_atomic_wall_clock_duration_us = 0;
266 int64_t gc_full_incremental_wall_clock_duration_us = 0;
267 int64_t gc_young_wall_clock_duration_us = 0;
268 // Only collected with --slow-histograms
269 int64_t v8_execute_us = 0;
270};
271
272} // namespace metrics
273} // namespace v8
274
275#endif // V8_METRICS_H_
Definition: v8-isolate.h:292
Definition: v8-local-handle.h:366
Definition: v8-local-handle.h:734
static void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
Definition: v8-internal.h:1363
Definition: v8-metrics.h:187
ContextId()
Definition: v8-metrics.h:189
bool operator==(const ContextId &other) const
Definition: v8-metrics.h:194
static const ContextId Empty()
Definition: v8-metrics.h:192
bool operator!=(const ContextId &other) const
Definition: v8-metrics.h:195
bool IsEmpty() const
Definition: v8-metrics.h:191
Definition: v8-metrics.h:183
virtual ~Recorder()=default
static MaybeLocal< Context > GetContext(Isolate *isolate, ContextId id)
virtual void NotifyIsolateDisposal()
Definition: v8-metrics.h:235
static ContextId GetContextId(Local< Context > context)
Definition: libplatform.h:15
std::vector< EventType > events
Definition: v8-metrics.h:100
Definition: v8-metrics.h:47
GarbageCollectionPhases main_thread_incremental
Definition: v8-metrics.h:64
double collection_weight_in_percent
Definition: v8-metrics.h:80
double collection_weight_cpp_in_percent
Definition: v8-metrics.h:81
double main_thread_efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:79
GarbageCollectionLimits global_consumed
Definition: v8-metrics.h:71
bool is_input_handling
Definition: v8-metrics.h:57
int64_t external_memory_bytes
Definition: v8-metrics.h:72
double collection_rate_cpp_in_percent
Definition: v8-metrics.h:75
GarbageCollectionSizes memory_cpp
Definition: v8-metrics.h:69
GarbageCollectionPhases main_thread_cpp
Definition: v8-metrics.h:61
GarbageCollectionLimits old_generation_consumed
Definition: v8-metrics.h:70
double efficiency_cpp_in_bytes_per_us
Definition: v8-metrics.h:77
GarbageCollectionSizes memory
Definition: v8-metrics.h:68
int64_t total_duration_since_last_mark_compact
Definition: v8-metrics.h:85
bool reduce_memory
Definition: v8-metrics.h:55
GarbageCollectionPhases main_thread_incremental_cpp
Definition: v8-metrics.h:65
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:78
GarbageCollectionSizes objects
Definition: v8-metrics.h:66
int64_t incremental_marking_start_stop_wall_clock_duration_in_us
Definition: v8-metrics.h:84
int64_t found_js_global_proxies
Definition: v8-metrics.h:73
GarbageCollectionPhases main_thread_atomic_cpp
Definition: v8-metrics.h:63
double collection_rate_in_percent
Definition: v8-metrics.h:74
bool is_loading
Definition: v8-metrics.h:56
int growing_mode
Definition: v8-metrics.h:50
GarbageCollectionPhases main_thread
Definition: v8-metrics.h:60
int incremental_marking_reason
Definition: v8-metrics.h:49
std::optional< v8::Isolate::Priority > priority
Definition: v8-metrics.h:54
GarbageCollectionPhases total_cpp
Definition: v8-metrics.h:59
GarbageCollectionPhases total
Definition: v8-metrics.h:58
double main_thread_collection_weight_in_percent
Definition: v8-metrics.h:82
GarbageCollectionPhases main_thread_atomic
Definition: v8-metrics.h:62
int reason
Definition: v8-metrics.h:48
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:76
GarbageCollectionSizes objects_cpp
Definition: v8-metrics.h:67
double main_thread_collection_weight_cpp_in_percent
Definition: v8-metrics.h:83
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:90
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:89
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:94
int64_t cpp_wall_clock_duration_in_us
Definition: v8-metrics.h:95
Definition: v8-metrics.h:40
int64_t bytes_limit
Definition: v8-metrics.h:42
int64_t bytes_max
Definition: v8-metrics.h:44
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:110
int64_t main_thread_wall_clock_duration_in_us
Definition: v8-metrics.h:117
double collection_rate_in_percent
Definition: v8-metrics.h:118
double efficiency_in_bytes_per_us
Definition: v8-metrics.h:119
double main_thread_efficiency_in_bytes_per_us
Definition: v8-metrics.h:120
int reason
Definition: v8-metrics.h:111
int64_t total_wall_clock_duration_in_us
Definition: v8-metrics.h:116
std::optional< v8::Isolate::Priority > priority
Definition: v8-metrics.h:115
Definition: v8-metrics.h:252
static void Reset(Isolate *isolate)
Definition: v8-metrics.h:256
static LongTaskStats Get(Isolate *isolate)
Definition: v8-metrics.h:145
const size_t liftoff_bailout_count
Definition: v8-metrics.h:153
const bool cached
Definition: v8-metrics.h:148
const bool success
Definition: v8-metrics.h:151
const bool deserialized
Definition: v8-metrics.h:149
const bool lazy
Definition: v8-metrics.h:150
const size_t code_size_in_bytes
Definition: v8-metrics.h:152
const bool streamed
Definition: v8-metrics.h:147
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:155
const bool async
Definition: v8-metrics.h:146
Definition: v8-metrics.h:135
const size_t module_size_in_bytes
Definition: v8-metrics.h:139
const size_t function_count
Definition: v8-metrics.h:140
const bool success
Definition: v8-metrics.h:138
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:142
const bool async
Definition: v8-metrics.h:136
const bool streamed
Definition: v8-metrics.h:137
Definition: v8-metrics.h:158
const bool success
Definition: v8-metrics.h:160
const bool async
Definition: v8-metrics.h:159
const size_t imported_function_count
Definition: v8-metrics.h:161
int64_t wall_clock_duration_in_us
Definition: v8-metrics.h:163
Definition: v8-metrics.h:166
const size_t count
Definition: v8-metrics.h:167
#define ADD_MAIN_THREAD_EVENT(E)
Definition: v8-metrics.h:211
#define ADD_THREAD_SAFE_EVENT(E)
Definition: v8-metrics.h:230
#define V8_EXPORT
Definition: v8config.h:867
#define V8_INLINE
Definition: v8config.h:511