| 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 "src/base/atomicops.h" | 8 #include "src/base/atomicops.h" |
| 9 #include "src/frames.h" | 9 #include "src/frames.h" |
| 10 #include "src/globals.h" | 10 #include "src/globals.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 RegisterState() : pc(NULL), sp(NULL), fp(NULL) {} | 25 RegisterState() : pc(NULL), sp(NULL), fp(NULL) {} |
| 26 Address pc; // Instruction pointer. | 26 Address pc; // Instruction pointer. |
| 27 Address sp; // Stack pointer. | 27 Address sp; // Stack pointer. |
| 28 Address fp; // Frame pointer. | 28 Address fp; // Frame pointer. |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 // TickSample captures the information collected for each sample. | 31 // TickSample captures the information collected for each sample. |
| 32 struct TickSample { | 32 struct TickSample { |
| 33 TickSample() | 33 TickSample() |
| 34 : state(OTHER), | 34 : state(OTHER), |
| 35 frames_count(0), |
| 35 pc(NULL), | 36 pc(NULL), |
| 36 external_callback(NULL), | 37 external_callback(NULL), |
| 37 frames_count(0), | |
| 38 has_external_callback(false), | 38 has_external_callback(false), |
| 39 top_frame_type(StackFrame::NONE) {} | 39 top_frame_type(StackFrame::NONE) {} |
| 40 void Init(Isolate* isolate, const RegisterState& state); | 40 static const unsigned kMaxFramesCountLog2 = 8; |
| 41 StateTag state; // The state of the VM. | 41 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; |
| 42 |
| 43 StateTag state; // The state of the VM. |
| 44 Address stack[kMaxFramesCount]; // Call stack. |
| 45 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. |
| 46 |
| 47 void Init(Isolate* isolate, |
| 48 const RegisterState& state); |
| 42 Address pc; // Instruction pointer. | 49 Address pc; // Instruction pointer. |
| 43 union { | 50 union { |
| 44 Address tos; // Top stack value (*sp). | 51 Address tos; // Top stack value (*sp). |
| 45 Address external_callback; | 52 Address external_callback; |
| 46 }; | 53 }; |
| 47 static const unsigned kMaxFramesCountLog2 = 8; | |
| 48 static const unsigned kMaxFramesCount = (1 << kMaxFramesCountLog2) - 1; | |
| 49 Address stack[kMaxFramesCount]; // Call stack. | |
| 50 base::TimeTicks timestamp; | 54 base::TimeTicks timestamp; |
| 51 unsigned frames_count : kMaxFramesCountLog2; // Number of captured frames. | |
| 52 bool has_external_callback : 1; | 55 bool has_external_callback : 1; |
| 53 StackFrame::Type top_frame_type : 4; | 56 StackFrame::Type top_frame_type : 4; |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 class Sampler { | 59 class Sampler { |
| 57 public: | 60 public: |
| 58 // Initializes the Sampler support. Called once at VM startup. | 61 // Initializes the Sampler support. Called once at VM startup. |
| 59 static void SetUp(); | 62 static void SetUp(); |
| 60 static void TearDown(); | 63 static void TearDown(); |
| 61 | 64 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 78 return base::NoBarrier_Load(&profiling_) > 0 && | 81 return base::NoBarrier_Load(&profiling_) > 0 && |
| 79 !base::NoBarrier_Load(&has_processing_thread_); | 82 !base::NoBarrier_Load(&has_processing_thread_); |
| 80 } | 83 } |
| 81 void IncreaseProfilingDepth(); | 84 void IncreaseProfilingDepth(); |
| 82 void DecreaseProfilingDepth(); | 85 void DecreaseProfilingDepth(); |
| 83 | 86 |
| 84 // Whether the sampler is running (that is, consumes resources). | 87 // Whether the sampler is running (that is, consumes resources). |
| 85 bool IsActive() const { return base::NoBarrier_Load(&active_); } | 88 bool IsActive() const { return base::NoBarrier_Load(&active_); } |
| 86 | 89 |
| 87 void DoSample(); | 90 void DoSample(); |
| 91 TickSample* GetSample(TickSample* sample); |
| 88 // If true next sample must be initiated on the profiler event processor | 92 // If true next sample must be initiated on the profiler event processor |
| 89 // thread right after latest sample is processed. | 93 // thread right after latest sample is processed. |
| 90 void SetHasProcessingThread(bool value) { | 94 void SetHasProcessingThread(bool value) { |
| 91 base::NoBarrier_Store(&has_processing_thread_, value); | 95 base::NoBarrier_Store(&has_processing_thread_, value); |
| 92 } | 96 } |
| 93 | 97 |
| 94 // Used in tests to make sure that stack sampling is performed. | 98 // Used in tests to make sure that stack sampling is performed. |
| 95 unsigned js_and_external_sample_count() const { | 99 unsigned js_and_external_sample_count() const { |
| 96 return js_and_external_sample_count_; | 100 return js_and_external_sample_count_; |
| 97 } | 101 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 113 | 117 |
| 114 Isolate* isolate_; | 118 Isolate* isolate_; |
| 115 const int interval_; | 119 const int interval_; |
| 116 base::Atomic32 profiling_; | 120 base::Atomic32 profiling_; |
| 117 base::Atomic32 has_processing_thread_; | 121 base::Atomic32 has_processing_thread_; |
| 118 base::Atomic32 active_; | 122 base::Atomic32 active_; |
| 119 PlatformData* data_; // Platform specific data. | 123 PlatformData* data_; // Platform specific data. |
| 120 bool is_counting_samples_; | 124 bool is_counting_samples_; |
| 121 // Counts stack samples taken in JS VM state. | 125 // Counts stack samples taken in JS VM state. |
| 122 unsigned js_and_external_sample_count_; | 126 unsigned js_and_external_sample_count_; |
| 127 TickSample* GetSampleHelper_(); |
| 123 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 128 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 124 }; | 129 }; |
| 125 | 130 |
| 126 | 131 |
| 127 } } // namespace v8::internal | 132 } } // namespace v8::internal |
| 128 | 133 |
| 129 #endif // V8_SAMPLER_H_ | 134 #endif // V8_SAMPLER_H_ |
| OLD | NEW |