Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Unified Diff: src/sampler.cc

Issue 596533002: Initial implementation of GetStackSample sampling profiler API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix ARM32 build. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/sampler.h ('k') | src/vm-state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/sampler.cc
diff --git a/src/sampler.cc b/src/sampler.cc
index 394efeb7640764870b6f768a9d11a1b879955416..4633712f1c4743bbbbdc459e2a9fc231c04a739b 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,22 +241,16 @@ 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;
}
state->pc = reinterpret_cast<Address>(simulator_->pc());
state->sp = reinterpret_cast<Address>(simulator_->sp());
state->fp = reinterpret_cast<Address>(simulator_->fp());
-#elif V8_TARGET_ARCH_MIPS
- state->pc = reinterpret_cast<Address>(simulator_->get_pc());
- state->sp = reinterpret_cast<Address>(simulator_->get_register(
- Simulator::sp));
- state->fp = reinterpret_cast<Address>(simulator_->get_register(
- Simulator::fp));
-#elif V8_TARGET_ARCH_MIPS64
+#elif V8_TARGET_ARCH_MIPS || V8_TARGET_ARCH_MIPS64
state->pc = reinterpret_cast<Address>(simulator_->get_pc());
state->sp = reinterpret_cast<Address>(simulator_->get_register(
Simulator::sp));
@@ -353,11 +347,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,20 +571,17 @@ 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.
if (state == GC) return;
Address js_entry_sp = isolate->js_entry_sp();
- if (js_entry_sp == 0) {
- // Not executing JS now.
- return;
- }
+ if (js_entry_sp == 0) return; // Not executing JS now.
ExternalCallbackScope* scope = isolate->external_callback_scope();
Address handler = Isolate::handler(isolate->thread_local_top());
@@ -603,18 +594,40 @@ 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();
+
+ SampleInfo info;
+ GetStackSample(isolate, regs, reinterpret_cast<void**>(&stack[0]),
+ kMaxFramesCount, &info);
+ frames_count = static_cast<unsigned>(info.frames_count);
+}
+
+
+void TickSample::GetStackSample(Isolate* isolate, const v8::RegisterState& regs,
+ void** frames, size_t frames_limit,
+ v8::SampleInfo* sample_info) {
+ DCHECK(isolate->IsInitialized());
+ sample_info->frames_count = 0;
+ sample_info->vm_state = isolate->current_vm_state();
+ if (sample_info->vm_state == GC) return;
+
+ Address js_entry_sp = isolate->js_entry_sp();
+ if (js_entry_sp == 0) return; // Not executing JS now.
+
+ SafeStackFrameIterator it(isolate, reinterpret_cast<Address>(regs.fp),
+ reinterpret_cast<Address>(regs.sp), js_entry_sp);
+ size_t i = 0;
+ while (!it.done() && i < frames_limit) {
+ frames[i++] = it.frame()->pc();
it.Advance();
}
- frames_count = i;
+ sample_info->frames_count = i;
}
@@ -682,7 +695,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 +727,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 +738,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
« no previous file with comments | « src/sampler.h ('k') | src/vm-state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698