RuntimeProfiler::IsolateEnteredJS(this);
} else if (current_state == JS && state != JS) {
// JS -> non-JS transition.
- ASSERT(RuntimeProfiler::IsSomeIsolateInJS());
RuntimeProfiler::IsolateExitedJS(this);
} else {
// Other types of state transitions are not interesting to the
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
OS::Sleep(interval_);
}
}
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
}
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (signal_handler_installed_) RestoreSignalHandler();
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
const int vm_tgid_;
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
OS::Sleep(interval_);
}
}
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (signal_handler_installed_) RestoreSignalHandler();
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
const int vm_tgid_;
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
if (signal_handler_installed_) RestoreSignalHandler();
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
Sleep(); // TODO(svenpanne) Figure out if OS:Sleep(interval_) is enough.
}
}
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
if (state == SamplerRegistry::HAS_CPU_PROFILING_SAMPLERS) {
SamplerRegistry::IterateActiveSamplers(&DoCpuProfile, this);
} else {
- if (rate_limiter_.SuspendIfNecessary()) continue;
+ if (RuntimeProfiler::WaitForSomeIsolateToEnterJS()) continue;
}
OS::Sleep(interval_);
}
}
const int interval_;
- RuntimeProfilerRateLimiter rate_limiter_;
// Protects the process wide state below.
static Mutex* mutex_;
}
-bool RuntimeProfiler::IsSomeIsolateInJS() {
- return NoBarrier_Load(&state_) > 0;
-}
-
-
bool RuntimeProfiler::WaitForSomeIsolateToEnterJS() {
Atomic32 old_state = NoBarrier_CompareAndSwap(&state_, 0, -1);
ASSERT(old_state >= -1);
}
-bool RuntimeProfilerRateLimiter::SuspendIfNecessary() {
- if (!RuntimeProfiler::IsSomeIsolateInJS()) {
- return RuntimeProfiler::WaitForSomeIsolateToEnterJS();
- }
- return false;
-}
-
-
} } // namespace v8::internal
// Profiler thread interface.
//
- // IsSomeIsolateInJS():
- // The profiler thread can query whether some isolate is currently
- // running JavaScript code.
- //
// WaitForSomeIsolateToEnterJS():
// When no isolates are running JavaScript code for some time the
// profiler thread suspends itself by calling the wait function. The
// wait function returns true after it waited or false immediately.
// While the function was waiting the profiler may have been
// disabled so it *must check* whether it is allowed to continue.
- static bool IsSomeIsolateInJS();
static bool WaitForSomeIsolateToEnterJS();
// Stops the runtime profiler thread when profiling support is being
};
-// Rate limiter intended to be used in the profiler thread.
-class RuntimeProfilerRateLimiter BASE_EMBEDDED {
- public:
- RuntimeProfilerRateLimiter() {}
-
- // Suspends the current thread (which must be the profiler thread)
- // when not executing JavaScript to minimize CPU usage. Returns
- // whether the thread was suspended (and so must check whether
- // profiling is still active.)
- //
- // Does nothing when runtime profiling is not enabled.
- bool SuspendIfNecessary();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RuntimeProfilerRateLimiter);
-};
-
-
// Implementation of RuntimeProfiler inline functions.
void RuntimeProfiler::IsolateEnteredJS(Isolate* isolate) {