| Index: src/platform-linux.cc
|
| diff --git a/src/platform-linux.cc b/src/platform-linux.cc
|
| index d5ac6fa4642db1333db703f49657ba389885e63e..d200c0c21885301e3ea13d03160518845b0c3a84 100644
|
| --- a/src/platform-linux.cc
|
| +++ b/src/platform-linux.cc
|
| @@ -1020,6 +1020,7 @@ static int GetThreadID() {
|
| static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
|
| USE(info);
|
| if (signal != SIGPROF) return;
|
| +
|
| Isolate* isolate = Isolate::UncheckedCurrent();
|
| if (isolate == NULL || !isolate->IsInitialized() || !isolate->IsInUse()) {
|
| // We require a fully initialized and entered isolate.
|
| @@ -1033,8 +1034,9 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
|
| Sampler* sampler = isolate->logger()->sampler();
|
| if (sampler == NULL || !sampler->IsActive()) return;
|
|
|
| + TickSample sample_obj;
|
| TickSample* sample = CpuProfiler::StartTickSampleEvent(isolate);
|
| - if (sample == NULL) return;
|
| + if (sample == NULL) sample = &sample_obj;
|
|
|
| // Extracting the sample from the context is extremely machine dependent.
|
| ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
|
| @@ -1185,16 +1187,45 @@ class SignalSender : public Thread {
|
| SamplerRegistry::State state;
|
| while ((state = SamplerRegistry::GetState()) !=
|
| SamplerRegistry::HAS_NO_SAMPLERS) {
|
| - if (rate_limiter_.SuspendIfNecessary()) continue;
|
| - if (RuntimeProfiler::IsEnabled()) {
|
| + bool cpu_profiling_enabled =
|
| + (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS);
|
| + bool runtime_profiler_enabled = RuntimeProfiler::IsEnabled();
|
| + // 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, NULL)) {
|
| + return;
|
| + }
|
| + Sleep(HALF_INTERVAL);
|
| if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile, NULL)) {
|
| return;
|
| }
|
| + Sleep(HALF_INTERVAL);
|
| + } else {
|
| + if (cpu_profiling_enabled) {
|
| + if (!SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, NULL)) {
|
| + return;
|
| + }
|
| + }
|
| + if (runtime_profiler_enabled) {
|
| + if (!SamplerRegistry::IterateActiveSamplers(&DoRuntimeProfile,
|
| + NULL)) {
|
| + return;
|
| + }
|
| + }
|
| + Sleep(FULL_INTERVAL);
|
| }
|
| - Sleep(FULL_INTERVAL);
|
| }
|
| }
|
|
|
| + static void DoCpuProfile(Sampler* sampler, void*) {
|
| + if (!sampler->IsProfiling()) return;
|
| + sampler->platform_data()->SendProfilingSignal();
|
| + }
|
| +
|
| static void DoRuntimeProfile(Sampler* sampler, void* ignored) {
|
| if (!sampler->isolate()->IsInitialized()) return;
|
| sampler->isolate()->runtime_profiler()->NotifyTick();
|
| @@ -1279,6 +1310,7 @@ Sampler::Sampler(Isolate* isolate, int interval)
|
| interval_(interval),
|
| profiling_(false),
|
| active_(false),
|
| + has_processing_thread_(false),
|
| samples_taken_(0) {
|
| data_ = new PlatformData;
|
| }
|
| @@ -1297,7 +1329,6 @@ void Sampler::DoSample() {
|
|
|
| void Sampler::Start() {
|
| ASSERT(!IsActive());
|
| - CpuProfilerSignalHandler::InstallSignalHandler();
|
| SetActive(true);
|
| SignalSender::AddActiveSampler(this);
|
| }
|
| @@ -1305,10 +1336,19 @@ void Sampler::Start() {
|
|
|
| void Sampler::Stop() {
|
| ASSERT(IsActive());
|
| - CpuProfilerSignalHandler::RestoreSignalHandler();
|
| SignalSender::RemoveActiveSampler(this);
|
| SetActive(false);
|
| }
|
|
|
|
|
| +void Sampler::StartSampling() {
|
| + CpuProfilerSignalHandler::InstallSignalHandler();
|
| +}
|
| +
|
| +
|
| +void Sampler::StopSampling() {
|
| + CpuProfilerSignalHandler::RestoreSignalHandler();
|
| +}
|
| +
|
| +
|
| } } // namespace v8::internal
|
|
|