From b0df2273abaf9e4e16f8211b1d754282a912784f Mon Sep 17 00:00:00 2001 From: Oleksandr Chekhovskyi Date: Fri, 7 Aug 2015 15:03:04 +0200 Subject: [PATCH] src: fix v8::CpuProfiler idle sampling Ensure that samples are evenly distributed, which is required for v8::CpuProfiler users to work correctly (v8-profiler / node-inspector). PR-URL: https://github.com/nodejs/node/pull/2324 Reviewed-By: Ben Noordhuis --- src/node.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index d48fd2a6c0b9f1..40358f88cecf64 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3567,10 +3567,6 @@ inline void PlatformInit() { RegisterSignalHandler(SIGINT, SignalExit, true); RegisterSignalHandler(SIGTERM, SignalExit, true); - // Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the - // performance penalty of frequent EINTR wakeups when the profiler is running. - uv_loop_configure(uv_default_loop(), UV_LOOP_BLOCK_SIGNAL, SIGPROF); - // Raise the open file descriptor limit. struct rlimit lim; if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) { @@ -3635,6 +3631,15 @@ void Init(int* argc, } } +#ifdef __POSIX__ + // Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the + // performance penalty of frequent EINTR wakeups when the profiler is running. + // Only do this for v8.log profiling, as it breaks v8::CpuProfiler users. + if (v8_is_profiling) { + uv_loop_configure(uv_default_loop(), UV_LOOP_BLOCK_SIGNAL, SIGPROF); + } +#endif + #if defined(NODE_HAVE_I18N_SUPPORT) if (icu_data_dir == nullptr) { // if the parameter isn't given, use the env variable.