 Chromium Code Reviews
 Chromium Code Reviews Issue 596533002:
  Initial implementation of GetStackSample sampling profiler API.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
    
  
    Issue 596533002:
  Initial implementation of GetStackSample sampling profiler API.  (Closed) 
  Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge| Index: src/sampler.cc | 
| diff --git a/src/sampler.cc b/src/sampler.cc | 
| index 394efeb7640764870b6f768a9d11a1b879955416..6bd84b75d82142d30e645e087bab1967639e6efb 100644 | 
| --- a/src/sampler.cc | 
| +++ b/src/sampler.cc | 
| @@ -226,13 +226,13 @@ class Sampler::PlatformData : public PlatformDataCommon { | 
| #if defined(USE_SIMULATOR) | 
| class SimulatorHelper { | 
| public: | 
| - inline bool Init(Sampler* sampler, Isolate* isolate) { | 
| + inline bool Init(Isolate* isolate) { | 
| simulator_ = isolate->thread_local_top()->simulator_; | 
| // Check if there is active simulator. | 
| return simulator_ != NULL; | 
| } | 
| - inline void FillRegisters(RegisterState* state) { | 
| + inline void FillRegisters(v8::RegisterState* state) { | 
| #if V8_TARGET_ARCH_ARM | 
| state->pc = reinterpret_cast<Address>(simulator_->get_pc()); | 
| state->sp = reinterpret_cast<Address>(simulator_->get_register( | 
| @@ -241,9 +241,9 @@ class SimulatorHelper { | 
| Simulator::r11)); | 
| #elif V8_TARGET_ARCH_ARM64 | 
| if (simulator_->sp() == 0 || simulator_->fp() == 0) { | 
| - // It possible that the simulator is interrupted while it is updating | 
| + // It's possible that the simulator is interrupted while it is updating | 
| // the sp or fp register. ARM64 simulator does this in two steps: | 
| - // first setting it to zero and then setting it to the new value. | 
| + // first setting it to zero and then setting it to a new value. | 
| // Bailout if sp/fp doesn't contain the new value. | 
| return; | 
| } | 
| @@ -353,11 +353,11 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, | 
| Sampler* sampler = isolate->logger()->sampler(); | 
| if (sampler == NULL) return; | 
| - RegisterState state; | 
| + v8::RegisterState state; | 
| #if defined(USE_SIMULATOR) | 
| SimulatorHelper helper; | 
| - if (!helper.Init(sampler, isolate)) return; | 
| + if (!helper.Init(isolate)) return; | 
| helper.FillRegisters(&state); | 
| // It possible that the simulator is interrupted while it is updating | 
| // the sp or fp register. ARM64 simulator does this in two steps: | 
| @@ -577,10 +577,10 @@ SamplerThread* SamplerThread::instance_ = NULL; | 
| // StackTracer implementation | 
| // | 
| DISABLE_ASAN void TickSample::Init(Isolate* isolate, | 
| - const RegisterState& regs) { | 
| + const v8::RegisterState& regs) { | 
| DCHECK(isolate->IsInitialized()); | 
| timestamp = base::TimeTicks::HighResolutionNow(); | 
| - pc = regs.pc; | 
| + pc = reinterpret_cast<Address>(regs.pc); | 
| state = isolate->current_vm_state(); | 
| // Avoid collecting traces while doing GC. | 
| @@ -603,18 +603,36 @@ DISABLE_ASAN void TickSample::Init(Isolate* isolate, | 
| } else { | 
| // Sample potential return address value for frameless invocation of | 
| // stubs (we'll figure out later, if this value makes sense). | 
| - tos = Memory::Address_at(regs.sp); | 
| + tos = Memory::Address_at(reinterpret_cast<Address>(regs.sp)); | 
| has_external_callback = false; | 
| } | 
| - SafeStackFrameIterator it(isolate, regs.fp, regs.sp, js_entry_sp); | 
| + SafeStackFrameIterator it(isolate, reinterpret_cast<Address>(regs.fp), | 
| + reinterpret_cast<Address>(regs.sp), js_entry_sp); | 
| top_frame_type = it.top_frame_type(); | 
| - unsigned i = 0; | 
| - while (!it.done() && i < TickSample::kMaxFramesCount) { | 
| - stack[i++] = it.frame()->pc(); | 
| + | 
| + frames_count = GetStackSample( | 
| + isolate, regs, reinterpret_cast<void**>(&stack[0]), kMaxFramesCount); | 
| +} | 
| + | 
| + | 
| +int TickSample::GetStackSample(Isolate* isolate, const v8::RegisterState& regs, | 
| 
Benedikt Meurer
2014/09/23 05:47:48
Nit: int -> size_t
 
alph
2014/09/23 07:30:46
Done.
 | 
| + void** frames, int frames_limit) { | 
| 
Benedikt Meurer
2014/09/23 05:47:48
Nit: int -> size_t
 
alph
2014/09/23 07:30:46
Done.
 | 
| + DCHECK(isolate->IsInitialized()); | 
| + Address js_entry_sp = isolate->js_entry_sp(); | 
| + if (js_entry_sp == 0) { | 
| + // Not executing JS now. | 
| + return 0; | 
| + } | 
| + | 
| + SafeStackFrameIterator it(isolate, reinterpret_cast<Address>(regs.fp), | 
| + reinterpret_cast<Address>(regs.sp), js_entry_sp); | 
| + int i = 0; | 
| 
Benedikt Meurer
2014/09/23 05:47:48
Nit: int -> size_t
 
alph
2014/09/23 07:30:46
Done.
 | 
| + while (!it.done() && i < frames_limit) { | 
| + frames[i++] = it.frame()->pc(); | 
| it.Advance(); | 
| } | 
| - frames_count = i; | 
| + return i; | 
| } | 
| @@ -682,7 +700,7 @@ void Sampler::DecreaseProfilingDepth() { | 
| } | 
| -void Sampler::SampleStack(const RegisterState& state) { | 
| +void Sampler::SampleStack(const v8::RegisterState& state) { | 
| TickSample* sample = isolate_->cpu_profiler()->StartTickSample(); | 
| TickSample sample_obj; | 
| if (sample == NULL) sample = &sample_obj; | 
| @@ -714,7 +732,7 @@ void Sampler::DoSample() { | 
| #if defined(USE_SIMULATOR) | 
| SimulatorHelper helper; | 
| - if (!helper.Init(this, isolate())) return; | 
| + if (!helper.Init(isolate())) return; | 
| #endif | 
| const DWORD kSuspendFailed = static_cast<DWORD>(-1); | 
| @@ -725,7 +743,7 @@ void Sampler::DoSample() { | 
| memset(&context, 0, sizeof(context)); | 
| context.ContextFlags = CONTEXT_FULL; | 
| if (GetThreadContext(profiled_thread, &context) != 0) { | 
| - RegisterState state; | 
| + v8::RegisterState state; | 
| #if defined(USE_SIMULATOR) | 
| helper.FillRegisters(&state); | 
| #else |