Skip to content

Commit

Permalink
bootstrap: print information for snapshot at environment exit in debug
Browse files Browse the repository at this point in the history
Print information relevant to snapshot building at the environment
exit when NODE_DEBUG_NATIVE is set to include mksnapshot. This helps
us understand what need to be fixed to build a snapshot when a script
is run to completion.

PR-URL: #37967
Refs: #37476
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and legendecas committed Apr 8, 2021
1 parent 9cfb418 commit 6cb314b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api/embed_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Maybe<int> SpinEventLoop(Environment* env) {
if (env->is_stopping()) return Nothing<int>();

env->set_trace_sync_io(false);
env->PrintInfoForSnapshotIfDebug();
env->VerifyNoStrongBaseObjects();
return EmitProcessExit(env);
}
Expand Down
19 changes: 19 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,25 @@ void Environment::RemoveUnmanagedFd(int fd) {
}
}

void Environment::PrintInfoForSnapshotIfDebug() {
if (enabled_debug_list()->enabled(DebugCategory::MKSNAPSHOT)) {
fprintf(stderr, "BaseObjects at the exit of the Environment:\n");
PrintAllBaseObjects();
fprintf(stderr, "\nNative modules without cache:\n");
for (const auto& s : native_modules_without_cache) {
fprintf(stderr, "%s\n", s.c_str());
}
fprintf(stderr, "\nNative modules with cache:\n");
for (const auto& s : native_modules_with_cache) {
fprintf(stderr, "%s\n", s.c_str());
}
fprintf(stderr, "\nStatic bindings (need to be registered):\n");
for (const auto mod : internal_bindings) {
fprintf(stderr, "%s:%s\n", mod->nm_filename, mod->nm_modname);
}
}
}

void Environment::PrintAllBaseObjects() {
size_t i = 0;
std::cout << "BaseObjects\n";
Expand Down
2 changes: 2 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ class Environment : public MemoryRetainer {
void CreateProperties();
void DeserializeProperties(const EnvSerializeInfo* info);

void PrintInfoForSnapshotIfDebug();
void PrintAllBaseObjects();
void VerifyNoStrongBaseObjects();
void EnqueueDeserializeRequest(DeserializeRequestCallback cb,
Expand Down Expand Up @@ -1123,6 +1124,7 @@ class Environment : public MemoryRetainer {
// List of id's that have been destroyed and need the destroy() cb called.
inline std::vector<double>* destroy_async_id_list();

std::set<struct node_module*> internal_bindings;
std::set<std::string> native_modules_with_cache;
std::set<std::string> native_modules_without_cache;
// This is only filled during deserialization. We use a vector since
Expand Down
1 change: 1 addition & 0 deletions src/node_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
node_module* mod = FindModule(modlist_internal, *module_v, NM_F_INTERNAL);
if (mod != nullptr) {
exports = InitModule(env, mod, module);
env->internal_bindings.insert(mod);
} else if (!strcmp(*module_v, "constants")) {
exports = Object::New(env->isolate());
CHECK(
Expand Down

0 comments on commit 6cb314b

Please sign in to comment.