Index: src/platform-linux.cc |
diff --git a/src/platform-linux.cc b/src/platform-linux.cc |
index 26de12f86d6332c057c5d0a79c33b6b37dc31e72..30e240d2e50dfaef616eb411c17a1e79e83c62b5 100644 |
--- a/src/platform-linux.cc |
+++ b/src/platform-linux.cc |
@@ -979,19 +979,28 @@ class SignalSender : public Thread { |
vm_tgid_(getpid()), |
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) { |
ScopedLock lock(mutex_); |
SamplerRegistry::AddActiveSampler(sampler); |
if (instance_ == NULL) { |
- // Install a signal handler. |
- 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); |
- |
- // Start a thread that sends SIGPROF signal to VM threads. |
+ // Start a thread that will send SIGPROF signal to VM threads, |
+ // when CPU profiling will be enabled. |
instance_ = new SignalSender(sampler->interval()); |
instance_->Start(); |
} else { |
@@ -1007,12 +1016,7 @@ class SignalSender : public Thread { |
instance_->Join(); |
delete instance_; |
instance_ = NULL; |
- |
- // Restore the old signal handler. |
- if (signal_handler_installed_) { |
- sigaction(SIGPROF, &old_signal_handler_, 0); |
- signal_handler_installed_ = false; |
- } |
+ RestoreSignalHandler(); |
} |
} |
@@ -1024,6 +1028,10 @@ class SignalSender : public Thread { |
bool cpu_profiling_enabled = |
(state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS); |
bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled(); |
+ if (cpu_profiling_enabled && !signal_handler_installed_) |
Mads Ager (chromium)
2011/06/02 10:26:55
Drive-by: please use braces around the bodies of i
|
+ 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) { |