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