Skip to content
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
bootstrap: print information for snapshot at environment exit in debug
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.
  • Loading branch information
joyeecheung committed Mar 29, 2021
commit 2e2efaa76a1127d4e3783aec47446abf405ce11d
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 @@ -958,6 +958,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 @@ -1121,6 +1122,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