@@ -18,14 +18,18 @@ namespace v8 {
1818class HeapGraphNode ;
1919struct HeapStatsUpdate ;
2020
21- typedef uint32_t SnapshotObjectId ;
22-
21+ using NativeObject = void * ;
22+ using SnapshotObjectId = uint32_t ;
2323
2424struct CpuProfileDeoptFrame {
2525 int script_id;
2626 size_t position;
2727};
2828
29+ namespace internal {
30+ class CpuProfile ;
31+ } // namespace internal
32+
2933} // namespace v8
3034
3135#ifdef V8_OS_WIN
@@ -48,75 +52,6 @@ template class V8_EXPORT std::vector<v8::CpuProfileDeoptInfo>;
4852
4953namespace v8 {
5054
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-
12055/* *
12156 * CpuProfileNode represents a node in a call graph.
12257 */
@@ -307,6 +242,15 @@ enum CpuProfilingNamingMode {
307242 kDebugNaming ,
308243};
309244
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+
310254/* *
311255 * Optional profiling attributes.
312256 */
@@ -328,21 +272,25 @@ class V8_EXPORT CpuProfilingOptions {
328272 * zero, the sampling interval will be equal to
329273 * the profiler's sampling interval.
330274 */
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>());
337279
338280 CpuProfilingMode mode () const { return mode_; }
339281 unsigned max_samples () const { return max_samples_; }
340282 int sampling_interval_us () const { return sampling_interval_us_; }
341283
342284 private:
285+ friend class internal ::CpuProfile;
286+
287+ bool has_filter_context () const { return !filter_context_.IsEmpty (); }
288+ void * raw_filter_context () const ;
289+
343290 CpuProfilingMode mode_;
344291 unsigned max_samples_;
345292 int sampling_interval_us_;
293+ CopyablePersistentTraits<Context>::CopyablePersistent filter_context_;
346294};
347295
348296/* *
@@ -357,7 +305,8 @@ class V8_EXPORT CpuProfiler {
357305 * |Dispose| method.
358306 */
359307 static CpuProfiler* New (Isolate* isolate,
360- CpuProfilingNamingMode = kDebugNaming );
308+ CpuProfilingNamingMode = kDebugNaming ,
309+ CpuProfilingLoggingMode = kLazyLogging );
361310
362311 /* *
363312 * Synchronously collect current stack sample in all profilers attached to
@@ -798,6 +747,12 @@ class V8_EXPORT EmbedderGraph {
798747 */
799748 virtual const char * NamePrefix () { return nullptr ; }
800749
750+ /* *
751+ * Returns the NativeObject that can be used for querying the
752+ * |HeapSnapshot|.
753+ */
754+ virtual NativeObject GetNativeObject () { return nullptr ; }
755+
801756 Node (const Node&) = delete ;
802757 Node& operator =(const Node&) = delete ;
803758 };
@@ -860,6 +815,12 @@ class V8_EXPORT HeapProfiler {
860815 */
861816 SnapshotObjectId GetObjectId (Local<Value> value);
862817
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+
863824 /* *
864825 * Returns heap object with given SnapshotObjectId if the object is alive,
865826 * otherwise empty handle is returned.
0 commit comments