• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_PROFILER_TICK_SAMPLE_H_
6 #define V8_PROFILER_TICK_SAMPLE_H_
7 
8 #include "include/v8.h"
9 #include "src/base/platform/time.h"
10 #include "src/common/globals.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class Isolate;
16 
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 
TickSampleTickSample24   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    */
44   void Init(Isolate* isolate, const v8::RegisterState& state,
45             RecordCEntryFrame record_c_entry_frame, bool update_stats,
46             bool use_simulator_reg_state = true,
47             base::TimeDelta sampling_interval = base::TimeDelta());
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 
74   void print() const;
75 
76   StateTag state;  // The state of the VM.
77   void* pc;        // Instruction pointer.
78   union {
79     void* tos;  // Top stack value (*sp).
80     void* external_callback_entry;
81   };
82   static const unsigned kMaxFramesCountLog2 = 8;
83   static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1;
84   void* stack[kMaxFramesCount];     // Call stack.
85   unsigned frames_count : kMaxFramesCountLog2;  // Number of captured frames.
86   bool has_external_callback : 1;
87   bool update_stats : 1;  // Whether the sample should update aggregated stats.
88 
89   base::TimeTicks timestamp;
90   base::TimeDelta sampling_interval;  // Sampling interval used to capture.
91 };
92 
93 }  // namespace internal
94 }  // namespace v8
95 
96 #endif  // V8_PROFILER_TICK_SAMPLE_H_
97