From c4783e37d70c007709aadf56d76d6efd070bec6f Mon Sep 17 00:00:00 2001 From: legendecas Date: Sun, 31 Jul 2022 23:16:48 +0800 Subject: [PATCH] src: nest namespace report in namespace node PR-URL: https://github.com/nodejs/node/pull/44069 Reviewed-By: Darshan Sen Reviewed-By: Colin Ihrig Reviewed-By: Feng Yu Reviewed-By: Minwoo Jung --- src/node_report.cc | 43 +++++++++++++++---------------------- src/node_report.h | 15 ++++++++++--- src/node_report_module.cc | 45 ++++++++++++++++++--------------------- src/node_report_utils.cc | 8 +++---- 4 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/node_report.cc b/src/node_report.cc index edc8ab802b06f7..455d5c4e875060 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -27,15 +27,9 @@ constexpr int NODE_REPORT_VERSION = 2; constexpr int NANOS_PER_SEC = 1000 * 1000 * 1000; constexpr double SEC_PER_MICROS = 1e-6; +namespace node { namespace report { -using node::arraysize; -using node::ConditionVariable; -using node::DiagnosticFilename; -using node::Environment; -using node::JSONWriter; -using node::Mutex; -using node::NativeSymbolDebuggingContext; -using node::TIME_TYPE; + using node::worker::Worker; using v8::Array; using v8::Context; @@ -54,8 +48,6 @@ using v8::TryCatch; using v8::V8; using v8::Value; -namespace per_process = node::per_process; - // Internal/static function declarations static void WriteNodeReport(Isolate* isolate, Environment* env, @@ -129,7 +121,7 @@ std::string TriggerNodeReport(Isolate* isolate, // Regular file. Append filename to directory path if one was specified if (report_directory.length() > 0) { std::string pathname = report_directory; - pathname += node::kPathSeparator; + pathname += kPathSeparator; pathname += filename; outfile.open(pathname, std::ios::out | std::ios::binary); } else { @@ -260,9 +252,9 @@ static void WriteNodeReport(Isolate* isolate, } // Report out the command line. - if (!node::per_process::cli_options->cmdline.empty()) { + if (!per_process::cli_options->cmdline.empty()) { writer.json_arraystart("commandLine"); - for (const std::string& arg : node::per_process::cli_options->cmdline) { + for (const std::string& arg : per_process::cli_options->cmdline) { writer.json_element(arg); } writer.json_arrayend(); @@ -377,8 +369,8 @@ static void PrintVersionInformation(JSONWriter* writer) { // Report Process word size writer->json_keyvalue("wordSize", sizeof(void*) * 8); - writer->json_keyvalue("arch", node::per_process::metadata.arch); - writer->json_keyvalue("platform", node::per_process::metadata.platform); + writer->json_keyvalue("arch", per_process::metadata.arch); + writer->json_keyvalue("platform", per_process::metadata.platform); // Report deps component versions PrintComponentVersions(writer); @@ -528,7 +520,7 @@ static Maybe ErrorToString(Isolate* isolate, maybe_str = error->ToString(context); } else if (error->IsObject()) { MaybeLocal stack = error.As()->Get( - context, node::FIXED_ONE_BYTE_STRING(isolate, "stack")); + context, FIXED_ONE_BYTE_STRING(isolate, "stack")); if (!stack.IsEmpty() && stack.ToLocalChecked()->IsString()) { maybe_str = stack.ToLocalChecked().As(); } @@ -656,7 +648,7 @@ static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate) { static void PrintResourceUsage(JSONWriter* writer) { // Get process uptime in seconds uint64_t uptime = - (uv_hrtime() - node::per_process::node_start_time) / (NANOS_PER_SEC); + (uv_hrtime() - per_process::node_start_time) / (NANOS_PER_SEC); if (uptime == 0) uptime = 1; // avoid division by zero. // Process and current thread usage statistics @@ -714,7 +706,7 @@ static void PrintSystemInformation(JSONWriter* writer) { writer->json_objectstart("environmentVariables"); { - Mutex::ScopedLock lock(node::per_process::env_var_mutex); + Mutex::ScopedLock lock(per_process::env_var_mutex); r = uv_os_environ(&envitems, &envcount); } @@ -794,8 +786,7 @@ static void PrintComponentVersions(JSONWriter* writer) { writer->json_objectstart("componentVersions"); -#define V(key) \ - writer->json_keyvalue(#key, node::per_process::metadata.versions.key); +#define V(key) writer->json_keyvalue(#key, per_process::metadata.versions.key); NODE_VERSIONS_KEYS(V) #undef V @@ -805,18 +796,17 @@ static void PrintComponentVersions(JSONWriter* writer) { // Report runtime release information. static void PrintRelease(JSONWriter* writer) { writer->json_objectstart("release"); - writer->json_keyvalue("name", node::per_process::metadata.release.name); + writer->json_keyvalue("name", per_process::metadata.release.name); #if NODE_VERSION_IS_LTS - writer->json_keyvalue("lts", node::per_process::metadata.release.lts); + writer->json_keyvalue("lts", per_process::metadata.release.lts); #endif #ifdef NODE_HAS_RELEASE_URLS writer->json_keyvalue("headersUrl", - node::per_process::metadata.release.headers_url); - writer->json_keyvalue("sourceUrl", - node::per_process::metadata.release.source_url); + per_process::metadata.release.headers_url); + writer->json_keyvalue("sourceUrl", per_process::metadata.release.source_url); #ifdef _WIN32 - writer->json_keyvalue("libUrl", node::per_process::metadata.release.lib_url); + writer->json_keyvalue("libUrl", per_process::metadata.release.lib_url); #endif // _WIN32 #endif // NODE_HAS_RELEASE_URLS @@ -824,3 +814,4 @@ static void PrintRelease(JSONWriter* writer) { } } // namespace report +} // namespace node diff --git a/src/node_report.h b/src/node_report.h index a8292eb2dd477d..dde48f14ec0f43 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -1,4 +1,7 @@ -#pragma once +#ifndef SRC_NODE_REPORT_H_ +#define SRC_NODE_REPORT_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include "node.h" #include "node_buffer.h" @@ -12,17 +15,18 @@ #include +namespace node { namespace report { // Function declarations - functions in src/node_report.cc std::string TriggerNodeReport(v8::Isolate* isolate, - node::Environment* env, + Environment* env, const char* message, const char* trigger, const std::string& name, v8::Local error); void GetNodeReport(v8::Isolate* isolate, - node::Environment* env, + Environment* env, const char* message, const char* trigger, v8::Local error, @@ -45,3 +49,8 @@ void WriteReport(const v8::FunctionCallbackInfo& info); void GetReport(const v8::FunctionCallbackInfo& info); } // namespace report +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#endif // SRC_NODE_REPORT_H_ diff --git a/src/node_report_module.cc b/src/node_report_module.cc index b57a933972d6c0..29da71b9e2a71f 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -15,11 +15,8 @@ #include #include +namespace node { namespace report { -using node::Environment; -using node::Mutex; -using node::SetMethod; -using node::Utf8Value; using v8::Context; using v8::FunctionCallbackInfo; using v8::HandleScope; @@ -77,48 +74,48 @@ void GetReport(const FunctionCallbackInfo& info) { } static void GetCompact(const FunctionCallbackInfo& info) { - node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); - info.GetReturnValue().Set(node::per_process::cli_options->report_compact); + Mutex::ScopedLock lock(per_process::cli_options_mutex); + info.GetReturnValue().Set(per_process::cli_options->report_compact); } static void SetCompact(const FunctionCallbackInfo& info) { - node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); + Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); Isolate* isolate = env->isolate(); bool compact = info[0]->ToBoolean(isolate)->Value(); - node::per_process::cli_options->report_compact = compact; + per_process::cli_options->report_compact = compact; } static void GetDirectory(const FunctionCallbackInfo& info) { - node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); + Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); - std::string directory = node::per_process::cli_options->report_directory; + std::string directory = per_process::cli_options->report_directory; auto result = String::NewFromUtf8(env->isolate(), directory.c_str()); info.GetReturnValue().Set(result.ToLocalChecked()); } static void SetDirectory(const FunctionCallbackInfo& info) { - node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); + Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); CHECK(info[0]->IsString()); Utf8Value dir(env->isolate(), info[0].As()); - node::per_process::cli_options->report_directory = *dir; + per_process::cli_options->report_directory = *dir; } static void GetFilename(const FunctionCallbackInfo& info) { - node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); + Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); - std::string filename = node::per_process::cli_options->report_filename; + std::string filename = per_process::cli_options->report_filename; auto result = String::NewFromUtf8(env->isolate(), filename.c_str()); info.GetReturnValue().Set(result.ToLocalChecked()); } static void SetFilename(const FunctionCallbackInfo& info) { - node::Mutex::ScopedLock lock(node::per_process::cli_options_mutex); + Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); CHECK(info[0]->IsString()); Utf8Value name(env->isolate(), info[0].As()); - node::per_process::cli_options->report_filename = *name; + per_process::cli_options->report_filename = *name; } static void GetSignal(const FunctionCallbackInfo& info) { @@ -136,15 +133,14 @@ static void SetSignal(const FunctionCallbackInfo& info) { } static void ShouldReportOnFatalError(const FunctionCallbackInfo& info) { - Mutex::ScopedLock lock(node::per_process::cli_options_mutex); - info.GetReturnValue().Set( - node::per_process::cli_options->report_on_fatalerror); + Mutex::ScopedLock lock(per_process::cli_options_mutex); + info.GetReturnValue().Set(per_process::cli_options->report_on_fatalerror); } static void SetReportOnFatalError(const FunctionCallbackInfo& info) { CHECK(info[0]->IsBoolean()); - Mutex::ScopedLock lock(node::per_process::cli_options_mutex); - node::per_process::cli_options->report_on_fatalerror = info[0]->IsTrue(); + Mutex::ScopedLock lock(per_process::cli_options_mutex); + per_process::cli_options->report_on_fatalerror = info[0]->IsTrue(); } static void ShouldReportOnSignal(const FunctionCallbackInfo& info) { @@ -201,7 +197,7 @@ static void Initialize(Local exports, SetReportOnUncaughtException); } -void RegisterExternalReferences(node::ExternalReferenceRegistry* registry) { +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(WriteReport); registry->Register(GetReport); registry->Register(GetCompact); @@ -221,6 +217,7 @@ void RegisterExternalReferences(node::ExternalReferenceRegistry* registry) { } } // namespace report +} // namespace node -NODE_MODULE_CONTEXT_AWARE_INTERNAL(report, report::Initialize) -NODE_MODULE_EXTERNAL_REFERENCE(report, report::RegisterExternalReferences) +NODE_MODULE_CONTEXT_AWARE_INTERNAL(report, node::report::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(report, node::report::RegisterExternalReferences) diff --git a/src/node_report_utils.cc b/src/node_report_utils.cc index 6d8b211b6d1c51..322bc7d5d8579a 100644 --- a/src/node_report_utils.cc +++ b/src/node_report_utils.cc @@ -3,11 +3,9 @@ #include "node_report.h" #include "util-inl.h" +namespace node { namespace report { -using node::JSONWriter; -using node::MallocedBuffer; - static constexpr auto null = JSONWriter::Null{}; // Utility function to format socket information. @@ -210,8 +208,7 @@ void WalkHandle(uv_handle_t* h, void* arg) { // SIGWINCH is used by libuv so always appears. // See http://docs.libuv.org/en/v1.x/signal.html writer->json_keyvalue("signum", handle->signal.signum); - writer->json_keyvalue("signal", - node::signo_string(handle->signal.signum)); + writer->json_keyvalue("signal", signo_string(handle->signal.signum)); break; default: break; @@ -269,3 +266,4 @@ void WalkHandle(uv_handle_t* h, void* arg) { } } // namespace report +} // namespace node