I will test this new code tonight, and upload it to the changelist, but
here is a new version:
// If profiling, we record the pc and sp of the profiled thread.
if (sampler_->IsProfiling()
&& KERN_SUCCESS == thread_suspend(profiled_thread_)) {
#if V8_HOST_ARCH_X64
thread_state_flavor_t flavor = x86_THREAD_STATE64;
x86_thread_state64_t state;
mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT;
#define REGISTER_PREFIX_LETTER r
#elif V8_HOST_ARCH_IA32
thread_state_flavor_t flavor = i386_THREAD_STATE;
i386_thread_state_t state;
mach_msg_type_number_t count = i386_THREAD_STATE_COUNT;
#define REGISTER_PREFIX_LETTER e
#else
#error Unsupported Mac OS X host architecture.
#endif // V8_HOST_ARCH
#if __DARWIN_UNIX03
#define REGISTER_FIELD(name) (__ ## REGISTER_PREFIX_LETTER ## name)
#else
#define REGISTER_FIELD(name) (REGISTER_PREFIX_LETTER ## name)
#endif // __DARWIN_UNIX03
if (thread_get_state(profiled_thread_,
flavor,
reinterpret_cast<natural_t*>(&state),
&count) == KERN_SUCCESS) {
sample.pc = state.REGISTER_FIELD(ip);
sample.sp = state.REGISTER_FIELD(sp);
sample.fp = state.REGISTER_FIELD(bp);
sampler_->SampleStack(&sample);
}
thread_resume(profiled_thread_);
}
// We always sample the VM state.
sample.state = Logger::state();
// Invoke tick handler with program counter and stack pointer.
sampler_->Tick(&sample);
// Wait until next sampling.
usleep(sampler_->interval_ * 1000);
}
}
};
#undef REGISTER_PREFIX_LETTER
#undef REGISTER_FIELD
http://codereview.chromium.org/151004
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---