55#ifndef V8_PROFILER_TICK_SAMPLE_H_
66#define V8_PROFILER_TICK_SAMPLE_H_
77
8- #include " include/v8-profiler .h"
8+ #include " include/v8.h"
99#include " src/base/platform/time.h"
1010#include " src/common/globals.h"
1111
@@ -14,15 +14,83 @@ namespace internal {
1414
1515class Isolate ;
1616
17- struct TickSample : public v8 ::TickSample {
17+ // TickSample captures the information collected for each sample.
18+ struct V8_EXPORT TickSample {
19+ // Internal profiling (with --prof + tools/$OS-tick-processor) wants to
20+ // include the runtime function we're calling. Externally exposed tick
21+ // samples don't care.
22+ enum RecordCEntryFrame { kIncludeCEntryFrame , kSkipCEntryFrame };
23+
24+ TickSample ()
25+ : state(OTHER ),
26+ pc (nullptr ),
27+ external_callback_entry(nullptr ),
28+ frames_count(0 ),
29+ has_external_callback(false ),
30+ update_stats(true ) {}
31+
32+ /* *
33+ * Initialize a tick sample from the isolate.
34+ * \param isolate The isolate.
35+ * \param state Execution state.
36+ * \param record_c_entry_frame Include or skip the runtime function.
37+ * \param update_stats Whether update the sample to the aggregated stats.
38+ * \param use_simulator_reg_state When set to true and V8 is running under a
39+ * simulator, the method will use the simulator
40+ * register state rather than the one provided
41+ * with |state| argument. Otherwise the method
42+ * will use provided register |state| as is.
43+ */
1844 void Init (Isolate* isolate, const v8::RegisterState& state,
1945 RecordCEntryFrame record_c_entry_frame, bool update_stats,
2046 bool use_simulator_reg_state = true ,
2147 base::TimeDelta sampling_interval = base::TimeDelta());
22- base::TimeTicks timestamp;
23- base::TimeDelta sampling_interval; // Sampling interval used to capture.
48+ /* *
49+ * Get a call stack sample from the isolate.
50+ * \param isolate The isolate.
51+ * \param state Register state.
52+ * \param record_c_entry_frame Include or skip the runtime function.
53+ * \param frames Caller allocated buffer to store stack frames.
54+ * \param frames_limit Maximum number of frames to capture. The buffer must
55+ * be large enough to hold the number of frames.
56+ * \param sample_info The sample info is filled up by the function
57+ * provides number of actual captured stack frames and
58+ * the current VM state.
59+ * \param use_simulator_reg_state When set to true and V8 is running under a
60+ * simulator, the method will use the simulator
61+ * register state rather than the one provided
62+ * with |state| argument. Otherwise the method
63+ * will use provided register |state| as is.
64+ * \note GetStackSample is thread and signal safe and should only be called
65+ * when the JS thread is paused or interrupted.
66+ * Otherwise the behavior is undefined.
67+ */
68+ static bool GetStackSample (Isolate* isolate, v8::RegisterState* state,
69+ RecordCEntryFrame record_c_entry_frame,
70+ void ** frames, size_t frames_limit,
71+ v8::SampleInfo* sample_info,
72+ bool use_simulator_reg_state = true ,
73+ void ** contexts = nullptr );
2474
2575 void print () const ;
76+
77+ StateTag state; // The state of the VM.
78+ void * pc; // Instruction pointer.
79+ union {
80+ void * tos; // Top stack value (*sp).
81+ void * external_callback_entry;
82+ };
83+ static const unsigned kMaxFramesCountLog2 = 8 ;
84+ static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2 ) - 1 ;
85+ void * stack[kMaxFramesCount ]; // Call stack.
86+ void * contexts[kMaxFramesCount ]; // Stack of associated native contexts.
87+ void * top_context = nullptr ; // Address of the incumbent native context.
88+ unsigned frames_count : kMaxFramesCountLog2 ; // Number of captured frames.
89+ bool has_external_callback : 1 ;
90+ bool update_stats : 1 ; // Whether the sample should update aggregated stats.
91+
92+ base::TimeTicks timestamp;
93+ base::TimeDelta sampling_interval; // Sampling interval used to capture.
2694};
2795
2896} // namespace internal
0 commit comments