Skip to content

Commit bf44af8

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

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
@@ -1224,6 +1224,16 @@
12241224
],
12251225

12261226
'conditions': [
1227+
[ 'node_use_openssl=="true"', {
1228+
'defines': [
1229+
'HAVE_OPENSSL=1',
1230+
],
1231+
}],
1232+
['v8_enable_inspector==1', {
1233+
'defines': [
1234+
'HAVE_INSPECTOR=1',
1235+
],
1236+
}],
12271237
['OS=="win"', {
12281238
'libraries': [
12291239
'dbghelp.lib',
@@ -1268,6 +1278,16 @@
12681278
],
12691279

12701280
'conditions': [
1281+
[ 'node_use_openssl=="true"', {
1282+
'defines': [
1283+
'HAVE_OPENSSL=1',
1284+
],
1285+
}],
1286+
['v8_enable_inspector==1', {
1287+
'defines': [
1288+
'HAVE_INSPECTOR=1',
1289+
],
1290+
}],
12711291
['OS=="win"', {
12721292
'libraries': [
12731293
'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)