Skip to content

Commit 192cb72

Browse files
committed
tools: use per-process native Debug() printer in mkcodecache
PR-URL: #31884 Reviewed-By: Anna Henningsen <[email protected]>
1 parent 51bc55f commit 192cb72

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

node.gyp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,16 @@
12591259
],
12601260

12611261
'conditions': [
1262+
[ 'node_use_openssl=="true"', {
1263+
'defines': [
1264+
'HAVE_OPENSSL=1',
1265+
],
1266+
}],
1267+
['v8_enable_inspector==1', {
1268+
'defines': [
1269+
'HAVE_INSPECTOR=1',
1270+
],
1271+
}],
12621272
['OS=="win"', {
12631273
'libraries': [
12641274
'dbghelp.lib',
@@ -1303,6 +1313,16 @@
13031313
],
13041314

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

src/debug_utils.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 10 additions & 15 deletions
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

Lines changed: 3 additions & 0 deletions
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)