From 61d54e771679f59fc92114435d608282dad4c913 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 20 Feb 2020 17:57:55 +0800 Subject: [PATCH] tools: use per-process native Debug() printer in mkcodecache PR-URL: https://github.com/nodejs/node/pull/31884 Reviewed-By: Anna Henningsen --- node.gyp | 20 ++++++++++++++++++++ src/debug_utils.h | 1 + tools/code_cache/cache_builder.cc | 25 ++++++++++--------------- tools/code_cache/mkcodecache.cc | 3 +++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/node.gyp b/node.gyp index 32c0eff96d5e9d..b49f6bfb42eb29 100644 --- a/node.gyp +++ b/node.gyp @@ -1224,6 +1224,16 @@ ], 'conditions': [ + [ 'node_use_openssl=="true"', { + 'defines': [ + 'HAVE_OPENSSL=1', + ], + }], + ['v8_enable_inspector==1', { + 'defines': [ + 'HAVE_INSPECTOR=1', + ], + }], ['OS=="win"', { 'libraries': [ 'dbghelp.lib', @@ -1268,6 +1278,16 @@ ], 'conditions': [ + [ 'node_use_openssl=="true"', { + 'defines': [ + 'HAVE_OPENSSL=1', + ], + }], + ['v8_enable_inspector==1', { + 'defines': [ + 'HAVE_INSPECTOR=1', + ], + }], ['OS=="win"', { 'libraries': [ 'Dbghelp.lib', diff --git a/src/debug_utils.h b/src/debug_utils.h index 200f1cf07cd27b..b654159ac2a24e 100644 --- a/src/debug_utils.h +++ b/src/debug_utils.h @@ -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 { diff --git a/tools/code_cache/cache_builder.cc b/tools/code_cache/cache_builder.cc index 8210355c4c37e2..28d61a6c70c467 100644 --- a/tools/code_cache/cache_builder.cc +++ b/tools/code_cache/cache_builder.cc @@ -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& data, - bool log_progress) { + const std::map& data) { std::stringstream ss; ss << R"(#include #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) { } } - 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 diff --git a/tools/code_cache/mkcodecache.cc b/tools/code_cache/mkcodecache.cc index e5b43a44b8d0d6..34af7bc61ba374 100644 --- a/tools/code_cache/mkcodecache.cc +++ b/tools/code_cache/mkcodecache.cc @@ -6,6 +6,7 @@ #include #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 platform = v8::platform::NewDefaultPlatform(); v8::V8::InitializePlatform(platform.get()); v8::V8::Initialize();