| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_CPU_PROFILER_H_ | 5 #ifndef V8_PROFILER_CPU_PROFILER_H_ |
| 6 #define V8_PROFILER_CPU_PROFILER_H_ | 6 #define V8_PROFILER_CPU_PROFILER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) | 126 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) |
| 127 #undef DECLARE_TYPE | 127 #undef DECLARE_TYPE |
| 128 }; | 128 }; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 | 131 |
| 132 // This class implements both the profile events processor thread and | 132 // This class implements both the profile events processor thread and |
| 133 // methods called by event producers: VM and stack sampler threads. | 133 // methods called by event producers: VM and stack sampler threads. |
| 134 class ProfilerEventsProcessor : public base::Thread { | 134 class ProfilerEventsProcessor : public base::Thread { |
| 135 public: | 135 public: |
| 136 ProfilerEventsProcessor(ProfileGenerator* generator, | 136 ProfilerEventsProcessor(Isolate* isolate, ProfileGenerator* generator, |
| 137 sampler::Sampler* sampler, | |
| 138 base::TimeDelta period); | 137 base::TimeDelta period); |
| 139 virtual ~ProfilerEventsProcessor(); | 138 virtual ~ProfilerEventsProcessor(); |
| 140 | 139 |
| 141 // Thread control. | 140 // Thread control. |
| 142 virtual void Run(); | 141 virtual void Run(); |
| 143 void StopSynchronously(); | 142 void StopSynchronously(); |
| 144 INLINE(bool running()) { return !!base::NoBarrier_Load(&running_); } | 143 INLINE(bool running()) { return !!base::NoBarrier_Load(&running_); } |
| 145 void Enqueue(const CodeEventsContainer& event); | 144 void Enqueue(const CodeEventsContainer& event); |
| 146 | 145 |
| 147 // Puts current stack into tick sample events buffer. | 146 // Puts current stack into tick sample events buffer. |
| 148 void AddCurrentStack(Isolate* isolate, bool update_stats = false); | 147 void AddCurrentStack(Isolate* isolate, bool update_stats = false); |
| 149 void AddDeoptStack(Isolate* isolate, Address from, int fp_to_sp_delta); | 148 void AddDeoptStack(Isolate* isolate, Address from, int fp_to_sp_delta); |
| 150 | 149 |
| 151 // Tick sample events are filled directly in the buffer of the circular | 150 // Tick sample events are filled directly in the buffer of the circular |
| 152 // queue (because the structure is of fixed width, but usually not all | 151 // queue (because the structure is of fixed width, but usually not all |
| 153 // stack frame entries are filled.) This method returns a pointer to the | 152 // stack frame entries are filled.) This method returns a pointer to the |
| 154 // next record of the buffer. | 153 // next record of the buffer. |
| 155 inline TickSample* StartTickSample(); | 154 inline TickSample* StartTickSample(); |
| 156 inline void FinishTickSample(); | 155 inline void FinishTickSample(); |
| 157 | 156 |
| 158 // SamplingCircularQueue has stricter alignment requirements than a normal new | 157 // SamplingCircularQueue has stricter alignment requirements than a normal new |
| 159 // can fulfil, so we need to provide our own new/delete here. | 158 // can fulfil, so we need to provide our own new/delete here. |
| 160 void* operator new(size_t size); | 159 void* operator new(size_t size); |
| 161 void operator delete(void* ptr); | 160 void operator delete(void* ptr); |
| 162 | 161 |
| 162 sampler::Sampler* sampler() { return sampler_.get(); } |
| 163 |
| 163 private: | 164 private: |
| 164 // Called from events processing thread (Run() method.) | 165 // Called from events processing thread (Run() method.) |
| 165 bool ProcessCodeEvent(); | 166 bool ProcessCodeEvent(); |
| 166 | 167 |
| 167 enum SampleProcessingResult { | 168 enum SampleProcessingResult { |
| 168 OneSampleProcessed, | 169 OneSampleProcessed, |
| 169 FoundSampleForNextCodeEvent, | 170 FoundSampleForNextCodeEvent, |
| 170 NoSamplesInQueue | 171 NoSamplesInQueue |
| 171 }; | 172 }; |
| 172 SampleProcessingResult ProcessOneSample(); | 173 SampleProcessingResult ProcessOneSample(); |
| 173 | 174 |
| 174 ProfileGenerator* generator_; | 175 ProfileGenerator* generator_; |
| 175 sampler::Sampler* sampler_; | 176 std::unique_ptr<sampler::Sampler> sampler_; |
| 176 base::Atomic32 running_; | 177 base::Atomic32 running_; |
| 177 const base::TimeDelta period_; // Samples & code events processing period. | 178 const base::TimeDelta period_; // Samples & code events processing period. |
| 178 LockedQueue<CodeEventsContainer> events_buffer_; | 179 LockedQueue<CodeEventsContainer> events_buffer_; |
| 179 static const size_t kTickSampleBufferSize = 1 * MB; | 180 static const size_t kTickSampleBufferSize = 1 * MB; |
| 180 static const size_t kTickSampleQueueLength = | 181 static const size_t kTickSampleQueueLength = |
| 181 kTickSampleBufferSize / sizeof(TickSampleEventRecord); | 182 kTickSampleBufferSize / sizeof(TickSampleEventRecord); |
| 182 SamplingCircularQueue<TickSampleEventRecord, | 183 SamplingCircularQueue<TickSampleEventRecord, |
| 183 kTickSampleQueueLength> ticks_buffer_; | 184 kTickSampleQueueLength> ticks_buffer_; |
| 184 LockedQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 185 LockedQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
| 185 base::AtomicNumber<unsigned> last_code_event_id_; | 186 base::AtomicNumber<unsigned> last_code_event_id_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 202 void StartProfiling(String* title, bool record_samples); | 203 void StartProfiling(String* title, bool record_samples); |
| 203 CpuProfile* StopProfiling(const char* title); | 204 CpuProfile* StopProfiling(const char* title); |
| 204 CpuProfile* StopProfiling(String* title); | 205 CpuProfile* StopProfiling(String* title); |
| 205 int GetProfilesCount(); | 206 int GetProfilesCount(); |
| 206 CpuProfile* GetProfile(int index); | 207 CpuProfile* GetProfile(int index); |
| 207 void DeleteAllProfiles(); | 208 void DeleteAllProfiles(); |
| 208 void DeleteProfile(CpuProfile* profile); | 209 void DeleteProfile(CpuProfile* profile); |
| 209 | 210 |
| 210 void CodeEventHandler(const CodeEventsContainer& evt_rec) override; | 211 void CodeEventHandler(const CodeEventsContainer& evt_rec) override; |
| 211 | 212 |
| 212 // Invoked from stack sampler (thread or signal handler.) | |
| 213 inline TickSample* StartTickSample(); | |
| 214 inline void FinishTickSample(); | |
| 215 | |
| 216 bool is_profiling() const { return is_profiling_; } | 213 bool is_profiling() const { return is_profiling_; } |
| 217 | 214 |
| 218 ProfileGenerator* generator() const { return generator_.get(); } | 215 ProfileGenerator* generator() const { return generator_.get(); } |
| 219 ProfilerEventsProcessor* processor() const { return processor_.get(); } | 216 ProfilerEventsProcessor* processor() const { return processor_.get(); } |
| 220 Isolate* isolate() const { return isolate_; } | 217 Isolate* isolate() const { return isolate_; } |
| 221 | 218 |
| 222 private: | 219 private: |
| 223 void StartProcessorIfNotStarted(); | 220 void StartProcessorIfNotStarted(); |
| 224 void StopProcessorIfLastProfile(const char* title); | 221 void StopProcessorIfLastProfile(const char* title); |
| 225 void StopProcessor(); | 222 void StopProcessor(); |
| 226 void ResetProfiles(); | 223 void ResetProfiles(); |
| 227 void LogBuiltins(); | 224 void LogBuiltins(); |
| 228 | 225 |
| 229 Isolate* const isolate_; | 226 Isolate* const isolate_; |
| 230 base::TimeDelta sampling_interval_; | 227 base::TimeDelta sampling_interval_; |
| 231 std::unique_ptr<CpuProfilesCollection> profiles_; | 228 std::unique_ptr<CpuProfilesCollection> profiles_; |
| 232 std::unique_ptr<ProfileGenerator> generator_; | 229 std::unique_ptr<ProfileGenerator> generator_; |
| 233 std::unique_ptr<ProfilerEventsProcessor> processor_; | 230 std::unique_ptr<ProfilerEventsProcessor> processor_; |
| 234 bool saved_is_logging_; | 231 bool saved_is_logging_; |
| 235 bool is_profiling_; | 232 bool is_profiling_; |
| 236 | 233 |
| 237 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 234 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| 238 }; | 235 }; |
| 239 | 236 |
| 240 } // namespace internal | 237 } // namespace internal |
| 241 } // namespace v8 | 238 } // namespace v8 |
| 242 | 239 |
| 243 | 240 |
| 244 #endif // V8_PROFILER_CPU_PROFILER_H_ | 241 #endif // V8_PROFILER_CPU_PROFILER_H_ |
| OLD | NEW |