| 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_PROFILER_SAMPLER_H_ | 5 #ifndef V8_PROFILER_SAMPLER_H_ |
| 6 #define V8_PROFILER_SAMPLER_H_ | 6 #define V8_PROFILER_SAMPLER_H_ |
| 7 | 7 |
| 8 #include "include/v8.h" | 8 #include "include/v8.h" |
| 9 | 9 |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 bool IsProfiling() const { | 85 bool IsProfiling() const { |
| 86 return base::NoBarrier_Load(&profiling_) > 0 && | 86 return base::NoBarrier_Load(&profiling_) > 0 && |
| 87 !base::NoBarrier_Load(&has_processing_thread_); | 87 !base::NoBarrier_Load(&has_processing_thread_); |
| 88 } | 88 } |
| 89 void IncreaseProfilingDepth(); | 89 void IncreaseProfilingDepth(); |
| 90 void DecreaseProfilingDepth(); | 90 void DecreaseProfilingDepth(); |
| 91 | 91 |
| 92 // Whether the sampler is running (that is, consumes resources). | 92 // Whether the sampler is running (that is, consumes resources). |
| 93 bool IsActive() const { return base::NoBarrier_Load(&active_); } | 93 bool IsActive() const { return base::NoBarrier_Load(&active_); } |
| 94 | 94 |
| 95 // A sampler can be registered when Start() doesn't get called, |
| 96 // since CpuProfiler won't start the sampler but need to collect samples. |
| 97 bool IsRegistered() const { return base::NoBarrier_Load(®istered_); } |
| 98 |
| 95 void DoSample(); | 99 void DoSample(); |
| 96 // 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 |
| 97 // thread right after latest sample is processed. | 101 // thread right after latest sample is processed. |
| 98 void SetHasProcessingThread(bool value) { | 102 void SetHasProcessingThread(bool value) { |
| 99 base::NoBarrier_Store(&has_processing_thread_, value); | 103 base::NoBarrier_Store(&has_processing_thread_, value); |
| 100 } | 104 } |
| 101 | 105 |
| 102 // Used in tests to make sure that stack sampling is performed. | 106 // Used in tests to make sure that stack sampling is performed. |
| 103 unsigned js_sample_count() const { return js_sample_count_; } | 107 unsigned js_sample_count() const { return js_sample_count_; } |
| 104 unsigned external_sample_count() const { return external_sample_count_; } | 108 unsigned external_sample_count() const { return external_sample_count_; } |
| 105 void StartCountingSamples() { | 109 void StartCountingSamples() { |
| 106 js_sample_count_ = 0; | 110 js_sample_count_ = 0; |
| 107 external_sample_count_ = 0; | 111 external_sample_count_ = 0; |
| 108 is_counting_samples_ = true; | 112 is_counting_samples_ = true; |
| 109 } | 113 } |
| 110 | 114 |
| 111 class PlatformData; | 115 class PlatformData; |
| 112 PlatformData* platform_data() const { return data_; } | 116 PlatformData* platform_data() const { return data_; } |
| 113 | 117 |
| 114 protected: | 118 protected: |
| 115 // This method is called for each sampling period with the current | 119 // This method is called for each sampling period with the current |
| 116 // program counter. | 120 // program counter. |
| 117 virtual void Tick(TickSample* sample) = 0; | 121 virtual void Tick(TickSample* sample) = 0; |
| 118 | 122 |
| 119 private: | 123 private: |
| 120 void SetActive(bool value) { base::NoBarrier_Store(&active_, value); } | 124 void SetActive(bool value) { base::NoBarrier_Store(&active_, value); } |
| 121 | 125 |
| 126 void SetRegistered(bool value) { base::NoBarrier_Store(®istered_, value); } |
| 127 |
| 122 Isolate* isolate_; | 128 Isolate* isolate_; |
| 123 const int interval_; | 129 const int interval_; |
| 124 base::Atomic32 profiling_; | 130 base::Atomic32 profiling_; |
| 125 base::Atomic32 has_processing_thread_; | 131 base::Atomic32 has_processing_thread_; |
| 126 base::Atomic32 active_; | 132 base::Atomic32 active_; |
| 133 base::Atomic32 registered_; |
| 127 PlatformData* data_; // Platform specific data. | 134 PlatformData* data_; // Platform specific data. |
| 128 // Counts stack samples taken in various VM states. | 135 // Counts stack samples taken in various VM states. |
| 129 bool is_counting_samples_; | 136 bool is_counting_samples_; |
| 130 unsigned js_sample_count_; | 137 unsigned js_sample_count_; |
| 131 unsigned external_sample_count_; | 138 unsigned external_sample_count_; |
| 132 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); | 139 DISALLOW_IMPLICIT_CONSTRUCTORS(Sampler); |
| 133 }; | 140 }; |
| 134 | 141 |
| 135 | 142 |
| 136 } // namespace internal | 143 } // namespace internal |
| 137 } // namespace v8 | 144 } // namespace v8 |
| 138 | 145 |
| 139 #endif // V8_PROFILER_SAMPLER_H_ | 146 #endif // V8_PROFILER_SAMPLER_H_ |
| OLD | NEW |