Index: src/platform-win32.cc |
=================================================================== |
--- src/platform-win32.cc (revision 5635) |
+++ src/platform-win32.cc (working copy) |
@@ -1838,17 +1838,25 @@ |
// Context used for sampling the register state of the profiled thread. |
CONTEXT context; |
memset(&context, 0, sizeof(context)); |
- // Loop until the sampler is disengaged, keeping the specified samling freq. |
+ // Loop until the sampler is disengaged, keeping the specified |
+ // sampling frequency. |
for ( ; sampler_->IsActive(); Sleep(sampler_->interval_)) { |
TickSample sample_obj; |
TickSample* sample = CpuProfiler::TickSampleEvent(); |
if (sample == NULL) sample = &sample_obj; |
+ // If the sampler runs in sync with the JS thread, we try to |
+ // suspend it. If we fail, we skip the current sample. |
+ if (sampler_->IsSynchronous()) { |
+ static const DWORD kSuspendFailed = static_cast<DWORD>(-1); |
+ if (SuspendThread(profiled_thread_) == kSuspendFailed) continue; |
+ } |
+ |
// We always sample the VM state. |
sample->state = VMState::current_state(); |
+ |
// If profiling, we record the pc and sp of the profiled thread. |
- if (sampler_->IsProfiling() |
- && SuspendThread(profiled_thread_) != (DWORD)-1) { |
+ if (sampler_->IsProfiling()) { |
context.ContextFlags = CONTEXT_FULL; |
if (GetThreadContext(profiled_thread_, &context) != 0) { |
#if V8_HOST_ARCH_X64 |
@@ -1862,11 +1870,14 @@ |
#endif |
sampler_->SampleStack(sample); |
} |
- ResumeThread(profiled_thread_); |
} |
// Invoke tick handler with program counter and stack pointer. |
sampler_->Tick(sample); |
+ |
+ // If the sampler runs in sync with the JS thread, we have to |
+ // remember to resume it. |
+ if (sampler_->IsSynchronous()) ResumeThread(profiled_thread_); |
} |
} |
}; |
@@ -1883,7 +1894,10 @@ |
// Initialize a profile sampler. |
Sampler::Sampler(int interval, bool profiling) |
- : interval_(interval), profiling_(profiling), active_(false) { |
+ : interval_(interval), |
+ profiling_(profiling), |
+ synchronous_(profiling), |
+ active_(false) { |
data_ = new PlatformData(this); |
} |
@@ -1895,9 +1909,9 @@ |
// Start profiling. |
void Sampler::Start() { |
- // If we are profiling, we need to be able to access the calling |
- // thread. |
- if (IsProfiling()) { |
+ // If we are starting a synchronous sampler, we need to be able to |
+ // access the calling thread. |
+ if (IsSynchronous()) { |
// Get a handle to the calling thread. This is the thread that we are |
// going to profile. We need to make a copy of the handle because we are |
// going to use it in the sampler thread. Using GetThreadHandle() will |