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