mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
tools: use per-process native Debug() printer in mkcodecache
PR-URL: https://github.com/nodejs/node/pull/31884 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
20
node.gyp
20
node.gyp
@@ -1259,6 +1259,16 @@
|
||||
],
|
||||
|
||||
'conditions': [
|
||||
[ 'node_use_openssl=="true"', {
|
||||
'defines': [
|
||||
'HAVE_OPENSSL=1',
|
||||
],
|
||||
}],
|
||||
['v8_enable_inspector==1', {
|
||||
'defines': [
|
||||
'HAVE_INSPECTOR=1',
|
||||
],
|
||||
}],
|
||||
['OS=="win"', {
|
||||
'libraries': [
|
||||
'dbghelp.lib',
|
||||
@@ -1303,6 +1313,16 @@
|
||||
],
|
||||
|
||||
'conditions': [
|
||||
[ 'node_use_openssl=="true"', {
|
||||
'defines': [
|
||||
'HAVE_OPENSSL=1',
|
||||
],
|
||||
}],
|
||||
['v8_enable_inspector==1', {
|
||||
'defines': [
|
||||
'HAVE_INSPECTOR=1',
|
||||
],
|
||||
}],
|
||||
['OS=="win"', {
|
||||
'libraries': [
|
||||
'Dbghelp.lib',
|
||||
|
||||
@@ -42,6 +42,7 @@ void FWrite(FILE* file, const std::string& str);
|
||||
NODE_ASYNC_PROVIDER_TYPES(V) \
|
||||
V(INSPECTOR_SERVER) \
|
||||
V(INSPECTOR_PROFILER) \
|
||||
V(CODE_CACHE) \
|
||||
V(WASI)
|
||||
|
||||
enum class DebugCategory {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "cache_builder.h"
|
||||
#include "debug_utils-inl.h"
|
||||
#include "node_native_module.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -67,8 +68,7 @@ static void GetInitializer(const std::string& id, std::stringstream& ss) {
|
||||
}
|
||||
|
||||
static std::string GenerateCodeCache(
|
||||
const std::map<std::string, ScriptCompiler::CachedData*>& data,
|
||||
bool log_progress) {
|
||||
const std::map<std::string, ScriptCompiler::CachedData*>& data) {
|
||||
std::stringstream ss;
|
||||
ss << R"(#include <cinttypes>
|
||||
#include "node_native_module_env.h"
|
||||
@@ -89,11 +89,13 @@ const bool has_code_cache = true;
|
||||
total += cached_data->length;
|
||||
std::string def = GetDefinition(id, cached_data->length, cached_data->data);
|
||||
ss << def << "\n\n";
|
||||
if (log_progress) {
|
||||
std::cout << "Generated cache for " << id
|
||||
<< ", size = " << FormatSize(cached_data->length)
|
||||
<< ", total = " << FormatSize(total) << "\n";
|
||||
}
|
||||
std::string size_str = FormatSize(cached_data->length);
|
||||
std::string total_str = FormatSize(total);
|
||||
per_process::Debug(DebugCategory::CODE_CACHE,
|
||||
"Generated cache for %s, size = %s, total = %s\n",
|
||||
id.c_str(),
|
||||
size_str.c_str(),
|
||||
total_str.c_str());
|
||||
}
|
||||
|
||||
ss << R"(void NativeModuleEnv::InitializeCodeCache() {
|
||||
@@ -142,14 +144,7 @@ std::string CodeCacheBuilder::Generate(Local<Context> context) {
|
||||
}
|
||||
}
|
||||
|
||||
char env_buf[32];
|
||||
size_t env_size = sizeof(env_buf);
|
||||
int ret = uv_os_getenv("NODE_DEBUG", env_buf, &env_size);
|
||||
bool log_progress = false;
|
||||
if (ret == 0 && strcmp(env_buf, "mkcodecache") == 0) {
|
||||
log_progress = true;
|
||||
}
|
||||
return GenerateCodeCache(data, log_progress);
|
||||
return GenerateCodeCache(data);
|
||||
}
|
||||
|
||||
} // namespace native_module
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "cache_builder.h"
|
||||
#include "debug_utils-inl.h"
|
||||
#include "libplatform/libplatform.h"
|
||||
#include "v8.h"
|
||||
|
||||
@@ -40,6 +41,8 @@ int main(int argc, char* argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
node::per_process::enabled_debug_list.Parse(nullptr);
|
||||
|
||||
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
|
||||
v8::V8::InitializePlatform(platform.get());
|
||||
v8::V8::Initialize();
|
||||
|
||||
Reference in New Issue
Block a user