OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_SAMPLER_H_ | 5 #ifndef V8_SAMPLER_H_ |
6 #define V8_SAMPLER_H_ | 6 #define V8_SAMPLER_H_ |
7 | 7 |
8 #include "include/v8.h" | |
9 | |
8 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
9 #include "src/frames.h" | 11 #include "src/frames.h" |
10 #include "src/globals.h" | 12 #include "src/globals.h" |
11 | 13 |
12 namespace v8 { | 14 namespace v8 { |
13 namespace internal { | 15 namespace internal { |
14 | 16 |
15 class Isolate; | 17 class Isolate; |
16 | 18 |
19 class ScopedSemaphore { | |
alph
2014/09/09 13:54:37
Move it into the cc file?
| |
20 public: | |
21 explicit ScopedSemaphore(base::Semaphore* sem) { semaphore_ = sem; } | |
22 ~ScopedSemaphore() { semaphore_->Signal(); } | |
23 | |
24 private: | |
25 base::Semaphore* semaphore_; | |
yurys
2014/09/09 14:35:20
semaphore.h would be a more appropriate place for
gholap
2014/09/17 02:35:06
Yes agreed. Another alternative could be, as alph
| |
26 }; | |
27 | |
28 | |
17 // ---------------------------------------------------------------------------- | 29 // ---------------------------------------------------------------------------- |
18 // Sampler | 30 // Sampler |
19 // | 31 // |
20 // A sampler periodically samples the state of the VM and optionally | 32 // A sampler periodically samples the state of the VM and optionally |
21 // (if used for profiling) the program counter and stack pointer for | 33 // (if used for profiling) the program counter and stack pointer for |
22 // the thread that created it. | 34 // the thread that created it. |
23 | 35 |
24 struct RegisterState { | 36 struct RegisterState { |
25 RegisterState() : pc(NULL), sp(NULL), fp(NULL) {} | 37 RegisterState() : pc(NULL), sp(NULL), fp(NULL) {} |
26 Address pc; // Instruction pointer. | 38 Address pc; // Instruction pointer. |
27 Address sp; // Stack pointer. | 39 Address sp; // Stack pointer. |
28 Address fp; // Frame pointer. | 40 Address fp; // Frame pointer. |
29 }; | 41 }; |
30 | 42 |
31 // TickSample captures the information collected for each sample. | 43 // TickSample captures the information collected for each sample. |
32 struct TickSample { | 44 struct TickSample { |
33 TickSample() | 45 TickSample() |
34 : state(OTHER), | 46 : state(OTHER), |
35 pc(NULL), | 47 pc(NULL), |
36 external_callback(NULL), | 48 external_callback(NULL), |
37 frames_count(0), | |
38 has_external_callback(false), | 49 has_external_callback(false), |
39 top_frame_type(StackFrame::NONE) {} | 50 top_frame_type(StackFrame::NONE) {} |
40 void Init(Isolate* isolate, const RegisterState& state); | 51 void Init(Isolate* isolate, const RegisterState& state); |
41 StateTag state; // The state of the VM. | 52 enum { kMaxFramesCount = 255u }; |
42 Address pc; // Instruction pointer. | 53 |
54 void* stack[kMaxFramesCount]; // Call stack. | |
55 size_t frames_count; // Number of captured frames. | |
56 StateTag state; // The state of the VM. | |
57 Address pc; // Instruction pointer. | |
43 union { | 58 union { |
44 Address tos; // Top stack value (*sp). | 59 Address tos; // Top stack value (*sp). |
45 Address external_callback; | 60 Address external_callback; |
46 }; | 61 }; |
47 static const unsigned kMaxFramesCountLog2 = 8; | |
48 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; | |
49 Address stack[kMaxFramesCount]; // Call stack. | |
50 base::TimeTicks timestamp; | 62 base::TimeTicks timestamp; |
51 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. | |
52 bool has_external_callback : 1; | 63 bool has_external_callback : 1; |
53 StackFrame::Type top_frame_type : 4; | 64 StackFrame::Type top_frame_type : 4; |
54 }; | 65 }; |
55 | 66 |
56 class Sampler { | 67 class Sampler { |
57 public: | 68 public: |
58 // Initializes the Sampler support. Called once at VM startup. | 69 // Initializes the Sampler support. Called once at VM startup. |
59 static void SetUp(); | 70 static void SetUp(); |
60 static void TearDown(); | 71 static void TearDown(); |
61 | 72 |
(...skipping 16 matching lines...) Expand all Loading... | |
78 return base::NoBarrier_Load(&profiling_) > 0 && | 89 return base::NoBarrier_Load(&profiling_) > 0 && |
79 !base::NoBarrier_Load(&has_processing_thread_); | 90 !base::NoBarrier_Load(&has_processing_thread_); |
80 } | 91 } |
81 void IncreaseProfilingDepth(); | 92 void IncreaseProfilingDepth(); |
82 void DecreaseProfilingDepth(); | 93 void DecreaseProfilingDepth(); |
83 | 94 |
84 // Whether the sampler is running (that is, consumes resources). | 95 // Whether the sampler is running (that is, consumes resources). |
85 bool IsActive() const { return base::NoBarrier_Load(&active_); } | 96 bool IsActive() const { return base::NoBarrier_Load(&active_); } |
86 | 97 |
87 void DoSample(); | 98 void DoSample(); |
99 void GetSample(v8::Sample* sample); | |
88 // If true next sample must be initiated on the profiler event processor | 100 // If true next sample must be initiated on the profiler event processor |
89 // thread right after latest sample is processed. | 101 // thread right after latest sample is processed. |
90 void SetHasProcessingThread(bool value) { | 102 void SetHasProcessingThread(bool value) { |
91 base::NoBarrier_Store(&has_processing_thread_, value); | 103 base::NoBarrier_Store(&has_processing_thread_, value); |
92 } | 104 } |
93 | 105 |
94 // Used in tests to make sure that stack sampling is performed. | 106 // Used in tests to make sure that stack sampling is performed. |
95 unsigned js_and_external_sample_count() const { | 107 unsigned js_and_external_sample_count() const { |
96 return js_and_external_sample_count_; | 108 return js_and_external_sample_count_; |
97 } | 109 } |
(...skipping 15 matching lines...) Expand all Loading... | |
113 | 125 |
114 Isolate* isolate_; | 126 Isolate* isolate_; |
115 const int interval_; | 127 const int interval_; |
116 base::Atomic32 profiling_; | 128 base::Atomic32 profiling_; |
117 base::Atomic32 has_processing_thread_; | 129 base::Atomic32 has_processing_thread_; |
118 base::Atomic32 active_; | 130 base::Atomic32 active_; |
119 PlatformData* data_; // Platform specific data. | 131 PlatformData* data_; // Platform specific data. |
120 bool is_counting_samples_; | 132 bool is_counting_samples_; |
121 // Counts stack samples taken in JS VM state. | 133 // Counts stack samples taken in JS VM state. |
122 unsigned js_and_external_sample_count_; | 134 unsigned js_and_external_sample_count_; |
135 void GetSampleHelper(TickSample* sample, bool called_from_get_sample); | |
123 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 136 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
124 }; | 137 }; |
125 | 138 |
126 | 139 |
127 } } // namespace v8::internal | 140 } } // namespace v8::internal |
128 | 141 |
129 #endif // V8_SAMPLER_H_ | 142 #endif // V8_SAMPLER_H_ |
OLD | NEW |