@downdraft/native-mobile-android-arm64 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +7 -0
  2. package/include/node/cppgc/allocation.h +308 -0
  3. package/include/node/cppgc/common.h +28 -0
  4. package/include/node/cppgc/cross-thread-persistent.h +462 -0
  5. package/include/node/cppgc/custom-space.h +97 -0
  6. package/include/node/cppgc/default-platform.h +68 -0
  7. package/include/node/cppgc/explicit-management.h +100 -0
  8. package/include/node/cppgc/garbage-collected.h +114 -0
  9. package/include/node/cppgc/heap-consistency.h +309 -0
  10. package/include/node/cppgc/heap-handle.h +48 -0
  11. package/include/node/cppgc/heap-state.h +82 -0
  12. package/include/node/cppgc/heap-statistics.h +126 -0
  13. package/include/node/cppgc/heap.h +202 -0
  14. package/include/node/cppgc/internal/api-constants.h +75 -0
  15. package/include/node/cppgc/internal/atomic-entry-flag.h +48 -0
  16. package/include/node/cppgc/internal/base-page-handle.h +43 -0
  17. package/include/node/cppgc/internal/caged-heap-local-data.h +117 -0
  18. package/include/node/cppgc/internal/caged-heap.h +64 -0
  19. package/include/node/cppgc/internal/compiler-specific.h +46 -0
  20. package/include/node/cppgc/internal/conditional-stack-allocated.h +41 -0
  21. package/include/node/cppgc/internal/finalizer-trait.h +93 -0
  22. package/include/node/cppgc/internal/gc-info.h +150 -0
  23. package/include/node/cppgc/internal/logging.h +50 -0
  24. package/include/node/cppgc/internal/member-storage.h +305 -0
  25. package/include/node/cppgc/internal/name-trait.h +141 -0
  26. package/include/node/cppgc/internal/persistent-node.h +219 -0
  27. package/include/node/cppgc/internal/pointer-policies.h +280 -0
  28. package/include/node/cppgc/internal/write-barrier.h +487 -0
  29. package/include/node/cppgc/liveness-broker.h +78 -0
  30. package/include/node/cppgc/macros.h +56 -0
  31. package/include/node/cppgc/member.h +669 -0
  32. package/include/node/cppgc/name-provider.h +75 -0
  33. package/include/node/cppgc/object-size-trait.h +58 -0
  34. package/include/node/cppgc/persistent.h +376 -0
  35. package/include/node/cppgc/platform.h +174 -0
  36. package/include/node/cppgc/prefinalizer.h +75 -0
  37. package/include/node/cppgc/process-heap-statistics.h +36 -0
  38. package/include/node/cppgc/sentinel-pointer.h +39 -0
  39. package/include/node/cppgc/source-location.h +16 -0
  40. package/include/node/cppgc/tagged-member.h +114 -0
  41. package/include/node/cppgc/testing.h +106 -0
  42. package/include/node/cppgc/trace-trait.h +127 -0
  43. package/include/node/cppgc/type-traits.h +272 -0
  44. package/include/node/cppgc/visitor.h +534 -0
  45. package/include/node/js_native_api.h +634 -0
  46. package/include/node/js_native_api_types.h +244 -0
  47. package/include/node/libplatform/libplatform-export.h +29 -0
  48. package/include/node/libplatform/libplatform.h +112 -0
  49. package/include/node/libplatform/v8-tracing.h +343 -0
  50. package/include/node/node.h +1744 -0
  51. package/include/node/node_api.h +265 -0
  52. package/include/node/node_api_types.h +58 -0
  53. package/include/node/node_buffer.h +94 -0
  54. package/include/node/node_object_wrap.h +145 -0
  55. package/include/node/node_version.h +116 -0
  56. package/include/node/uv/aix.h +32 -0
  57. package/include/node/uv/bsd.h +34 -0
  58. package/include/node/uv/darwin.h +61 -0
  59. package/include/node/uv/errno.h +483 -0
  60. package/include/node/uv/linux.h +34 -0
  61. package/include/node/uv/os390.h +33 -0
  62. package/include/node/uv/posix.h +31 -0
  63. package/include/node/uv/sunos.h +44 -0
  64. package/include/node/uv/threadpool.h +37 -0
  65. package/include/node/uv/tree.h +521 -0
  66. package/include/node/uv/unix.h +509 -0
  67. package/include/node/uv/version.h +43 -0
  68. package/include/node/uv/win.h +698 -0
  69. package/include/node/uv.h +1994 -0
  70. package/include/node/v8-array-buffer.h +646 -0
  71. package/include/node/v8-callbacks.h +533 -0
  72. package/include/node/v8-container.h +183 -0
  73. package/include/node/v8-context.h +580 -0
  74. package/include/node/v8-cpp-heap-external.h +56 -0
  75. package/include/node/v8-cppgc.h +194 -0
  76. package/include/node/v8-data.h +96 -0
  77. package/include/node/v8-date.h +57 -0
  78. package/include/node/v8-debug.h +210 -0
  79. package/include/node/v8-embedder-heap.h +54 -0
  80. package/include/node/v8-embedder-state-scope.h +52 -0
  81. package/include/node/v8-exception.h +298 -0
  82. package/include/node/v8-extension.h +60 -0
  83. package/include/node/v8-external-memory-accounter.h +60 -0
  84. package/include/node/v8-external.h +73 -0
  85. package/include/node/v8-fast-api-calls.h +784 -0
  86. package/include/node/v8-forward.h +82 -0
  87. package/include/node/v8-function-callback.h +708 -0
  88. package/include/node/v8-function.h +148 -0
  89. package/include/node/v8-handle-base.h +155 -0
  90. package/include/node/v8-initialization.h +343 -0
  91. package/include/node/v8-inspector-protocol.h +13 -0
  92. package/include/node/v8-inspector.h +458 -0
  93. package/include/node/v8-internal.h +1827 -0
  94. package/include/node/v8-isolate.h +1925 -0
  95. package/include/node/v8-json.h +54 -0
  96. package/include/node/v8-local-handle.h +884 -0
  97. package/include/node/v8-locker.h +138 -0
  98. package/include/node/v8-maybe.h +185 -0
  99. package/include/node/v8-memory-span.h +273 -0
  100. package/include/node/v8-message.h +215 -0
  101. package/include/node/v8-metrics.h +273 -0
  102. package/include/node/v8-microtask-queue.h +152 -0
  103. package/include/node/v8-microtask.h +28 -0
  104. package/include/node/v8-object.h +1134 -0
  105. package/include/node/v8-persistent-handle.h +556 -0
  106. package/include/node/v8-platform.h +1552 -0
  107. package/include/node/v8-primitive-object.h +118 -0
  108. package/include/node/v8-primitive.h +1056 -0
  109. package/include/node/v8-profiler.h +1401 -0
  110. package/include/node/v8-promise.h +185 -0
  111. package/include/node/v8-proxy.h +49 -0
  112. package/include/node/v8-regexp.h +105 -0
  113. package/include/node/v8-sandbox.h +170 -0
  114. package/include/node/v8-script.h +996 -0
  115. package/include/node/v8-snapshot.h +302 -0
  116. package/include/node/v8-source-location.h +91 -0
  117. package/include/node/v8-statistics.h +246 -0
  118. package/include/node/v8-template.h +1096 -0
  119. package/include/node/v8-trace-categories.h +28 -0
  120. package/include/node/v8-traced-handle.h +420 -0
  121. package/include/node/v8-typed-array.h +386 -0
  122. package/include/node/v8-unwinder-state.h +30 -0
  123. package/include/node/v8-unwinder.h +146 -0
  124. package/include/node/v8-util.h +549 -0
  125. package/include/node/v8-value-serializer-version.h +24 -0
  126. package/include/node/v8-value-serializer.h +316 -0
  127. package/include/node/v8-value.h +674 -0
  128. package/include/node/v8-version-string.h +38 -0
  129. package/include/node/v8-version.h +20 -0
  130. package/include/node/v8-wasm-trap-handler-posix.h +31 -0
  131. package/include/node/v8-wasm-trap-handler-win.h +28 -0
  132. package/include/node/v8-wasm.h +325 -0
  133. package/include/node/v8-weak-callback-info.h +88 -0
  134. package/include/node/v8.h +88 -0
  135. package/include/node/v8config.h +1077 -0
  136. package/lib/libc++_shared.so +0 -0
  137. package/lib/libnode.so +4 -0
  138. package/package.json +23 -3
@@ -0,0 +1,1401 @@
1
+ // Copyright 2010 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_V8_PROFILER_H_
6
+ #define V8_V8_PROFILER_H_
7
+
8
+ #include <limits.h>
9
+
10
+ #include <memory>
11
+ #include <unordered_set>
12
+ #include <vector>
13
+
14
+ #include "cppgc/common.h" // NOLINT(build/include_directory)
15
+ #include "v8-local-handle.h" // NOLINT(build/include_directory)
16
+ #include "v8-message.h" // NOLINT(build/include_directory)
17
+ #include "v8-persistent-handle.h" // NOLINT(build/include_directory)
18
+
19
+ /**
20
+ * Profiler support for the V8 JavaScript engine.
21
+ */
22
+ namespace v8 {
23
+
24
+ enum class EmbedderStateTag : uint8_t;
25
+ class HeapGraphNode;
26
+ struct HeapStatsUpdate;
27
+ class Object;
28
+ enum StateTag : uint16_t;
29
+
30
+ using NativeObject = void*;
31
+ using SnapshotObjectId = uint32_t;
32
+ using ProfilerId = uint32_t;
33
+
34
+ struct CpuProfileDeoptFrame {
35
+ int script_id;
36
+ size_t position;
37
+ };
38
+
39
+ namespace internal {
40
+ class CpuProfile;
41
+ } // namespace internal
42
+
43
+ } // namespace v8
44
+
45
+ #ifdef V8_OS_WIN
46
+ template class V8_EXPORT std::vector<v8::CpuProfileDeoptFrame>;
47
+ #endif
48
+
49
+ namespace v8 {
50
+
51
+ /**
52
+ * Identifies which component initiated CPU profiling for proper attribution.
53
+ */
54
+ enum class CpuProfileSource : uint8_t {
55
+ /** Default value when no explicit source is specified. */
56
+ kUnspecified = 0,
57
+ /** Profiling initiated via the DevTools Inspector protocol. */
58
+ kInspector = 1,
59
+ /** Profiling initiated by the embedder (e.g., Blink) via self-profiling API.
60
+ */
61
+ kSelfProfiling = 2,
62
+ /** Profiling initiated internally by V8 (e.g., tracing CPU profiler). */
63
+ kInternal = 3,
64
+ };
65
+
66
+ struct V8_EXPORT CpuProfileDeoptInfo {
67
+ /** A pointer to a static string owned by v8. */
68
+ const char* deopt_reason;
69
+ std::vector<CpuProfileDeoptFrame> stack;
70
+ };
71
+
72
+ } // namespace v8
73
+
74
+ #ifdef V8_OS_WIN
75
+ template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
76
+ #endif
77
+
78
+ namespace v8 {
79
+
80
+ /**
81
+ * CpuProfileNode represents a node in a call graph.
82
+ */
83
+ class V8_EXPORT CpuProfileNode {
84
+ public:
85
+ struct LineTick {
86
+ /** The 1-based number of the source line where the function originates. */
87
+ int line;
88
+
89
+ /** The 1-based number of the source column where the function originates.
90
+ */
91
+ int column;
92
+
93
+ /** The count of samples associated with the source line. */
94
+ unsigned int hit_count;
95
+ };
96
+
97
+ // An annotation hinting at the source of a CpuProfileNode.
98
+ enum SourceType {
99
+ // User-supplied script with associated resource information.
100
+ kScript = 0,
101
+ // Native scripts and provided builtins.
102
+ kBuiltin = 1,
103
+ // Callbacks into native code.
104
+ kCallback = 2,
105
+ // VM-internal functions or state.
106
+ kInternal = 3,
107
+ // A node that failed to symbolize.
108
+ kUnresolved = 4,
109
+ };
110
+
111
+ /** Returns function name (empty string for anonymous functions.) */
112
+ Local<String> GetFunctionName() const;
113
+
114
+ /**
115
+ * Returns function name (empty string for anonymous functions.)
116
+ * The string ownership is *not* passed to the caller. It stays valid until
117
+ * profile is deleted. The function is thread safe.
118
+ */
119
+ const char* GetFunctionNameStr() const;
120
+
121
+ /** Returns id of the script where function is located. */
122
+ int GetScriptId() const;
123
+
124
+ /** Returns resource name for script from where the function originates. */
125
+ Local<String> GetScriptResourceName() const;
126
+
127
+ /**
128
+ * Returns resource name for script from where the function originates.
129
+ * The string ownership is *not* passed to the caller. It stays valid until
130
+ * profile is deleted. The function is thread safe.
131
+ */
132
+ const char* GetScriptResourceNameStr() const;
133
+
134
+ /**
135
+ * Return true if the script from where the function originates is flagged as
136
+ * being shared cross-origin.
137
+ */
138
+ bool IsScriptSharedCrossOrigin() const;
139
+
140
+ /**
141
+ * Returns the number, 1-based, of the line where the function originates.
142
+ * kNoLineNumberInfo if no line number information is available.
143
+ */
144
+ int GetLineNumber() const;
145
+
146
+ /**
147
+ * Returns 1-based number of the column where the function originates.
148
+ * kNoColumnNumberInfo if no column number information is available.
149
+ */
150
+ int GetColumnNumber() const;
151
+
152
+ /**
153
+ * Returns the number of the function's source lines that collect the samples.
154
+ */
155
+ unsigned int GetHitLineCount() const;
156
+
157
+ /** Returns the set of source lines that collect the samples.
158
+ * The caller allocates buffer and responsible for releasing it.
159
+ * True if all available entries are copied, otherwise false.
160
+ * The function copies nothing if buffer is not large enough.
161
+ */
162
+ bool GetLineTicks(LineTick* entries, unsigned int length) const;
163
+
164
+ /** Returns bailout reason for the function
165
+ * if the optimization was disabled for it.
166
+ */
167
+ const char* GetBailoutReason() const;
168
+
169
+ /**
170
+ * Returns the count of samples where the function was currently executing.
171
+ */
172
+ unsigned GetHitCount() const;
173
+
174
+ /** Returns id of the node. The id is unique within the tree */
175
+ unsigned GetNodeId() const;
176
+
177
+ /**
178
+ * Gets the type of the source which the node was captured from.
179
+ */
180
+ SourceType GetSourceType() const;
181
+
182
+ /** Returns child nodes count of the node. */
183
+ int GetChildrenCount() const;
184
+
185
+ /** Retrieves a child node by index. */
186
+ const CpuProfileNode* GetChild(int index) const;
187
+
188
+ /** Retrieves the ancestor node, or null if the root. */
189
+ const CpuProfileNode* GetParent() const;
190
+
191
+ /** Retrieves deopt infos for the node. */
192
+ const std::vector<CpuProfileDeoptInfo>& GetDeoptInfos() const;
193
+
194
+ static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
195
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
196
+ };
197
+
198
+ /**
199
+ * An interface for exporting data from V8, using "push" model.
200
+ */
201
+ class V8_EXPORT OutputStream {
202
+ public:
203
+ enum WriteResult { kContinue = 0, kAbort = 1 };
204
+ virtual ~OutputStream() = default;
205
+ /** Notify about the end of stream. */
206
+ virtual void EndOfStream() = 0;
207
+ /** Get preferred output chunk size. Called only once. */
208
+ virtual int GetChunkSize() { return 1024; }
209
+ /**
210
+ * Writes the next chunk of snapshot data into the stream. Writing
211
+ * can be stopped by returning kAbort as function result. EndOfStream
212
+ * will not be called in case writing was aborted.
213
+ */
214
+ virtual WriteResult WriteAsciiChunk(char* data, int size) = 0;
215
+ /**
216
+ * Writes the next chunk of heap stats data into the stream. Writing
217
+ * can be stopped by returning kAbort as function result. EndOfStream
218
+ * will not be called in case writing was aborted.
219
+ */
220
+ virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
221
+ return kAbort;
222
+ }
223
+ };
224
+
225
+ /**
226
+ * CpuProfile contains a CPU profile in a form of top-down call tree
227
+ * (from main() down to functions that do all the work).
228
+ */
229
+ class V8_EXPORT CpuProfile {
230
+ public:
231
+ enum SerializationFormat {
232
+ kJSON = 0 // See format description near 'Serialize' method.
233
+ };
234
+ /** Returns CPU profile title. */
235
+ Local<String> GetTitle() const;
236
+
237
+ /** Returns the root node of the top down call tree. */
238
+ const CpuProfileNode* GetTopDownRoot() const;
239
+
240
+ /**
241
+ * Returns number of samples recorded. The samples are not recorded unless
242
+ * |record_samples| parameter of CpuProfiler::StartCpuProfiling is true.
243
+ */
244
+ int GetSamplesCount() const;
245
+
246
+ /**
247
+ * Returns profile node corresponding to the top frame the sample at
248
+ * the given index.
249
+ */
250
+ const CpuProfileNode* GetSample(int index) const;
251
+
252
+ /**
253
+ * Returns the timestamp of the sample. The timestamp is the number of
254
+ * microseconds since some unspecified starting point.
255
+ * The point is equal to the starting point used by GetStartTime.
256
+ */
257
+ int64_t GetSampleTimestamp(int index) const;
258
+
259
+ /**
260
+ * Returns time when the profile recording was started (in microseconds)
261
+ * since some unspecified starting point.
262
+ */
263
+ int64_t GetStartTime() const;
264
+
265
+ /**
266
+ * Returns state of the vm when sample was captured.
267
+ */
268
+ StateTag GetSampleState(int index) const;
269
+
270
+ /**
271
+ * Returns state of the embedder when sample was captured.
272
+ */
273
+ EmbedderStateTag GetSampleEmbedderState(int index) const;
274
+
275
+ /**
276
+ * Returns time when the profile recording was stopped (in microseconds)
277
+ * since some unspecified starting point.
278
+ * The point is equal to the starting point used by GetStartTime.
279
+ */
280
+ int64_t GetEndTime() const;
281
+
282
+ /**
283
+ * Deletes the profile and removes it from CpuProfiler's list.
284
+ * All pointers to nodes previously returned become invalid.
285
+ */
286
+ void Delete();
287
+
288
+ /**
289
+ * Prepare a serialized representation of the profile. The result
290
+ * is written into the stream provided in chunks of specified size.
291
+ *
292
+ * For the JSON format, heap contents are represented as an object
293
+ * with the following structure:
294
+ *
295
+ * {
296
+ * nodes: [nodes array],
297
+ * startTime: number,
298
+ * endTime: number
299
+ * samples: [strings array]
300
+ * timeDeltas: [numbers array]
301
+ * }
302
+ *
303
+ */
304
+ void Serialize(OutputStream* stream,
305
+ SerializationFormat format = kJSON) const;
306
+ };
307
+
308
+ enum CpuProfilingMode {
309
+ // In the resulting CpuProfile tree, intermediate nodes in a stack trace
310
+ // (from the root to a leaf) will have line numbers that point to the start
311
+ // line of the function, rather than the line of the callsite of the child.
312
+ kLeafNodeLineNumbers,
313
+ // In the resulting CpuProfile tree, nodes are separated based on the line
314
+ // number of their callsite in their parent.
315
+ kCallerLineNumbers,
316
+ };
317
+
318
+ // Determines how names are derived for functions sampled.
319
+ enum CpuProfilingNamingMode {
320
+ // Use the immediate name of functions at compilation time.
321
+ kStandardNaming,
322
+ // Use more verbose naming for functions without names, inferred from scope
323
+ // where possible.
324
+ kDebugNaming,
325
+ };
326
+
327
+ enum CpuProfilingLoggingMode {
328
+ // Enables logging when a profile is active, and disables logging when all
329
+ // profiles are detached.
330
+ kLazyLogging,
331
+ // Enables logging for the lifetime of the CpuProfiler. Calls to
332
+ // StartRecording are faster, at the expense of runtime overhead.
333
+ kEagerLogging,
334
+ };
335
+
336
+ // Enum for returning profiling status. Once StartProfiling is called,
337
+ // we want to return to clients whether the profiling was able to start
338
+ // correctly, or return a descriptive error.
339
+ enum class CpuProfilingStatus {
340
+ kStarted,
341
+ kAlreadyStarted,
342
+ kErrorTooManyProfilers
343
+ };
344
+
345
+ /**
346
+ * Result from StartProfiling returning the Profiling Status, and
347
+ * id of the started profiler, or 0 if profiler is not started
348
+ */
349
+ struct CpuProfilingResult {
350
+ const ProfilerId id;
351
+ const CpuProfilingStatus status;
352
+ };
353
+
354
+ /**
355
+ * Delegate for when max samples reached and samples are discarded.
356
+ */
357
+ class V8_EXPORT DiscardedSamplesDelegate {
358
+ public:
359
+ DiscardedSamplesDelegate() = default;
360
+
361
+ virtual ~DiscardedSamplesDelegate() = default;
362
+ virtual void Notify() = 0;
363
+
364
+ ProfilerId GetId() const { return profiler_id_; }
365
+
366
+ private:
367
+ friend internal::CpuProfile;
368
+
369
+ void SetId(ProfilerId id) { profiler_id_ = id; }
370
+
371
+ ProfilerId profiler_id_;
372
+ };
373
+
374
+ /**
375
+ * Optional profiling attributes.
376
+ */
377
+ class V8_EXPORT CpuProfilingOptions {
378
+ public:
379
+ // Indicates that the sample buffer size should not be explicitly limited.
380
+ static const unsigned kNoSampleLimit = UINT_MAX;
381
+
382
+ /**
383
+ * \param mode Type of computation of stack frame line numbers.
384
+ * \param max_samples The maximum number of samples that should be recorded by
385
+ * the profiler. Samples obtained after this limit will be
386
+ * discarded.
387
+ * \param sampling_interval_us controls the profile-specific target
388
+ * sampling interval. The provided sampling
389
+ * interval will be snapped to the next lowest
390
+ * non-zero multiple of the profiler's sampling
391
+ * interval, set via SetSamplingInterval(). If
392
+ * zero, the sampling interval will be equal to
393
+ * the profiler's sampling interval.
394
+ * \param filter_context If specified, profiles will only contain frames
395
+ * using this context. Other frames will be elided.
396
+ * \param profile_source Identifies the source of this CPU profile.
397
+ */
398
+ CpuProfilingOptions(
399
+ CpuProfilingMode mode = kLeafNodeLineNumbers,
400
+ unsigned max_samples = kNoSampleLimit, int sampling_interval_us = 0,
401
+ MaybeLocal<Context> filter_context = MaybeLocal<Context>(),
402
+ CpuProfileSource profile_source = CpuProfileSource::kUnspecified);
403
+
404
+ CpuProfilingOptions(CpuProfilingOptions&&) = default;
405
+ CpuProfilingOptions& operator=(CpuProfilingOptions&&) = default;
406
+
407
+ CpuProfilingMode mode() const { return mode_; }
408
+ unsigned max_samples() const { return max_samples_; }
409
+ int sampling_interval_us() const { return sampling_interval_us_; }
410
+ CpuProfileSource profile_source() const { return profile_source_; }
411
+
412
+ private:
413
+ friend class internal::CpuProfile;
414
+
415
+ bool has_filter_context() const { return !filter_context_.IsEmpty(); }
416
+ void* raw_filter_context() const;
417
+
418
+ CpuProfilingMode mode_;
419
+ unsigned max_samples_;
420
+ int sampling_interval_us_;
421
+ Global<Context> filter_context_;
422
+ CpuProfileSource profile_source_;
423
+ };
424
+
425
+ /**
426
+ * Interface for controlling CPU profiling. Instance of the
427
+ * profiler can be created using v8::CpuProfiler::New method.
428
+ */
429
+ class V8_EXPORT CpuProfiler {
430
+ public:
431
+ /**
432
+ * Creates a new CPU profiler for the |isolate|. The isolate must be
433
+ * initialized. The profiler object must be disposed after use by calling
434
+ * |Dispose| method.
435
+ */
436
+ static CpuProfiler* New(Isolate* isolate,
437
+ CpuProfilingNamingMode = kDebugNaming,
438
+ CpuProfilingLoggingMode = kLazyLogging);
439
+
440
+ /**
441
+ * Synchronously collect current stack sample in all profilers attached to
442
+ * the |isolate|. The call does not affect number of ticks recorded for
443
+ * the current top node.
444
+ * |trace_id| is an optional identifier set to the collected sample.
445
+ * this is useful to associate the sample with a trace event.
446
+ */
447
+ static void CollectSample(
448
+ Isolate* isolate, const std::optional<uint64_t> trace_id = std::nullopt);
449
+
450
+ /**
451
+ * Disposes the CPU profiler object.
452
+ */
453
+ void Dispose();
454
+
455
+ /**
456
+ * Changes default CPU profiler sampling interval to the specified number
457
+ * of microseconds. Default interval is 1000us. This method must be called
458
+ * when there are no profiles being recorded.
459
+ */
460
+ void SetSamplingInterval(int us);
461
+
462
+ /**
463
+ * Sets whether or not the profiler should prioritize consistency of sample
464
+ * periodicity on Windows. Disabling this can greatly reduce CPU usage, but
465
+ * may result in greater variance in sample timings from the platform's
466
+ * scheduler. Defaults to enabled. This method must be called when there are
467
+ * no profiles being recorded.
468
+ */
469
+ void SetUsePreciseSampling(bool);
470
+
471
+ /**
472
+ * Starts collecting a CPU profile. Several profiles may be collected at once.
473
+ * Generates an anonymous profiler, without a String identifier.
474
+ */
475
+ CpuProfilingResult Start(
476
+ CpuProfilingOptions options,
477
+ std::unique_ptr<DiscardedSamplesDelegate> delegate = nullptr);
478
+
479
+ /**
480
+ * Starts collecting a CPU profile. Title may be an empty string. Several
481
+ * profiles may be collected at once. Attempts to start collecting several
482
+ * profiles with the same title are silently ignored.
483
+ */
484
+ CpuProfilingResult Start(
485
+ Local<String> title, CpuProfilingOptions options,
486
+ std::unique_ptr<DiscardedSamplesDelegate> delegate = nullptr);
487
+
488
+ /**
489
+ * Starts profiling with the same semantics as above, except with expanded
490
+ * parameters.
491
+ *
492
+ * |record_samples| parameter controls whether individual samples should
493
+ * be recorded in addition to the aggregated tree.
494
+ *
495
+ * |max_samples| controls the maximum number of samples that should be
496
+ * recorded by the profiler. Samples obtained after this limit will be
497
+ * discarded.
498
+ */
499
+ CpuProfilingResult Start(
500
+ Local<String> title, CpuProfilingMode mode, bool record_samples = false,
501
+ unsigned max_samples = CpuProfilingOptions::kNoSampleLimit);
502
+
503
+ /**
504
+ * The same as StartProfiling above, but the CpuProfilingMode defaults to
505
+ * kLeafNodeLineNumbers mode, which was the previous default behavior of the
506
+ * profiler.
507
+ */
508
+ CpuProfilingResult Start(Local<String> title, bool record_samples = false);
509
+
510
+ /**
511
+ * Starts collecting a CPU profile. Title may be an empty string. Several
512
+ * profiles may be collected at once. Attempts to start collecting several
513
+ * profiles with the same title are silently ignored.
514
+ */
515
+ CpuProfilingStatus StartProfiling(
516
+ Local<String> title, CpuProfilingOptions options,
517
+ std::unique_ptr<DiscardedSamplesDelegate> delegate = nullptr);
518
+
519
+ /**
520
+ * Starts profiling with the same semantics as above, except with expanded
521
+ * parameters.
522
+ *
523
+ * |record_samples| parameter controls whether individual samples should
524
+ * be recorded in addition to the aggregated tree.
525
+ *
526
+ * |max_samples| controls the maximum number of samples that should be
527
+ * recorded by the profiler. Samples obtained after this limit will be
528
+ * discarded.
529
+ */
530
+ CpuProfilingStatus StartProfiling(
531
+ Local<String> title, CpuProfilingMode mode, bool record_samples = false,
532
+ unsigned max_samples = CpuProfilingOptions::kNoSampleLimit);
533
+
534
+ /**
535
+ * The same as StartProfiling above, but the CpuProfilingMode defaults to
536
+ * kLeafNodeLineNumbers mode, which was the previous default behavior of the
537
+ * profiler.
538
+ */
539
+ CpuProfilingStatus StartProfiling(Local<String> title,
540
+ bool record_samples = false);
541
+
542
+ /**
543
+ * Stops collecting CPU profile with a given id and returns it.
544
+ */
545
+ CpuProfile* Stop(ProfilerId id);
546
+
547
+ /**
548
+ * Stops collecting CPU profile with a given title and returns it.
549
+ * If the title given is empty, finishes the last profile started.
550
+ */
551
+ CpuProfile* StopProfiling(Local<String> title);
552
+
553
+ /**
554
+ * Generate more detailed source positions to code objects. This results in
555
+ * better results when mapping profiling samples to script source.
556
+ */
557
+ static void UseDetailedSourcePositionsForProfiling(Isolate* isolate);
558
+
559
+ private:
560
+ CpuProfiler();
561
+ ~CpuProfiler();
562
+ CpuProfiler(const CpuProfiler&);
563
+ CpuProfiler& operator=(const CpuProfiler&);
564
+ };
565
+
566
+ /**
567
+ * HeapSnapshotEdge represents a directed connection between heap
568
+ * graph nodes: from retainers to retained nodes.
569
+ */
570
+ class V8_EXPORT HeapGraphEdge {
571
+ public:
572
+ enum Type {
573
+ kContextVariable = 0, // A variable from a function context.
574
+ kElement = 1, // An element of an array.
575
+ kProperty = 2, // A named object property.
576
+ kInternal = 3, // A link that can't be accessed from JS,
577
+ // thus, its name isn't a real property name
578
+ // (e.g. parts of a ConsString).
579
+ kHidden = 4, // A link that is needed for proper sizes
580
+ // calculation, but may be hidden from user.
581
+ kShortcut = 5, // A link that must not be followed during
582
+ // sizes calculation.
583
+ kWeak = 6 // A weak reference (ignored by the GC).
584
+ };
585
+
586
+ /** Returns edge type (see HeapGraphEdge::Type). */
587
+ Type GetType() const;
588
+
589
+ /**
590
+ * Returns edge name. This can be a variable name, an element index, or
591
+ * a property name.
592
+ */
593
+ Local<Value> GetName() const;
594
+
595
+ /** Returns origin node. */
596
+ const HeapGraphNode* GetFromNode() const;
597
+
598
+ /** Returns destination node. */
599
+ const HeapGraphNode* GetToNode() const;
600
+ };
601
+
602
+
603
+ /**
604
+ * HeapGraphNode represents a node in a heap graph.
605
+ */
606
+ class V8_EXPORT HeapGraphNode {
607
+ public:
608
+ enum Type {
609
+ kHidden = 0, // Hidden node, may be filtered when shown to user.
610
+ kArray = 1, // An array of elements.
611
+ kString = 2, // A string.
612
+ kObject = 3, // A JS object (except for arrays and strings).
613
+ kCode = 4, // Compiled code.
614
+ kClosure = 5, // Function closure.
615
+ kRegExp = 6, // RegExp.
616
+ kHeapNumber = 7, // Number stored in the heap.
617
+ kNative = 8, // Native object (not from V8 heap).
618
+ kSynthetic = 9, // Synthetic object, usually used for grouping
619
+ // snapshot items together.
620
+ kConsString = 10, // Concatenated string. A pair of pointers to strings.
621
+ kSlicedString = 11, // Sliced string. A fragment of another string.
622
+ kSymbol = 12, // A Symbol (ES6).
623
+ kBigInt = 13, // BigInt.
624
+ kObjectShape = 14, // Internal data used for tracking the shapes (or
625
+ // "hidden classes") of JS objects.
626
+ };
627
+
628
+ /** Returns node type (see HeapGraphNode::Type). */
629
+ Type GetType() const;
630
+
631
+ /**
632
+ * Returns node name. Depending on node's type this can be the name
633
+ * of the constructor (for objects), the name of the function (for
634
+ * closures), string value, or an empty string (for compiled code).
635
+ */
636
+ Local<String> GetName() const;
637
+
638
+ /**
639
+ * Returns node id. For the same heap object, the id remains the same
640
+ * across all snapshots.
641
+ */
642
+ SnapshotObjectId GetId() const;
643
+
644
+ /** Returns node's own size, in bytes. */
645
+ size_t GetShallowSize() const;
646
+
647
+ /** Returns child nodes count of the node. */
648
+ int GetChildrenCount() const;
649
+
650
+ /** Retrieves a child by index. */
651
+ const HeapGraphEdge* GetChild(int index) const;
652
+ };
653
+
654
+ /**
655
+ * HeapSnapshots record the state of the JS heap at some moment.
656
+ */
657
+ class V8_EXPORT HeapSnapshot {
658
+ public:
659
+ enum SerializationFormat {
660
+ kJSON = 0 // See format description near 'Serialize' method.
661
+ };
662
+
663
+ /** Returns the root node of the heap graph. */
664
+ const HeapGraphNode* GetRoot() const;
665
+
666
+ /** Returns a node by its id. */
667
+ const HeapGraphNode* GetNodeById(SnapshotObjectId id) const;
668
+
669
+ /** Returns total nodes count in the snapshot. */
670
+ int GetNodesCount() const;
671
+
672
+ /** Returns a node by index. */
673
+ const HeapGraphNode* GetNode(int index) const;
674
+
675
+ /** Returns a max seen JS object Id. */
676
+ SnapshotObjectId GetMaxSnapshotJSObjectId() const;
677
+
678
+ /**
679
+ * Deletes the snapshot and removes it from HeapProfiler's list.
680
+ * All pointers to nodes, edges and paths previously returned become
681
+ * invalid.
682
+ */
683
+ void Delete();
684
+
685
+ /**
686
+ * Prepare a serialized representation of the snapshot. The result
687
+ * is written into the stream provided in chunks of specified size.
688
+ * The total length of the serialized snapshot is unknown in
689
+ * advance, it can be roughly equal to JS heap size (that means,
690
+ * it can be really big - tens of megabytes).
691
+ *
692
+ * For the JSON format, heap contents are represented as an object
693
+ * with the following structure:
694
+ *
695
+ * {
696
+ * snapshot: {
697
+ * title: "...",
698
+ * uid: nnn,
699
+ * meta: { meta-info },
700
+ * node_count: nnn,
701
+ * edge_count: nnn
702
+ * },
703
+ * nodes: [nodes array],
704
+ * edges: [edges array],
705
+ * strings: [strings array]
706
+ * }
707
+ *
708
+ * Nodes reference strings, other nodes, and edges by their indexes
709
+ * in corresponding arrays.
710
+ */
711
+ void Serialize(OutputStream* stream,
712
+ SerializationFormat format = kJSON) const;
713
+ };
714
+
715
+
716
+ /**
717
+ * An interface for reporting progress and controlling long-running
718
+ * activities.
719
+ */
720
+ class V8_EXPORT ActivityControl {
721
+ public:
722
+ enum ControlOption {
723
+ kContinue = 0,
724
+ kAbort = 1
725
+ };
726
+ virtual ~ActivityControl() = default;
727
+ /**
728
+ * Notify about current progress. The activity can be stopped by
729
+ * returning kAbort as the callback result.
730
+ */
731
+ virtual ControlOption ReportProgressValue(uint32_t done, uint32_t total) = 0;
732
+ };
733
+
734
+ /**
735
+ * AllocationProfile is a sampled profile of allocations done by the program.
736
+ * This is structured as a call-graph.
737
+ */
738
+ class V8_EXPORT AllocationProfile {
739
+ public:
740
+ struct Allocation {
741
+ /**
742
+ * Size of the sampled allocation object.
743
+ */
744
+ size_t size;
745
+
746
+ /**
747
+ * The number of objects of such size that were sampled.
748
+ */
749
+ unsigned int count;
750
+ };
751
+
752
+ /**
753
+ * Represents a node in the call-graph.
754
+ */
755
+ struct Node {
756
+ /**
757
+ * Name of the function. May be empty for anonymous functions or if the
758
+ * script corresponding to this function has been unloaded.
759
+ */
760
+ Local<String> name;
761
+
762
+ /**
763
+ * Name of the script containing the function. May be empty if the script
764
+ * name is not available, or if the script has been unloaded.
765
+ */
766
+ Local<String> script_name;
767
+
768
+ /**
769
+ * id of the script where the function is located. May be equal to
770
+ * v8::UnboundScript::kNoScriptId in cases where the script doesn't exist.
771
+ */
772
+ int script_id;
773
+
774
+ /**
775
+ * Start position of the function in the script.
776
+ */
777
+ int start_position;
778
+
779
+ /**
780
+ * 1-indexed line number where the function starts. May be
781
+ * kNoLineNumberInfo if no line number information is available.
782
+ */
783
+ int line_number;
784
+
785
+ /**
786
+ * 1-indexed column number where the function starts. May be
787
+ * kNoColumnNumberInfo if no line number information is available.
788
+ */
789
+ int column_number;
790
+
791
+ /**
792
+ * Unique id of the node.
793
+ */
794
+ uint32_t node_id;
795
+
796
+ /**
797
+ * List of callees called from this node for which we have sampled
798
+ * allocations. The lifetime of the children is scoped to the containing
799
+ * AllocationProfile.
800
+ */
801
+ std::vector<Node*> children;
802
+
803
+ /**
804
+ * List of self allocations done by this node in the call-graph.
805
+ */
806
+ std::vector<Allocation> allocations;
807
+ };
808
+
809
+ /**
810
+ * Represent a single sample recorded for an allocation.
811
+ */
812
+ struct Sample {
813
+ /**
814
+ * id of the node in the profile tree.
815
+ */
816
+ uint32_t node_id;
817
+
818
+ /**
819
+ * Size of the sampled allocation object.
820
+ */
821
+ size_t size;
822
+
823
+ /**
824
+ * The number of objects of such size that were sampled.
825
+ */
826
+ unsigned int count;
827
+
828
+ /**
829
+ * Unique time-ordered id of the allocation sample. Can be used to track
830
+ * what samples were added or removed between two snapshots.
831
+ */
832
+ uint64_t sample_id;
833
+
834
+ /**
835
+ * Indicates whether the sampled allocation is still live or has already
836
+ * been collected by GC.
837
+ */
838
+ bool is_live;
839
+ };
840
+
841
+ /**
842
+ * Returns the root node of the call-graph. The root node corresponds to an
843
+ * empty JS call-stack. The lifetime of the returned Node* is scoped to the
844
+ * containing AllocationProfile.
845
+ */
846
+ virtual Node* GetRootNode() = 0;
847
+ virtual const std::vector<Sample>& GetSamples() = 0;
848
+
849
+ virtual ~AllocationProfile() = default;
850
+
851
+ static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
852
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
853
+ };
854
+
855
+ /**
856
+ * An object graph consisting of embedder objects and V8 objects.
857
+ * Edges of the graph are strong references between the objects.
858
+ * The embedder can build this graph during heap snapshot generation
859
+ * to include the embedder objects in the heap snapshot.
860
+ * Usage:
861
+ * 1) Define derived class of EmbedderGraph::Node for embedder objects.
862
+ * 2) Set the build embedder graph callback on the heap profiler using
863
+ * HeapProfiler::AddBuildEmbedderGraphCallback.
864
+ * 3) In the callback use graph->AddEdge(node1, node2) to add an edge from
865
+ * node1 to node2.
866
+ * 4) To represent references from/to V8 object, construct V8 nodes using
867
+ * graph->V8Node(value).
868
+ */
869
+ class V8_EXPORT EmbedderGraph {
870
+ public:
871
+ class Node {
872
+ public:
873
+ /**
874
+ * Detachedness specifies whether an object is attached or detached from the
875
+ * main application state. While unkown in general, there may be objects
876
+ * that specifically know their state. V8 passes this information along in
877
+ * the snapshot. Users of the snapshot may use it to annotate the object
878
+ * graph.
879
+ */
880
+ enum class Detachedness : uint8_t {
881
+ kUnknown = 0,
882
+ kAttached = 1,
883
+ kDetached = 2,
884
+ };
885
+
886
+ Node() = default;
887
+ virtual ~Node() = default;
888
+ virtual const char* Name() = 0;
889
+ virtual size_t SizeInBytes() = 0;
890
+ /**
891
+ * The corresponding V8 wrapper node if not null.
892
+ * During heap snapshot generation the embedder node and the V8 wrapper
893
+ * node will be merged into one node to simplify retaining paths.
894
+ */
895
+ virtual Node* WrapperNode() { return nullptr; }
896
+ virtual bool IsRootNode() { return false; }
897
+ /** Must return true for non-V8 nodes. */
898
+ virtual bool IsEmbedderNode() { return true; }
899
+ /**
900
+ * Optional name prefix. It is used in Chrome for tagging detached nodes.
901
+ */
902
+ virtual const char* NamePrefix() { return nullptr; }
903
+
904
+ /**
905
+ * Returns the NativeObject that can be used for querying the
906
+ * |HeapSnapshot|.
907
+ */
908
+ virtual NativeObject GetNativeObject() { return nullptr; }
909
+
910
+ /**
911
+ * Detachedness state of a given object. While unkown in general, there may
912
+ * be objects that specifically know their state. V8 passes this information
913
+ * along in the snapshot. Users of the snapshot may use it to annotate the
914
+ * object graph.
915
+ */
916
+ virtual Detachedness GetDetachedness() { return Detachedness::kUnknown; }
917
+
918
+ /**
919
+ * Returns the address of the object in the embedder heap, or nullptr to not
920
+ * specify the address. If this address is provided, then V8 can generate
921
+ * consistent IDs for objects across subsequent heap snapshots, which allows
922
+ * devtools to determine which objects were retained from one snapshot to
923
+ * the next. This value is used only if GetNativeObject returns nullptr.
924
+ */
925
+ virtual const void* GetAddress() { return nullptr; }
926
+
927
+ Node(const Node&) = delete;
928
+ Node& operator=(const Node&) = delete;
929
+ };
930
+
931
+ /**
932
+ * Returns a node corresponding to the given V8 value. Ownership is not
933
+ * transferred. The result pointer is valid while the graph is alive.
934
+ *
935
+ * For now the variant that takes v8::Data is not marked as abstract for
936
+ * compatibility, but embedders who subclass EmbedderGraph are expected to
937
+ * implement it. Then in the implementation of the variant that takes
938
+ * v8::Value, they can simply forward the call to the one that takes
939
+ * v8::Local<v8::Data>.
940
+ */
941
+ virtual Node* V8Node(const v8::Local<v8::Value>& value) = 0;
942
+
943
+ /**
944
+ * Returns a node corresponding to the given V8 value. Ownership is not
945
+ * transferred. The result pointer is valid while the graph is alive.
946
+ *
947
+ * For API compatibility, this default implementation just checks that the
948
+ * data is a v8::Value and forward it to the variant that takes v8::Value,
949
+ * which is currently required to be implemented. In the future we'll remove
950
+ * the v8::Value variant, and make this variant that takes v8::Data abstract
951
+ * instead. If the embedder subclasses v8::EmbedderGraph and also use
952
+ * v8::TracedReference<v8::Data>, they must override this variant.
953
+ */
954
+ virtual Node* V8Node(const v8::Local<v8::Data>& value);
955
+
956
+ /**
957
+ * Adds the given node to the graph and takes ownership of the node.
958
+ * Returns a raw pointer to the node that is valid while the graph is alive.
959
+ */
960
+ virtual Node* AddNode(std::unique_ptr<Node> node) = 0;
961
+
962
+ /**
963
+ * Adds an edge that represents a strong reference from the given
964
+ * node |from| to the given node |to|. The nodes must be added to the graph
965
+ * before calling this function.
966
+ *
967
+ * If name is nullptr, the edge will have auto-increment indexes, otherwise
968
+ * it will be named accordingly.
969
+ */
970
+ virtual void AddEdge(Node* from, Node* to, const char* name = nullptr) = 0;
971
+
972
+ /**
973
+ * Adds a count of bytes that are not associated with any particular Node.
974
+ * An embedder may use this to represent the size of nodes which were omitted
975
+ * from this EmbedderGraph despite being retained by the graph, or other
976
+ * overhead costs. This number will contribute to the total size in a heap
977
+ * snapshot, without being represented in the object graph.
978
+ */
979
+ virtual void AddNativeSize(size_t size) {}
980
+
981
+ virtual ~EmbedderGraph() = default;
982
+ };
983
+
984
+ class QueryObjectPredicate {
985
+ public:
986
+ virtual ~QueryObjectPredicate() = default;
987
+ virtual bool Filter(v8::Local<v8::Object> object) = 0;
988
+ };
989
+
990
+ /**
991
+ * Interface for controlling heap profiling. Instance of the
992
+ * profiler can be retrieved using v8::Isolate::GetHeapProfiler.
993
+ */
994
+ class V8_EXPORT HeapProfiler {
995
+ public:
996
+ void QueryObjects(v8::Local<v8::Context> context,
997
+ QueryObjectPredicate* predicate,
998
+ std::vector<v8::Global<v8::Object>>* objects);
999
+
1000
+ enum SamplingFlags {
1001
+ kSamplingNoFlags = 0,
1002
+ kSamplingForceGC = 1 << 0,
1003
+ kSamplingIncludeObjectsCollectedByMajorGC = 1 << 1,
1004
+ kSamplingIncludeObjectsCollectedByMinorGC = 1 << 2,
1005
+ };
1006
+
1007
+ /**
1008
+ * Callback function invoked during heap snapshot generation to retrieve
1009
+ * the embedder object graph. The callback should use graph->AddEdge(..) to
1010
+ * add references between the objects.
1011
+ * The callback must not trigger garbage collection in V8.
1012
+ */
1013
+ typedef void (*BuildEmbedderGraphCallback)(v8::Isolate* isolate,
1014
+ v8::EmbedderGraph* graph,
1015
+ void* data);
1016
+
1017
+ /**
1018
+ * Callback function invoked during heap snapshot generation to retrieve
1019
+ * the detachedness state of a JS object referenced by a TracedReference.
1020
+ *
1021
+ * The callback takes Local<Value> as parameter to allow the embedder to
1022
+ * unpack the TracedReference into a Local and reuse that Local for different
1023
+ * purposes.
1024
+ */
1025
+ using GetDetachednessCallback = EmbedderGraph::Node::Detachedness (*)(
1026
+ v8::Isolate* isolate, const v8::Local<v8::Value>& v8_value,
1027
+ uint16_t class_id, void* data);
1028
+
1029
+ /** Returns the number of snapshots taken. */
1030
+ int GetSnapshotCount();
1031
+
1032
+ /** Returns a snapshot by index. */
1033
+ const HeapSnapshot* GetHeapSnapshot(int index);
1034
+
1035
+ /**
1036
+ * Returns SnapshotObjectId for a heap object referenced by |value| if
1037
+ * it has been seen by the heap profiler, kUnknownObjectId otherwise.
1038
+ */
1039
+ SnapshotObjectId GetObjectId(Local<Value> value);
1040
+
1041
+ /**
1042
+ * Returns SnapshotObjectId for a native object referenced by |value| if it
1043
+ * has been seen by the heap profiler, kUnknownObjectId otherwise.
1044
+ */
1045
+ SnapshotObjectId GetObjectId(NativeObject value);
1046
+
1047
+ /**
1048
+ * Returns heap object with given SnapshotObjectId if the object is alive,
1049
+ * otherwise empty handle is returned.
1050
+ */
1051
+ Local<Value> FindObjectById(SnapshotObjectId id);
1052
+
1053
+ /**
1054
+ * Clears internal map from SnapshotObjectId to heap object. The new objects
1055
+ * will not be added into it unless a heap snapshot is taken or heap object
1056
+ * tracking is kicked off.
1057
+ */
1058
+ void ClearObjectIds();
1059
+
1060
+ /**
1061
+ * A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
1062
+ * it in case heap profiler cannot find id for the object passed as
1063
+ * parameter. HeapSnapshot::GetNodeById will always return NULL for such id.
1064
+ */
1065
+ static const SnapshotObjectId kUnknownObjectId = 0;
1066
+
1067
+ /**
1068
+ * Callback interface for retrieving user friendly names of global objects.
1069
+ *
1070
+ * This interface will soon be deprecated in favour of ContextNameResolver.
1071
+ */
1072
+ class V8_DEPRECATE_SOON("Use ContextNameResolver instead.")
1073
+ ObjectNameResolver {
1074
+ public:
1075
+ /**
1076
+ * Returns name to be used in the heap snapshot for given node. Returned
1077
+ * string must stay alive until snapshot collection is completed.
1078
+ */
1079
+ virtual const char* GetName(Local<Object> object) = 0;
1080
+
1081
+ protected:
1082
+ virtual ~ObjectNameResolver() = default;
1083
+ };
1084
+
1085
+ /**
1086
+ * Callback interface for retrieving user friendly names of a V8::Context
1087
+ * objects.
1088
+ */
1089
+ class ContextNameResolver {
1090
+ public:
1091
+ /**
1092
+ * Returns name to be used in the heap snapshot for given node. Returned
1093
+ * string must stay alive until snapshot collection is completed.
1094
+ * If no user friendly name is available return nullptr.
1095
+ */
1096
+ virtual const char* GetName(Local<Context> context) = 0;
1097
+
1098
+ protected:
1099
+ virtual ~ContextNameResolver() = default;
1100
+ };
1101
+
1102
+ enum class HeapSnapshotMode {
1103
+ /**
1104
+ * Heap snapshot for regular developers.
1105
+ */
1106
+ kRegular,
1107
+ /**
1108
+ * Heap snapshot is exposing internals that may be useful for experts.
1109
+ */
1110
+ kExposeInternals,
1111
+ };
1112
+
1113
+ enum class NumericsMode {
1114
+ /**
1115
+ * Numeric values are hidden as they are values of the corresponding
1116
+ * objects.
1117
+ */
1118
+ kHideNumericValues,
1119
+ /**
1120
+ * Numeric values are exposed in artificial fields.
1121
+ */
1122
+ kExposeNumericValues
1123
+ };
1124
+
1125
+ struct HeapSnapshotOptions final {
1126
+ // Manually define default constructor here to be able to use it in
1127
+ // `TakeSnapshot()` below.
1128
+ // NOLINTNEXTLINE
1129
+ HeapSnapshotOptions() {}
1130
+
1131
+ /**
1132
+ * The control used to report intermediate progress to.
1133
+ */
1134
+ ActivityControl* control = nullptr;
1135
+ /**
1136
+ * The resolver used by the snapshot generator to get names for v8::Context
1137
+ * objects.
1138
+ */
1139
+ ContextNameResolver* context_name_resolver = nullptr;
1140
+ /**
1141
+ * Mode for taking the snapshot, see `HeapSnapshotMode`.
1142
+ */
1143
+ HeapSnapshotMode snapshot_mode = HeapSnapshotMode::kRegular;
1144
+ /**
1145
+ * Mode for dealing with numeric values, see `NumericsMode`.
1146
+ */
1147
+ NumericsMode numerics_mode = NumericsMode::kHideNumericValues;
1148
+ /**
1149
+ * Whether stack is considered as a root set.
1150
+ */
1151
+ cppgc::EmbedderStackState stack_state =
1152
+ cppgc::EmbedderStackState::kMayContainHeapPointers;
1153
+ };
1154
+
1155
+ /**
1156
+ * Takes a heap snapshot.
1157
+ *
1158
+ * \returns the snapshot.
1159
+ */
1160
+ const HeapSnapshot* TakeHeapSnapshot(
1161
+ const HeapSnapshotOptions& options = HeapSnapshotOptions());
1162
+
1163
+ /**
1164
+ * Takes a heap snapshot. See `HeapSnapshotOptions` for details on the
1165
+ * parameters.
1166
+ *
1167
+ * \returns the snapshot.
1168
+ */
1169
+ const HeapSnapshot* TakeHeapSnapshot(ActivityControl* control,
1170
+ ContextNameResolver* resolver = nullptr,
1171
+ bool hide_internals = true,
1172
+ bool capture_numeric_value = false);
1173
+
1174
+ /**
1175
+ * Obtains list of Detached JS Wrapper Objects. This functon calls garbage
1176
+ * collection, then iterates over traced handles in the isolate
1177
+ */
1178
+ std::vector<v8::Local<v8::Value>> GetDetachedJSWrapperObjects();
1179
+
1180
+ /**
1181
+ * Starts tracking of heap objects population statistics. After calling
1182
+ * this method, all heap objects relocations done by the garbage collector
1183
+ * are being registered.
1184
+ *
1185
+ * |track_allocations| parameter controls whether stack trace of each
1186
+ * allocation in the heap will be recorded and reported as part of
1187
+ * HeapSnapshot.
1188
+ */
1189
+ void StartTrackingHeapObjects(bool track_allocations = false);
1190
+
1191
+ /**
1192
+ * Adds a new time interval entry to the aggregated statistics array. The
1193
+ * time interval entry contains information on the current heap objects
1194
+ * population size. The method also updates aggregated statistics and
1195
+ * reports updates for all previous time intervals via the OutputStream
1196
+ * object. Updates on each time interval are provided as a stream of the
1197
+ * HeapStatsUpdate structure instances.
1198
+ * If |timestamp_us| is supplied, timestamp of the new entry will be written
1199
+ * into it. The return value of the function is the last seen heap object Id.
1200
+ *
1201
+ * StartTrackingHeapObjects must be called before the first call to this
1202
+ * method.
1203
+ */
1204
+ SnapshotObjectId GetHeapStats(OutputStream* stream,
1205
+ int64_t* timestamp_us = nullptr);
1206
+
1207
+ /**
1208
+ * Stops tracking of heap objects population statistics, cleans up all
1209
+ * collected data. StartHeapObjectsTracking must be called again prior to
1210
+ * calling GetHeapStats next time.
1211
+ */
1212
+ void StopTrackingHeapObjects();
1213
+
1214
+ /**
1215
+ * Starts gathering a sampling heap profile. A sampling heap profile is
1216
+ * similar to tcmalloc's heap profiler and Go's mprof. It samples object
1217
+ * allocations and builds an online 'sampling' heap profile. At any point in
1218
+ * time, this profile is expected to be a representative sample of objects
1219
+ * currently live in the system. Each sampled allocation includes the stack
1220
+ * trace at the time of allocation, which makes this really useful for memory
1221
+ * leak detection.
1222
+ *
1223
+ * This mechanism is intended to be cheap enough that it can be used in
1224
+ * production with minimal performance overhead.
1225
+ *
1226
+ * Allocations are sampled using a randomized Poisson process. On average, one
1227
+ * allocation will be sampled every |sample_interval| bytes allocated. The
1228
+ * |stack_depth| parameter controls the maximum number of stack frames to be
1229
+ * captured on each allocation.
1230
+ *
1231
+ * NOTE: Support for native allocations doesn't exist yet, but is anticipated
1232
+ * in the future.
1233
+ *
1234
+ * Objects allocated before the sampling is started will not be included in
1235
+ * the profile.
1236
+ *
1237
+ * Returns false if a sampling heap profiler is already running.
1238
+ */
1239
+ bool StartSamplingHeapProfiler(uint64_t sample_interval = 512 * 1024,
1240
+ int stack_depth = 16,
1241
+ SamplingFlags flags = kSamplingNoFlags);
1242
+
1243
+ /**
1244
+ * Stops the sampling heap profile and discards the current profile.
1245
+ */
1246
+ void StopSamplingHeapProfiler();
1247
+
1248
+ /**
1249
+ * Returns the sampled profile of allocations allocated (and still live) since
1250
+ * StartSamplingHeapProfiler was called. The ownership of the pointer is
1251
+ * transferred to the caller. Returns nullptr if sampling heap profiler is not
1252
+ * active.
1253
+ */
1254
+ AllocationProfile* GetAllocationProfile();
1255
+
1256
+ /**
1257
+ * Deletes all snapshots taken. All previously returned pointers to
1258
+ * snapshots and their contents become invalid after this call.
1259
+ */
1260
+ void DeleteAllHeapSnapshots();
1261
+
1262
+ void AddBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback,
1263
+ void* data);
1264
+ void RemoveBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback,
1265
+ void* data);
1266
+
1267
+ void SetGetDetachednessCallback(GetDetachednessCallback callback, void* data);
1268
+
1269
+ /**
1270
+ * Returns whether the heap profiler is currently taking a snapshot.
1271
+ */
1272
+ bool IsTakingSnapshot();
1273
+
1274
+ /**
1275
+ * Allocates a copy of the provided string within the heap snapshot generator
1276
+ * and returns a pointer to the copy. May only be called during heap snapshot
1277
+ * generation.
1278
+ */
1279
+ const char* CopyNameForHeapSnapshot(const char* name);
1280
+
1281
+ /**
1282
+ * Default value of persistent handle class ID. Must not be used to
1283
+ * define a class. Can be used to reset a class of a persistent
1284
+ * handle.
1285
+ */
1286
+ static const uint16_t kPersistentHandleNoClassId = 0;
1287
+
1288
+ private:
1289
+ HeapProfiler();
1290
+ ~HeapProfiler();
1291
+ HeapProfiler(const HeapProfiler&);
1292
+ HeapProfiler& operator=(const HeapProfiler&);
1293
+ };
1294
+
1295
+ /**
1296
+ * A struct for exporting HeapStats data from V8, using "push" model.
1297
+ * See HeapProfiler::GetHeapStats.
1298
+ */
1299
+ struct HeapStatsUpdate {
1300
+ HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
1301
+ : index(index), count(count), size(size) { }
1302
+ uint32_t index; // Index of the time interval that was changed.
1303
+ uint32_t count; // New value of count field for the interval with this index.
1304
+ uint32_t size; // New value of size field for the interval with this index.
1305
+ };
1306
+
1307
+ #define CODE_EVENTS_LIST(V) \
1308
+ V(Builtin) \
1309
+ V(Callback) \
1310
+ V(Eval) \
1311
+ V(Function) \
1312
+ V(InterpretedFunction) \
1313
+ V(Handler) \
1314
+ V(BytecodeHandler) \
1315
+ V(LazyCompile) /* Unused, use kFunction instead */ \
1316
+ V(RegExp) \
1317
+ V(Script) \
1318
+ V(Stub) \
1319
+ V(Relocation)
1320
+
1321
+ /**
1322
+ * Note that this enum may be extended in the future. Please include a default
1323
+ * case if this enum is used in a switch statement.
1324
+ */
1325
+ enum CodeEventType {
1326
+ kUnknownType = 0
1327
+ #define V(Name) , k##Name##Type
1328
+ CODE_EVENTS_LIST(V)
1329
+ #undef V
1330
+ };
1331
+
1332
+ /**
1333
+ * Representation of a code creation event
1334
+ */
1335
+ class V8_EXPORT CodeEvent {
1336
+ public:
1337
+ uintptr_t GetCodeStartAddress();
1338
+ size_t GetCodeSize();
1339
+ Local<String> GetFunctionName();
1340
+ Local<String> GetScriptName();
1341
+ int GetScriptLine();
1342
+ int GetScriptColumn();
1343
+ /**
1344
+ * NOTE (mmarchini): We can't allocate objects in the heap when we collect
1345
+ * existing code, and both the code type and the comment are not stored in the
1346
+ * heap, so we return those as const char*.
1347
+ */
1348
+ CodeEventType GetCodeType();
1349
+ const char* GetComment();
1350
+
1351
+ static const char* GetCodeEventTypeName(CodeEventType code_event_type);
1352
+
1353
+ uintptr_t GetPreviousCodeStartAddress();
1354
+ };
1355
+
1356
+ /**
1357
+ * Interface to listen to code creation and code relocation events.
1358
+ */
1359
+ class V8_EXPORT CodeEventHandler {
1360
+ public:
1361
+ /**
1362
+ * Creates a new listener for the |isolate|. The isolate must be initialized.
1363
+ * The listener object must be disposed after use by calling |Dispose| method.
1364
+ * Multiple listeners can be created for the same isolate.
1365
+ */
1366
+ explicit CodeEventHandler(Isolate* isolate);
1367
+ virtual ~CodeEventHandler();
1368
+
1369
+ /**
1370
+ * Handle is called every time a code object is created or moved. Information
1371
+ * about each code event will be available through the `code_event`
1372
+ * parameter.
1373
+ *
1374
+ * When the CodeEventType is kRelocationType, the code for this CodeEvent has
1375
+ * moved from `GetPreviousCodeStartAddress()` to `GetCodeStartAddress()`.
1376
+ */
1377
+ virtual void Handle(CodeEvent* code_event) = 0;
1378
+
1379
+ /**
1380
+ * Call `Enable()` to starts listening to code creation and code relocation
1381
+ * events. These events will be handled by `Handle()`.
1382
+ */
1383
+ void Enable();
1384
+
1385
+ /**
1386
+ * Call `Disable()` to stop listening to code creation and code relocation
1387
+ * events.
1388
+ */
1389
+ void Disable();
1390
+
1391
+ private:
1392
+ CodeEventHandler();
1393
+ CodeEventHandler(const CodeEventHandler&);
1394
+ CodeEventHandler& operator=(const CodeEventHandler&);
1395
+ void* internal_listener_;
1396
+ };
1397
+
1398
+ } // namespace v8
1399
+
1400
+
1401
+ #endif // V8_V8_PROFILER_H_