[Linux] Do not install SIGPROF handler until we

start CPU profiling.

TBR=vitalyr@chromium.org
BUG=1344,crbug/79320,crbug/83521
TEST=none

Review URL: http://codereview.chromium.org/7107003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8152 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a60085b2
...@@ -979,19 +979,28 @@ class SignalSender : public Thread { ...@@ -979,19 +979,28 @@ class SignalSender : public Thread {
vm_tgid_(getpid()), vm_tgid_(getpid()),
interval_(interval) {} interval_(interval) {}
static void InstallSignalHandler() {
struct sigaction sa;
sa.sa_sigaction = ProfilerSignalHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
signal_handler_installed_ =
(sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
}
static void RestoreSignalHandler() {
if (signal_handler_installed_) {
sigaction(SIGPROF, &old_signal_handler_, 0);
signal_handler_installed_ = false;
}
}
static void AddActiveSampler(Sampler* sampler) { static void AddActiveSampler(Sampler* sampler) {
ScopedLock lock(mutex_); ScopedLock lock(mutex_);
SamplerRegistry::AddActiveSampler(sampler); SamplerRegistry::AddActiveSampler(sampler);
if (instance_ == NULL) { if (instance_ == NULL) {
// Install a signal handler. // Start a thread that will send SIGPROF signal to VM threads,
struct sigaction sa; // when CPU profiling will be enabled.
sa.sa_sigaction = ProfilerSignalHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
signal_handler_installed_ =
(sigaction(SIGPROF, &sa, &old_signal_handler_) == 0);
// Start a thread that sends SIGPROF signal to VM threads.
instance_ = new SignalSender(sampler->interval()); instance_ = new SignalSender(sampler->interval());
instance_->Start(); instance_->Start();
} else { } else {
...@@ -1007,12 +1016,7 @@ class SignalSender : public Thread { ...@@ -1007,12 +1016,7 @@ class SignalSender : public Thread {
instance_->Join(); instance_->Join();
delete instance_; delete instance_;
instance_ = NULL; instance_ = NULL;
RestoreSignalHandler();
// Restore the old signal handler.
if (signal_handler_installed_) {
sigaction(SIGPROF, &old_signal_handler_, 0);
signal_handler_installed_ = false;
}
} }
} }
...@@ -1024,6 +1028,10 @@ class SignalSender : public Thread { ...@@ -1024,6 +1028,10 @@ class SignalSender : public Thread {
bool cpu_profiling_enabled = bool cpu_profiling_enabled =
(state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); 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 // When CPU profiling is enabled both JavaScript and C++ code is
// profiled. We must not suspend. // profiled. We must not suspend.
if (!cpu_profiling_enabled) { if (!cpu_profiling_enabled) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment