Skip to content

Commit

Permalink
tools: use per-process native Debug() printer in mkcodecache
Browse files Browse the repository at this point in the history
PR-URL: #31884
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
joyeecheung authored and MylesBorins committed Mar 10, 2020
1 parent 6aa797b commit bb41383
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
20 changes: 20 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,16 @@
],

'conditions': [
[ 'node_use_openssl=="true"', {
'defines': [
'HAVE_OPENSSL=1',
],
}],
['v8_enable_inspector==1', {
'defines': [
'HAVE_INSPECTOR=1',
],
}],
['OS=="win"', {
'libraries': [
'dbghelp.lib',
Expand Down Expand Up @@ -1302,6 +1312,16 @@
],

'conditions': [
[ 'node_use_openssl=="true"', {
'defines': [
'HAVE_OPENSSL=1',
],
}],
['v8_enable_inspector==1', {
'defines': [
'HAVE_INSPECTOR=1',
],
}],
['OS=="win"', {
'libraries': [
'Dbghelp.lib',
Expand Down
1 change: 1 addition & 0 deletions src/debug_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 10 additions & 15 deletions tools/code_cache/cache_builder.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache_builder.h"
#include "debug_utils-inl.h"
#include "node_native_module.h"
#include "util.h"

Expand Down Expand Up @@ -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"
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tools/code_cache/mkcodecache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vector>

#include "cache_builder.h"
#include "debug_utils-inl.h"
#include "libplatform/libplatform.h"
#include "v8.h"

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit bb41383

Please sign in to comment.