Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: always enable idle notifier #33138

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/internal/bootstrap/switches/is_main_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const rawMethods = internalBinding('process_methods');
// TODO(joyeecheung): deprecate and remove these underscore methods
process._debugProcess = rawMethods._debugProcess;
process._debugEnd = rawMethods._debugEnd;
process._startProfilerIdleNotifier = rawMethods._startProfilerIdleNotifier;
process._stopProfilerIdleNotifier = rawMethods._stopProfilerIdleNotifier;

// Stubs for legacy methods.
process._startProfilerIdleNotifier = () => {};
process._stopProfilerIdleNotifier = () => {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just turning them into stubs does not seem an ideal way to handle this.

It would be very surprising for me to see that a function would just silently not behave as it originally did (if I would use the function).

I suggest to at least add a note with --pending-deprecation and make this function non-enumerable. Ideally, we could just run CITGM and https://github.com/nodejs/Gzemnid to see how many libraries actually use these. Those should ideally be fixed by us and in that case I would also add a runtime deprecation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR … this PR turns the functionality always-on rather than using these methods to enable or disable it. This isn’t even a breaking change, and in fact adding a runtime deprecation (--pending-deprecation or not) would be far more invasive, so I can’t really agree here at all.

(That being said, I’ll probably not update the PR until I have looked into Ben’s concerns anyway.)

Copy link
Member

@BridgeAR BridgeAR May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user wanted to disable it, it would be a changed behavior?

If we want to prevent usage of an API we should definitely let the user know about it. Just silently doing nothing seems pretty bad to me.

A deprecation notice is IMO also not invasive. If a user does not want to get notified, it's possible to opt-out of those.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user wanted to disable it, it would be a changed behavior?

Only in terms of diagnostic output, not program behavior. Practically speaking, this is not something that’s used in end-user code but in diagnostic platforms.

If we want to prevent usage of an API we should definitely let the user know about it. Just silently doing nothing seems pretty bad to me.

I don’t want to prevent usage of this API, hence the lack of a deprecation.

A deprecation notice is IMO also not be invasive. If a user does not want to get notified, it's possible to opt-out of those.

I mean, you know I disagree strongly here.


function defineStream(name, getter) {
ObjectDefineProperty(process, name, {
Expand Down
2 changes: 0 additions & 2 deletions lib/internal/bootstrap/switches/is_not_main_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const { ObjectDefineProperty } = primordials;

delete process._debugProcess;
delete process._debugEnd;
delete process._startProfilerIdleNotifier;
delete process._stopProfilerIdleNotifier;

function defineStream(name, getter) {
ObjectDefineProperty(process, name, {
Expand Down
2 changes: 1 addition & 1 deletion src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ MaybeLocal<Value> LoadEnvironment(
Environment* env,
StartExecutionCallback cb,
std::unique_ptr<InspectorParentHandle> removeme) {
env->InitializeLibuv(per_process::v8_is_profiling);
env->InitializeLibuv();
env->InitializeDiagnostics();

return StartExecution(env, cb);
Expand Down
4 changes: 0 additions & 4 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ inline Environment* Environment::GetThreadLocalEnv() {
return static_cast<Environment*>(uv_key_get(&thread_local_env));
}

inline bool Environment::profiler_idle_notifier_started() const {
return profiler_idle_notifier_started_;
}

inline v8::Isolate* Environment::isolate() const {
return isolate_;
}
Expand Down
17 changes: 2 additions & 15 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Environment::~Environment() {
CHECK_EQ(base_object_count_, 0);
}

void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
void Environment::InitializeLibuv() {
HandleScope handle_scope(isolate());
Context::Scope context_scope(context());

Expand Down Expand Up @@ -557,9 +557,7 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
// FreeEnvironment.
RegisterHandleCleanups();

if (start_profiler_idle_notifier) {
StartProfilerIdleNotifier();
}
StartProfilerIdleNotifier();
}

void Environment::ExitEnv() {
Expand Down Expand Up @@ -636,11 +634,6 @@ void Environment::CleanupHandles() {
}

void Environment::StartProfilerIdleNotifier() {
if (profiler_idle_notifier_started_)
return;

profiler_idle_notifier_started_ = true;

uv_prepare_start(&idle_prepare_handle_, [](uv_prepare_t* handle) {
Environment* env = ContainerOf(&Environment::idle_prepare_handle_, handle);
env->isolate()->SetIdle(true);
Expand All @@ -652,12 +645,6 @@ void Environment::StartProfilerIdleNotifier() {
});
}

void Environment::StopProfilerIdleNotifier() {
profiler_idle_notifier_started_ = false;
uv_prepare_stop(&idle_prepare_handle_);
uv_check_stop(&idle_check_handle_);
}

void Environment::PrintSyncTrace() const {
if (!trace_sync_io_) return;

Expand Down
5 changes: 1 addition & 4 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ class Environment : public MemoryRetainer {
ThreadId thread_id);
~Environment() override;

void InitializeLibuv(bool start_profiler_idle_notifier);
void InitializeLibuv();
inline const std::vector<std::string>& exec_argv();
inline const std::vector<std::string>& argv();
const std::string& exec_path() const;
Expand Down Expand Up @@ -926,8 +926,6 @@ class Environment : public MemoryRetainer {
const ContextInfo& info);

void StartProfilerIdleNotifier();
void StopProfilerIdleNotifier();
inline bool profiler_idle_notifier_started() const;

inline v8::Isolate* isolate() const;
inline uv_loop_t* event_loop() const;
Expand Down Expand Up @@ -1269,7 +1267,6 @@ class Environment : public MemoryRetainer {
uv_check_t idle_check_handle_;
uv_async_t task_queues_async_;
int64_t task_queues_async_refs_ = 0;
bool profiler_idle_notifier_started_ = false;

AsyncHooks async_hooks_;
ImmediateInfo immediate_info_;
Expand Down
12 changes: 1 addition & 11 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ bool v8_initialized = false;
// node_internals.h
// process-relative uptime base in nanoseconds, initialized in node::Start()
uint64_t node_start_time;
// Tells whether --prof is passed.
bool v8_is_profiling = false;

// node_v8_platform-inl.h
struct V8Platform v8_platform;
Expand Down Expand Up @@ -743,19 +741,11 @@ int ProcessGlobalArgs(std::vector<std::string>* args,
env_opts->abort_on_uncaught_exception = true;
}

// TODO(bnoordhuis) Intercept --prof arguments and start the CPU profiler
// manually? That would give us a little more control over its runtime
// behavior but it could also interfere with the user's intentions in ways
// we fail to anticipate. Dillema.
if (std::find(v8_args.begin(), v8_args.end(), "--prof") != v8_args.end()) {
per_process::v8_is_profiling = true;
}

#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 (per_process::v8_is_profiling) {
if (std::find(v8_args.begin(), v8_args.end(), "--prof") != v8_args.end()) {
uv_loop_configure(uv_default_loop(), UV_LOOP_BLOCK_SIGNAL, SIGPROF);
}
#endif
Expand Down
1 change: 0 additions & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class NativeModuleLoader;
namespace per_process {
extern Mutex env_var_mutex;
extern uint64_t node_start_time;
extern bool v8_is_profiling;
} // namespace per_process

// Forward declaration
Expand Down
14 changes: 0 additions & 14 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,6 @@ void RawDebug(const FunctionCallbackInfo<Value>& args) {
fflush(stderr);
}

static void StartProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
env->StartProfilerIdleNotifier();
}

static void StopProfilerIdleNotifier(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
env->StopProfilerIdleNotifier();
}

static void Umask(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(env->has_run_bootstrapping_code());
Expand Down Expand Up @@ -469,10 +459,6 @@ static void InitializeProcessMethods(Local<Object> target,
env->SetMethod(target, "chdir", Chdir);
}

env->SetMethod(
target, "_startProfilerIdleNotifier", StartProfilerIdleNotifier);
env->SetMethod(target, "_stopProfilerIdleNotifier", StopProfilerIdleNotifier);

env->SetMethod(target, "umask", Umask);
env->SetMethod(target, "_rawDebug", RawDebug);
env->SetMethod(target, "memoryUsage", MemoryUsage);
Expand Down