| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #include "content/renderer/devtools/v8_sampling_profiler.h" | 5 #include "content/renderer/devtools/v8_sampling_profiler.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #define USE_SIGNALS | 9 #define USE_SIGNALS |
| 10 #endif | 10 #endif |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 "0x%" PRIx64, static_cast<uint64>(reinterpret_cast<intptr_t>(value))); | 88 "0x%" PRIx64, static_cast<uint64>(reinterpret_cast<intptr_t>(value))); |
| 89 } | 89 } |
| 90 | 90 |
| 91 class SampleRecord { | 91 class SampleRecord { |
| 92 public: | 92 public: |
| 93 static const int kMaxFramesCountLog2 = 8; | 93 static const int kMaxFramesCountLog2 = 8; |
| 94 static const unsigned kMaxFramesCount = (1u << kMaxFramesCountLog2) - 1; | 94 static const unsigned kMaxFramesCount = (1u << kMaxFramesCountLog2) - 1; |
| 95 | 95 |
| 96 SampleRecord() {} | 96 SampleRecord() {} |
| 97 | 97 |
| 98 base::TimeTicks timestamp() const { return timestamp_; } | 98 base::TraceTicks timestamp() const { return timestamp_; } |
| 99 void Collect(v8::Isolate* isolate, | 99 void Collect(v8::Isolate* isolate, |
| 100 base::TimeTicks timestamp, | 100 base::TraceTicks timestamp, |
| 101 const v8::RegisterState& state); | 101 const v8::RegisterState& state); |
| 102 scoped_refptr<ConvertableToTraceFormat> ToTraceFormat() const; | 102 scoped_refptr<ConvertableToTraceFormat> ToTraceFormat() const; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 base::TimeTicks timestamp_; | 105 base::TraceTicks timestamp_; |
| 106 unsigned vm_state_ : 4; | 106 unsigned vm_state_ : 4; |
| 107 unsigned frames_count_ : kMaxFramesCountLog2; | 107 unsigned frames_count_ : kMaxFramesCountLog2; |
| 108 const void* frames_[kMaxFramesCount]; | 108 const void* frames_[kMaxFramesCount]; |
| 109 | 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(SampleRecord); | 110 DISALLOW_COPY_AND_ASSIGN(SampleRecord); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 void SampleRecord::Collect(v8::Isolate* isolate, | 113 void SampleRecord::Collect(v8::Isolate* isolate, |
| 114 base::TimeTicks timestamp, | 114 base::TraceTicks timestamp, |
| 115 const v8::RegisterState& state) { | 115 const v8::RegisterState& state) { |
| 116 v8::SampleInfo sample_info; | 116 v8::SampleInfo sample_info; |
| 117 isolate->GetStackSample(state, (void**)frames_, kMaxFramesCount, | 117 isolate->GetStackSample(state, (void**)frames_, kMaxFramesCount, |
| 118 &sample_info); | 118 &sample_info); |
| 119 timestamp_ = timestamp; | 119 timestamp_ = timestamp; |
| 120 frames_count_ = sample_info.frames_count; | 120 frames_count_ = sample_info.frames_count; |
| 121 vm_state_ = sample_info.vm_state; | 121 vm_state_ = sample_info.vm_state; |
| 122 } | 122 } |
| 123 | 123 |
| 124 scoped_refptr<ConvertableToTraceFormat> SampleRecord::ToTraceFormat() const { | 124 scoped_refptr<ConvertableToTraceFormat> SampleRecord::ToTraceFormat() const { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 LOG(ERROR) << "pthread_kill failed with error " << error << " " | 275 LOG(ERROR) << "pthread_kill failed with error " << error << " " |
| 276 << strerror(error); | 276 << strerror(error); |
| 277 } | 277 } |
| 278 #endif | 278 #endif |
| 279 InjectPendingEvents(); | 279 InjectPendingEvents(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void Sampler::DoSample(const v8::RegisterState& state) { | 282 void Sampler::DoSample(const v8::RegisterState& state) { |
| 283 // Called in the sampled thread signal handler. | 283 // Called in the sampled thread signal handler. |
| 284 // Because of that it is not allowed to do any memory allocation here. | 284 // Because of that it is not allowed to do any memory allocation here. |
| 285 base::TimeTicks timestamp = base::TimeTicks::NowFromSystemTraceTime(); | 285 base::TraceTicks timestamp = base::TraceTicks::Now(); |
| 286 SampleRecord* record = samples_data_->StartEnqueue(); | 286 SampleRecord* record = samples_data_->StartEnqueue(); |
| 287 if (!record) | 287 if (!record) |
| 288 return; | 288 return; |
| 289 record->Collect(isolate_, timestamp, state); | 289 record->Collect(isolate_, timestamp, state); |
| 290 samples_data_->FinishEnqueue(); | 290 samples_data_->FinishEnqueue(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void Sampler::InjectPendingEvents() { | 293 void Sampler::InjectPendingEvents() { |
| 294 SampleRecord* record = samples_data_->Peek(); | 294 SampleRecord* record = samples_data_->Peek(); |
| 295 while (record) { | 295 while (record) { |
| 296 TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP1( | 296 TRACE_EVENT_SAMPLE_WITH_TID_AND_TIMESTAMP1( |
| 297 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile"), "V8Sample", | 297 TRACE_DISABLED_BY_DEFAULT("v8.cpu_profile"), "V8Sample", |
| 298 platform_data_.thread_id(), | 298 platform_data_.thread_id(), |
| 299 (record->timestamp() - base::TimeTicks()).InMicroseconds(), "data", | 299 (record->timestamp() - base::TraceTicks()).InMicroseconds(), "data", |
| 300 record->ToTraceFormat()); | 300 record->ToTraceFormat()); |
| 301 samples_data_->Remove(); | 301 samples_data_->Remove(); |
| 302 record = samples_data_->Peek(); | 302 record = samples_data_->Peek(); |
| 303 base::subtle::NoBarrier_AtomicIncrement(&samples_count_, 1); | 303 base::subtle::NoBarrier_AtomicIncrement(&samples_count_, 1); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 // static | 307 // static |
| 308 void Sampler::InstallJitCodeEventHandler(Isolate* isolate, void* data) { | 308 void Sampler::InstallJitCodeEventHandler(Isolate* isolate, void* data) { |
| 309 // Called on the sampled V8 thread. | 309 // Called on the sampled V8 thread. |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 render_thread_sampler_->SetEventsToCollectForTest(code_added_events, | 618 render_thread_sampler_->SetEventsToCollectForTest(code_added_events, |
| 619 sample_events); | 619 sample_events); |
| 620 waitable_event_for_testing_.reset(new base::WaitableEvent(false, false)); | 620 waitable_event_for_testing_.reset(new base::WaitableEvent(false, false)); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void V8SamplingProfiler::WaitSamplingEventForTesting() { | 623 void V8SamplingProfiler::WaitSamplingEventForTesting() { |
| 624 waitable_event_for_testing_->Wait(); | 624 waitable_event_for_testing_->Wait(); |
| 625 } | 625 } |
| 626 | 626 |
| 627 } // namespace blink | 627 } // namespace blink |
| OLD | NEW |