Skip to content

Commit bb41383

Browse files
joyeecheungMylesBorins
authored andcommitted
tools: use per-process native Debug() printer in mkcodecache
PR-URL: #31884 Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 6aa797b commit bb41383

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

node.gyp

+20
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,16 @@
12581258
],
12591259

12601260
'conditions': [
1261+
[ 'node_use_openssl=="true"', {
1262+
'defines': [
1263+
'HAVE_OPENSSL=1',
1264+
],
1265+
}],
1266+
['v8_enable_inspector==1', {
1267+
'defines': [
1268+
'HAVE_INSPECTOR=1',
1269+
],
1270+
}],
12611271
['OS=="win"', {
12621272
'libraries': [
12631273
'dbghelp.lib',
@@ -1302,6 +1312,16 @@
13021312
],
13031313

13041314
'conditions': [
1315+
[ 'node_use_openssl=="true"', {
1316+
'defines': [
1317+
'HAVE_OPENSSL=1',
1318+
],
1319+
}],
1320+
['v8_enable_inspector==1', {
1321+
'defines': [
1322+
'HAVE_INSPECTOR=1',
1323+
],
1324+
}],
13051325
['OS=="win"', {
13061326
'libraries': [
13071327
'Dbghelp.lib',

src/debug_utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void FWrite(FILE* file, const std::string& str);
4242
NODE_ASYNC_PROVIDER_TYPES(V) \
4343
V(INSPECTOR_SERVER) \
4444
V(INSPECTOR_PROFILER) \
45+
V(CODE_CACHE) \
4546
V(WASI)
4647

4748
enum class DebugCategory {

tools/code_cache/cache_builder.cc

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache_builder.h"
2+
#include "debug_utils-inl.h"
23
#include "node_native_module.h"
34
#include "util.h"
45

@@ -67,8 +68,7 @@ static void GetInitializer(const std::string& id, std::stringstream& ss) {
6768
}
6869

6970
static std::string GenerateCodeCache(
70-
const std::map<std::string, ScriptCompiler::CachedData*>& data,
71-
bool log_progress) {
71+
const std::map<std::string, ScriptCompiler::CachedData*>& data) {
7272
std::stringstream ss;
7373
ss << R"(#include <cinttypes>
7474
#include "node_native_module_env.h"
@@ -89,11 +89,13 @@ const bool has_code_cache = true;
8989
total += cached_data->length;
9090
std::string def = GetDefinition(id, cached_data->length, cached_data->data);
9191
ss << def << "\n\n";
92-
if (log_progress) {
93-
std::cout << "Generated cache for " << id
94-
<< ", size = " << FormatSize(cached_data->length)
95-
<< ", total = " << FormatSize(total) << "\n";
96-
}
92+
std::string size_str = FormatSize(cached_data->length);
93+
std::string total_str = FormatSize(total);
94+
per_process::Debug(DebugCategory::CODE_CACHE,
95+
"Generated cache for %s, size = %s, total = %s\n",
96+
id.c_str(),
97+
size_str.c_str(),
98+
total_str.c_str());
9799
}
98100

99101
ss << R"(void NativeModuleEnv::InitializeCodeCache() {
@@ -142,14 +144,7 @@ std::string CodeCacheBuilder::Generate(Local<Context> context) {
142144
}
143145
}
144146

145-
char env_buf[32];
146-
size_t env_size = sizeof(env_buf);
147-
int ret = uv_os_getenv("NODE_DEBUG", env_buf, &env_size);
148-
bool log_progress = false;
149-
if (ret == 0 && strcmp(env_buf, "mkcodecache") == 0) {
150-
log_progress = true;
151-
}
152-
return GenerateCodeCache(data, log_progress);
147+
return GenerateCodeCache(data);
153148
}
154149

155150
} // namespace native_module

tools/code_cache/mkcodecache.cc

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <vector>
77

88
#include "cache_builder.h"
9+
#include "debug_utils-inl.h"
910
#include "libplatform/libplatform.h"
1011
#include "v8.h"
1112

@@ -40,6 +41,8 @@ int main(int argc, char* argv[]) {
4041
return 1;
4142
}
4243

44+
node::per_process::enabled_debug_list.Parse(nullptr);
45+
4346
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
4447
v8::V8::InitializePlatform(platform.get());
4548
v8::V8::Initialize();

0 commit comments

Comments
 (0)