| 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 #include "src/profiler/cpu-profiler.h" | 5 #include "src/profiler/cpu-profiler.h" |
| 6 | 6 |
| 7 #include "src/debug/debug.h" | 7 #include "src/debug/debug.h" |
| 8 #include "src/deoptimizer.h" | 8 #include "src/deoptimizer.h" |
| 9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
| 10 #include "src/locked-queue-inl.h" | 10 #include "src/locked-queue-inl.h" |
| 11 #include "src/log-inl.h" | 11 #include "src/log-inl.h" |
| 12 #include "src/profiler/cpu-profiler-inl.h" | 12 #include "src/profiler/cpu-profiler-inl.h" |
| 13 #include "src/vm-state-inl.h" | 13 #include "src/vm-state-inl.h" |
| 14 | 14 |
| 15 #include "include/v8-profiler.h" | |
| 16 | |
| 17 namespace v8 { | 15 namespace v8 { |
| 18 namespace internal { | 16 namespace internal { |
| 19 | 17 |
| 20 static const int kProfilerStackSize = 64 * KB; | 18 static const int kProfilerStackSize = 64 * KB; |
| 21 | 19 |
| 22 | 20 |
| 23 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, | 21 ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator, |
| 24 sampler::Sampler* sampler, | 22 sampler::Sampler* sampler, |
| 25 base::TimeDelta period) | 23 base::TimeDelta period) |
| 26 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), | 24 : Thread(Thread::Options("v8:ProfEvntProc", kProfilerStackSize)), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 | 40 |
| 43 | 41 |
| 44 void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from, | 42 void ProfilerEventsProcessor::AddDeoptStack(Isolate* isolate, Address from, |
| 45 int fp_to_sp_delta) { | 43 int fp_to_sp_delta) { |
| 46 TickSampleEventRecord record(last_code_event_id_.Value()); | 44 TickSampleEventRecord record(last_code_event_id_.Value()); |
| 47 RegisterState regs; | 45 RegisterState regs; |
| 48 Address fp = isolate->c_entry_fp(isolate->thread_local_top()); | 46 Address fp = isolate->c_entry_fp(isolate->thread_local_top()); |
| 49 regs.sp = fp - fp_to_sp_delta; | 47 regs.sp = fp - fp_to_sp_delta; |
| 50 regs.fp = fp; | 48 regs.fp = fp; |
| 51 regs.pc = from; | 49 regs.pc = from; |
| 52 record.sample.Init(isolate, regs, TickSample::kSkipCEntryFrame, false); | 50 record.sample.Init(reinterpret_cast<v8::Isolate*>(isolate), regs, |
| 51 TickSample::kSkipCEntryFrame, false); |
| 52 record.timestamp = record.sample.pc == nullptr |
| 53 ? base::TimeTicks() |
| 54 : base::TimeTicks::HighResolutionNow(); |
| 53 ticks_from_vm_buffer_.Enqueue(record); | 55 ticks_from_vm_buffer_.Enqueue(record); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate, | 58 void ProfilerEventsProcessor::AddCurrentStack(Isolate* isolate, |
| 57 bool update_stats) { | 59 bool update_stats) { |
| 58 TickSampleEventRecord record(last_code_event_id_.Value()); | 60 TickSampleEventRecord record(last_code_event_id_.Value()); |
| 59 RegisterState regs; | 61 RegisterState regs; |
| 60 StackFrameIterator it(isolate); | 62 StackFrameIterator it(isolate); |
| 61 if (!it.done()) { | 63 if (!it.done()) { |
| 62 StackFrame* frame = it.frame(); | 64 StackFrame* frame = it.frame(); |
| 63 regs.sp = frame->sp(); | 65 regs.sp = frame->sp(); |
| 64 regs.fp = frame->fp(); | 66 regs.fp = frame->fp(); |
| 65 regs.pc = frame->pc(); | 67 regs.pc = frame->pc(); |
| 66 } | 68 } |
| 67 record.sample.Init(isolate, regs, TickSample::kSkipCEntryFrame, update_stats); | 69 record.sample.Init(reinterpret_cast<v8::Isolate*>(isolate), regs, |
| 70 TickSample::kSkipCEntryFrame, update_stats); |
| 71 record.timestamp = record.sample.pc == nullptr |
| 72 ? base::TimeTicks() |
| 73 : base::TimeTicks::HighResolutionNow(); |
| 68 ticks_from_vm_buffer_.Enqueue(record); | 74 ticks_from_vm_buffer_.Enqueue(record); |
| 69 } | 75 } |
| 70 | 76 |
| 71 | 77 |
| 72 void ProfilerEventsProcessor::StopSynchronously() { | 78 void ProfilerEventsProcessor::StopSynchronously() { |
| 73 if (!base::NoBarrier_AtomicExchange(&running_, 0)) return; | 79 if (!base::NoBarrier_AtomicExchange(&running_, 0)) return; |
| 74 Join(); | 80 Join(); |
| 75 } | 81 } |
| 76 | 82 |
| 77 | 83 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 95 return false; | 101 return false; |
| 96 } | 102 } |
| 97 | 103 |
| 98 ProfilerEventsProcessor::SampleProcessingResult | 104 ProfilerEventsProcessor::SampleProcessingResult |
| 99 ProfilerEventsProcessor::ProcessOneSample() { | 105 ProfilerEventsProcessor::ProcessOneSample() { |
| 100 TickSampleEventRecord record1; | 106 TickSampleEventRecord record1; |
| 101 if (ticks_from_vm_buffer_.Peek(&record1) && | 107 if (ticks_from_vm_buffer_.Peek(&record1) && |
| 102 (record1.order == last_processed_code_event_id_)) { | 108 (record1.order == last_processed_code_event_id_)) { |
| 103 TickSampleEventRecord record; | 109 TickSampleEventRecord record; |
| 104 ticks_from_vm_buffer_.Dequeue(&record); | 110 ticks_from_vm_buffer_.Dequeue(&record); |
| 105 generator_->RecordTickSample(record.sample); | 111 generator_->RecordTickSample(record.sample, record.timestamp); |
| 106 return OneSampleProcessed; | 112 return OneSampleProcessed; |
| 107 } | 113 } |
| 108 | 114 |
| 109 const TickSampleEventRecord* record = ticks_buffer_.Peek(); | 115 const TickSampleEventRecord* record = ticks_buffer_.Peek(); |
| 110 if (record == NULL) { | 116 if (record == NULL) { |
| 111 if (ticks_from_vm_buffer_.IsEmpty()) return NoSamplesInQueue; | 117 if (ticks_from_vm_buffer_.IsEmpty()) return NoSamplesInQueue; |
| 112 return FoundSampleForNextCodeEvent; | 118 return FoundSampleForNextCodeEvent; |
| 113 } | 119 } |
| 114 if (record->order != last_processed_code_event_id_) { | 120 if (record->order != last_processed_code_event_id_) { |
| 115 return FoundSampleForNextCodeEvent; | 121 return FoundSampleForNextCodeEvent; |
| 116 } | 122 } |
| 117 generator_->RecordTickSample(record->sample); | 123 generator_->RecordTickSample(record->sample, record->timestamp); |
| 118 ticks_buffer_.Remove(); | 124 ticks_buffer_.Remove(); |
| 119 return OneSampleProcessed; | 125 return OneSampleProcessed; |
| 120 } | 126 } |
| 121 | 127 |
| 122 | 128 |
| 123 void ProfilerEventsProcessor::Run() { | 129 void ProfilerEventsProcessor::Run() { |
| 124 while (!!base::NoBarrier_Load(&running_)) { | 130 while (!!base::NoBarrier_Load(&running_)) { |
| 125 base::TimeTicks nextSampleTime = | 131 base::TimeTicks nextSampleTime = |
| 126 base::TimeTicks::HighResolutionNow() + period_; | 132 base::TimeTicks::HighResolutionNow() + period_; |
| 127 base::TimeTicks now; | 133 base::TimeTicks now; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; | 366 ReportBuiltinEventRecord* rec = &evt_rec.ReportBuiltinEventRecord_; |
| 361 Builtins::Name id = static_cast<Builtins::Name>(i); | 367 Builtins::Name id = static_cast<Builtins::Name>(i); |
| 362 rec->start = builtins->builtin(id)->address(); | 368 rec->start = builtins->builtin(id)->address(); |
| 363 rec->builtin_id = id; | 369 rec->builtin_id = id; |
| 364 processor_->Enqueue(evt_rec); | 370 processor_->Enqueue(evt_rec); |
| 365 } | 371 } |
| 366 } | 372 } |
| 367 | 373 |
| 368 } // namespace internal | 374 } // namespace internal |
| 369 } // namespace v8 | 375 } // namespace v8 |
| OLD | NEW |