@@ -18,14 +18,18 @@ namespace v8 {
18
18
class HeapGraphNode ;
19
19
struct HeapStatsUpdate ;
20
20
21
- typedef uint32_t SnapshotObjectId ;
22
-
21
+ using NativeObject = void * ;
22
+ using SnapshotObjectId = uint32_t ;
23
23
24
24
struct CpuProfileDeoptFrame {
25
25
int script_id;
26
26
size_t position;
27
27
};
28
28
29
+ namespace internal {
30
+ class CpuProfile ;
31
+ } // namespace internal
32
+
29
33
} // namespace v8
30
34
31
35
#ifdef V8_OS_WIN
@@ -48,75 +52,6 @@ template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
48
52
49
53
namespace v8 {
50
54
51
- // TickSample captures the information collected for each sample.
52
- struct V8_EXPORT TickSample {
53
- // Internal profiling (with --prof + tools/$OS-tick-processor) wants to
54
- // include the runtime function we're calling. Externally exposed tick
55
- // samples don't care.
56
- enum RecordCEntryFrame { kIncludeCEntryFrame , kSkipCEntryFrame };
57
-
58
- TickSample ()
59
- : state(OTHER),
60
- pc (nullptr ),
61
- external_callback_entry(nullptr ),
62
- frames_count(0 ),
63
- has_external_callback(false ),
64
- update_stats(true ) {}
65
-
66
- /* *
67
- * Initialize a tick sample from the isolate.
68
- * \param isolate The isolate.
69
- * \param state Execution state.
70
- * \param record_c_entry_frame Include or skip the runtime function.
71
- * \param update_stats Whether update the sample to the aggregated stats.
72
- * \param use_simulator_reg_state When set to true and V8 is running under a
73
- * simulator, the method will use the simulator
74
- * register state rather than the one provided
75
- * with |state| argument. Otherwise the method
76
- * will use provided register |state| as is.
77
- */
78
- void Init (Isolate* isolate, const v8::RegisterState& state,
79
- RecordCEntryFrame record_c_entry_frame, bool update_stats,
80
- bool use_simulator_reg_state = true );
81
- /* *
82
- * Get a call stack sample from the isolate.
83
- * \param isolate The isolate.
84
- * \param state Register state.
85
- * \param record_c_entry_frame Include or skip the runtime function.
86
- * \param frames Caller allocated buffer to store stack frames.
87
- * \param frames_limit Maximum number of frames to capture. The buffer must
88
- * be large enough to hold the number of frames.
89
- * \param sample_info The sample info is filled up by the function
90
- * provides number of actual captured stack frames and
91
- * the current VM state.
92
- * \param use_simulator_reg_state When set to true and V8 is running under a
93
- * simulator, the method will use the simulator
94
- * register state rather than the one provided
95
- * with |state| argument. Otherwise the method
96
- * will use provided register |state| as is.
97
- * \note GetStackSample is thread and signal safe and should only be called
98
- * when the JS thread is paused or interrupted.
99
- * Otherwise the behavior is undefined.
100
- */
101
- static bool GetStackSample (Isolate* isolate, v8::RegisterState* state,
102
- RecordCEntryFrame record_c_entry_frame,
103
- void ** frames, size_t frames_limit,
104
- v8::SampleInfo* sample_info,
105
- bool use_simulator_reg_state = true );
106
- StateTag state; // The state of the VM.
107
- void * pc; // Instruction pointer.
108
- union {
109
- void * tos; // Top stack value (*sp).
110
- void * external_callback_entry;
111
- };
112
- static const unsigned kMaxFramesCountLog2 = 8 ;
113
- static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2 ) - 1 ;
114
- void * stack[kMaxFramesCount ]; // Call stack.
115
- unsigned frames_count : kMaxFramesCountLog2 ; // Number of captured frames.
116
- bool has_external_callback : 1 ;
117
- bool update_stats : 1 ; // Whether the sample should update aggregated stats.
118
- };
119
-
120
55
/* *
121
56
* CpuProfileNode represents a node in a call graph.
122
57
*/
@@ -307,6 +242,15 @@ enum CpuProfilingNamingMode {
307
242
kDebugNaming ,
308
243
};
309
244
245
+ enum CpuProfilingLoggingMode {
246
+ // Enables logging when a profile is active, and disables logging when all
247
+ // profiles are detached.
248
+ kLazyLogging ,
249
+ // Enables logging for the lifetime of the CpuProfiler. Calls to
250
+ // StartRecording are faster, at the expense of runtime overhead.
251
+ kEagerLogging ,
252
+ };
253
+
310
254
/* *
311
255
* Optional profiling attributes.
312
256
*/
@@ -328,21 +272,25 @@ class V8_EXPORT CpuProfilingOptions {
328
272
* zero, the sampling interval will be equal to
329
273
* the profiler's sampling interval.
330
274
*/
331
- CpuProfilingOptions (CpuProfilingMode mode = kLeafNodeLineNumbers ,
332
- unsigned max_samples = kNoSampleLimit ,
333
- int sampling_interval_us = 0 )
334
- : mode_(mode),
335
- max_samples_ (max_samples),
336
- sampling_interval_us_(sampling_interval_us) {}
275
+ CpuProfilingOptions (
276
+ CpuProfilingMode mode = kLeafNodeLineNumbers ,
277
+ unsigned max_samples = kNoSampleLimit , int sampling_interval_us = 0 ,
278
+ MaybeLocal<Context> filter_context = MaybeLocal<Context>());
337
279
338
280
CpuProfilingMode mode () const { return mode_; }
339
281
unsigned max_samples () const { return max_samples_; }
340
282
int sampling_interval_us () const { return sampling_interval_us_; }
341
283
342
284
private:
285
+ friend class internal ::CpuProfile;
286
+
287
+ bool has_filter_context () const { return !filter_context_.IsEmpty (); }
288
+ void * raw_filter_context () const ;
289
+
343
290
CpuProfilingMode mode_;
344
291
unsigned max_samples_;
345
292
int sampling_interval_us_;
293
+ CopyablePersistentTraits<Context>::CopyablePersistent filter_context_;
346
294
};
347
295
348
296
/* *
@@ -357,7 +305,8 @@ class V8_EXPORT CpuProfiler {
357
305
* |Dispose| method.
358
306
*/
359
307
static CpuProfiler* New (Isolate* isolate,
360
- CpuProfilingNamingMode = kDebugNaming );
308
+ CpuProfilingNamingMode = kDebugNaming ,
309
+ CpuProfilingLoggingMode = kLazyLogging );
361
310
362
311
/* *
363
312
* Synchronously collect current stack sample in all profilers attached to
@@ -798,6 +747,12 @@ class V8_EXPORT EmbedderGraph {
798
747
*/
799
748
virtual const char * NamePrefix () { return nullptr ; }
800
749
750
+ /* *
751
+ * Returns the NativeObject that can be used for querying the
752
+ * |HeapSnapshot|.
753
+ */
754
+ virtual NativeObject GetNativeObject () { return nullptr ; }
755
+
801
756
Node (const Node&) = delete ;
802
757
Node& operator =(const Node&) = delete ;
803
758
};
@@ -860,6 +815,12 @@ class V8_EXPORT HeapProfiler {
860
815
*/
861
816
SnapshotObjectId GetObjectId (Local<Value> value);
862
817
818
+ /* *
819
+ * Returns SnapshotObjectId for a native object referenced by |value| if it
820
+ * has been seen by the heap profiler, kUnknownObjectId otherwise.
821
+ */
822
+ SnapshotObjectId GetObjectId (NativeObject value);
823
+
863
824
/* *
864
825
* Returns heap object with given SnapshotObjectId if the object is alive,
865
826
* otherwise empty handle is returned.
0 commit comments