Chromium Code Reviews| Index: src/platform-linux.cc |
| diff --git a/src/platform-linux.cc b/src/platform-linux.cc |
| index d02244896bcf8930ecd895a92a7b2ab5a5365b32..655529064fb1ca4928b3127de676085ead8c2da3 100644 |
| --- a/src/platform-linux.cc |
| +++ b/src/platform-linux.cc |
| @@ -1080,8 +1080,14 @@ class SignalSender : public Thread { |
| vm_tgid_(getpid()), |
| interval_(interval) {} |
| - static void SetUp() { if (!mutex_) mutex_ = OS::CreateMutex(); } |
| - static void TearDown() { delete mutex_; } |
| + static void SetUp() { |
| + if (!mutex_) mutex_ = OS::CreateMutex(); |
| + InstallSignalHandler(); |
|
caseq
2012/08/16 14:39:22
So SignalSender has nothing to do with CPU profili
|
| + } |
| + static void TearDown() { |
| + RestoreSignalHandler(); |
| + delete mutex_; |
| + } |
| static void InstallSignalHandler() { |
| struct sigaction sa; |
| @@ -1128,67 +1134,24 @@ class SignalSender : public Thread { |
| SamplerRegistry::State state; |
| while ((state = SamplerRegistry::GetState()) != |
| SamplerRegistry::HAS_NO_SAMPLERS) { |
| - bool cpu_profiling_enabled = |
| - (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); |
| bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); |
| - if (cpu_profiling_enabled && !signal_handler_installed_) { |
| - InstallSignalHandler(); |
| - } else if (!cpu_profiling_enabled && signal_handler_installed_) { |
| - RestoreSignalHandler(); |
| - } |
| // When CPU profiling is enabled both JavaScript and C++ code is |
| // profiled. We must not suspend. |
| - if (!cpu_profiling_enabled) { |
| - if (rate_limiter_.SuspendIfNecessary()) continue; |
| - } |
| - if (cpu_profiling_enabled && runtime_profiler_enabled) { |
| - if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this)) { |
| - return; |
| - } |
| - Sleep(HALF_INTERVAL); |
| + if (rate_limiter_.SuspendIfNecessary()) continue; |
| + if (runtime_profiler_enabled) { |
| if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) { |
| return; |
| } |
| - Sleep(HALF_INTERVAL); |
| - } else { |
| - if (cpu_profiling_enabled) { |
| - if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, |
| - this)) { |
| - return; |
| - } |
| - } |
| - if (runtime_profiler_enabled) { |
| - if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, |
| - NULL)) { |
| - return; |
| - } |
| - } |
| - Sleep(FULL_INTERVAL); |
| } |
| + Sleep(FULL_INTERVAL); |
| } |
| } |
| - static void DoCpuProfile(Sampler* sampler, void* raw_sender) { |
| - if (!sampler->IsProfiling()) return; |
| - SignalSender* sender = reinterpret_cast<SignalSender*>(raw_sender); |
| - sender->SendProfilingSignal(sampler->platform_data()->vm_tid()); |
| - } |
| - |
| static void DoRuntimeProfile(Sampler* sampler, void* ignored) { |
| if (!sampler->isolate()->IsInitialized()) return; |
| sampler->isolate()->runtime_profiler()->NotifyTick(); |
| } |
| - void SendProfilingSignal(int tid) { |
| - if (!signal_handler_installed_) return; |
| - // Glibc doesn't provide a wrapper for tgkill(2). |
| -#if defined(ANDROID) |
| - syscall(__NR_tgkill, vm_tgid_, tid, SIGPROF); |
| -#else |
| - syscall(SYS_tgkill, vm_tgid_, tid, SIGPROF); |
| -#endif |
| - } |
| - |
| void Sleep(SleepInterval full_or_half) { |
| // Convert ms to us and subtract 100 us to compensate delays |
| // occuring during signal delivery. |
| @@ -1296,4 +1259,23 @@ void Sampler::Stop() { |
| } |
| +CpuProfilerThread::CpuProfilerThread(Sampler* sampler) |
| + : Thread(Thread::Options("CpuProfiler", kCpuProfilerThreadStackSize)), |
| + vm_tgid_(getpid()), |
| + sampler_(sampler) { |
| +} |
| + |
| + |
| +void CpuProfilerThread::DoCpuProfile() { |
|
caseq
2012/08/16 14:39:22
DoCpuProfile -> DoSample?
|
| + int tid = sampler_->platform_data()->vm_tid(); |
| + if (!SignalSender::signal_handler_installed_) return; |
| + // Glibc doesn't provide a wrapper for tgkill(2). |
| +#if defined(ANDROID) |
| + syscall(__NR_tgkill, vm_tgid_, tid, SIGPROF); |
| +#else |
| + syscall(SYS_tgkill, vm_tgid_, tid, SIGPROF); |
| +#endif |
| +} |
| + |
| + |
| } } // namespace v8::internal |