Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/deps/v8/include/v8-metrics.h
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 17 namespace v8 { 18 19 class Context; 20 class Isolate; 21 22 namespace metrics { 23 24 struct GarbageCollectionPhases { 25 int64_t total_wall_clock_duration_in_us = -1; 26 int64_t compact_wall_clock_duration_in_us = -1; 27 int64_t mark_wall_clock_duration_in_us = -1; 28 int64_t sweep_wall_clock_duration_in_us = -1; 29 int64_t weak_wall_clock_duration_in_us = -1; 30 }; 31 32 struct GarbageCollectionSizes { 33 int64_t bytes_before = -1; 34 int64_t bytes_after = -1; 35 int64_t bytes_freed = -1; 36 }; 37 38 struct GarbageCollectionFullCycle { 39 int reason = -1; 40 GarbageCollectionPhases total; 41 GarbageCollectionPhases total_cpp; 42 GarbageCollectionPhases main_thread; 43 GarbageCollectionPhases main_thread_cpp; 44 GarbageCollectionPhases main_thread_atomic; 45 GarbageCollectionPhases main_thread_atomic_cpp; 46 GarbageCollectionPhases main_thread_incremental; 47 GarbageCollectionPhases main_thread_incremental_cpp; 48 GarbageCollectionSizes objects; 49 GarbageCollectionSizes objects_cpp; 50 GarbageCollectionSizes memory; 51 GarbageCollectionSizes memory_cpp; 52 double collection_rate_in_percent = -1.0; 53 double collection_rate_cpp_in_percent = -1.0; 54 double efficiency_in_bytes_per_us = -1.0; 55 double efficiency_cpp_in_bytes_per_us = -1.0; 56 double main_thread_efficiency_in_bytes_per_us = -1.0; 57 double main_thread_efficiency_cpp_in_bytes_per_us = -1.0; 58 int64_t incremental_marking_start_stop_wall_clock_duration_in_us = -1; 59 }; 60 61 struct GarbageCollectionFullMainThreadIncrementalMark { 62 int64_t wall_clock_duration_in_us = -1; 63 int64_t cpp_wall_clock_duration_in_us = -1; 64 }; 65 66 struct GarbageCollectionFullMainThreadIncrementalSweep { 67 int64_t wall_clock_duration_in_us = -1; 68 int64_t cpp_wall_clock_duration_in_us = -1; 69 }; 70 71 template <typename EventType> 72 struct GarbageCollectionBatchedEvents { 73 std::vector<EventType> events; 74 }; 75 76 using GarbageCollectionFullMainThreadBatchedIncrementalMark = 77 GarbageCollectionBatchedEvents< 78 GarbageCollectionFullMainThreadIncrementalMark>; 79 using GarbageCollectionFullMainThreadBatchedIncrementalSweep = 80 GarbageCollectionBatchedEvents< 81 GarbageCollectionFullMainThreadIncrementalSweep>; 82 83 struct GarbageCollectionYoungCycle { 84 int reason = -1; 85 int64_t total_wall_clock_duration_in_us = -1; 86 int64_t main_thread_wall_clock_duration_in_us = -1; 87 double collection_rate_in_percent = -1.0; 88 double efficiency_in_bytes_per_us = -1.0; 89 double main_thread_efficiency_in_bytes_per_us = -1.0; 90 #if defined(CPPGC_YOUNG_GENERATION) 91 GarbageCollectionPhases total_cpp; 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 100 struct WasmModuleDecoded { 101 WasmModuleDecoded() = default; 102 WasmModuleDecoded(bool async, bool streamed, bool success, 103 size_t module_size_in_bytes, size_t function_count, 104 int64_t wall_clock_duration_in_us) 105 : async(async), 106 streamed(streamed), 107 success(success), 108 module_size_in_bytes(module_size_in_bytes), 109 function_count(function_count), 110 wall_clock_duration_in_us(wall_clock_duration_in_us) {} 111 112 bool async = false; 113 bool streamed = false; 114 bool success = false; 115 size_t module_size_in_bytes = 0; 116 size_t function_count = 0; 117 int64_t wall_clock_duration_in_us = -1; 118 }; 119 120 struct WasmModuleCompiled { 121 WasmModuleCompiled() = default; 122 123 WasmModuleCompiled(bool async, bool streamed, bool cached, bool deserialized, 124 bool lazy, bool success, size_t code_size_in_bytes, 125 size_t liftoff_bailout_count, 126 int64_t wall_clock_duration_in_us) 127 : async(async), 128 streamed(streamed), 129 cached(cached), 130 deserialized(deserialized), 131 lazy(lazy), 132 success(success), 133 code_size_in_bytes(code_size_in_bytes), 134 liftoff_bailout_count(liftoff_bailout_count), 135 wall_clock_duration_in_us(wall_clock_duration_in_us) {} 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; 143 size_t code_size_in_bytes = 0; 144 size_t liftoff_bailout_count = 0; 145 int64_t wall_clock_duration_in_us = -1; 146 }; 147 148 struct WasmModuleInstantiated { 149 bool async = false; 150 bool success = false; 151 size_t imported_function_count = 0; 152 int64_t wall_clock_duration_in_us = -1; 153 }; 154 155 struct WasmModulesPerIsolate { 156 size_t count = 0; 157 }; 158 159 /** 160 * This class serves as a base class for recording event-based metrics in V8. 161 * There a two kinds of metrics, those which are expected to be thread-safe and 162 * whose implementation is required to fulfill this requirement and those whose 163 * implementation does not have that requirement and only needs to be 164 * executable on the main thread. If such an event is triggered from a 165 * background thread, it will be delayed and executed by the foreground task 166 * runner. 167 * 168 * The embedder is expected to call v8::Isolate::SetMetricsRecorder() 169 * providing its implementation and have the virtual methods overwritten 170 * for the events it cares about. 171 */ 172 class V8_EXPORT Recorder { 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) {} 202 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullCycle) 203 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalMark) 204 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalMark) 205 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadIncrementalSweep) 206 ADD_MAIN_THREAD_EVENT(GarbageCollectionFullMainThreadBatchedIncrementalSweep) 207 ADD_MAIN_THREAD_EVENT(GarbageCollectionYoungCycle) 208 ADD_MAIN_THREAD_EVENT(WasmModuleDecoded) 209 ADD_MAIN_THREAD_EVENT(WasmModuleCompiled) 210 ADD_MAIN_THREAD_EVENT(WasmModuleInstantiated) 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&) {} 221 ADD_THREAD_SAFE_EVENT(WasmModulesPerIsolate) 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. 228 static MaybeLocal<Context> GetContext(Isolate* isolate, ContextId id); 229 // Return the unique id corresponding to the given context. 230 static ContextId GetContextId(Local<Context> context); 231 }; 232 233 /** 234 * Experimental API intended for the LongTasks UKM (crbug.com/1173527). 235 * The Reset() method should be called at the start of a potential 236 * long task. The Get() method returns durations of V8 work that 237 * happened during the task. 238 * 239 * This API is experimental and may be removed/changed in the future. 240 */ 241 struct V8_EXPORT LongTaskStats { 242 /** 243 * Resets durations of V8 work for the new task. 244 */ 245 V8_INLINE static void Reset(Isolate* isolate) { 246 v8::internal::Internals::IncrementLongTasksStatsCounter(isolate); 247 } 248 249 /** 250 * Returns durations of V8 work that happened since the last Reset(). 251 */ 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_