From bec33ebc47a49c5c5ca958472ecaf1dde66f901f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9?= Date: Sat, 19 Oct 2024 21:17:22 -0500 Subject: [PATCH] cli: add `--heap-prof` flag available to `NODE_OPTIONS` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/nodejs/node/issues/54257 Signed-off-by: Juan José Arboleda PR-URL: https://github.com/nodejs/node/pull/54259 Reviewed-By: Zeyu "Alex" Yang Reviewed-By: Franziska Hinkelmann Reviewed-By: Yagiz Nizipli --- doc/api/cli.md | 4 ++++ src/node_options.cc | 12 ++++++++---- .../test-process-env-allowed-flags-are-documented.js | 12 ++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index b4da9f48866aee..cd2f4c27f322ba 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -3076,6 +3076,10 @@ one is included in the list below. * `--force-fips` * `--force-node-api-uncaught-exceptions-policy` * `--frozen-intrinsics` +* `--heap-prof-dir` +* `--heap-prof-interval` +* `--heap-prof-name` +* `--heap-prof` * `--heapsnapshot-near-heap-limit` * `--heapsnapshot-signal` * `--http-parser` diff --git a/src/node_options.cc b/src/node_options.cc index 3bfab2759b18f4..2f99bfcd704c4e 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -617,19 +617,23 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "Start the V8 heap profiler on start up, and write the heap profile " "to disk before exit. If --heap-prof-dir is not specified, write " "the profile to the current working directory.", - &EnvironmentOptions::heap_prof); + &EnvironmentOptions::heap_prof, + kAllowedInEnvvar); AddOption("--heap-prof-name", "specified file name of the V8 heap profile generated with " "--heap-prof", - &EnvironmentOptions::heap_prof_name); + &EnvironmentOptions::heap_prof_name, + kAllowedInEnvvar); AddOption("--heap-prof-dir", "Directory where the V8 heap profiles generated by --heap-prof " "will be placed.", - &EnvironmentOptions::heap_prof_dir); + &EnvironmentOptions::heap_prof_dir, + kAllowedInEnvvar); AddOption("--heap-prof-interval", "specified sampling interval in bytes for the V8 heap " "profile generated with --heap-prof. (default: 512 * 1024)", - &EnvironmentOptions::heap_prof_interval); + &EnvironmentOptions::heap_prof_interval, + kAllowedInEnvvar); #endif // HAVE_INSPECTOR AddOption("--max-http-header-size", "set the maximum size of HTTP headers (default: 16384 (16KB))", diff --git a/test/parallel/test-process-env-allowed-flags-are-documented.js b/test/parallel/test-process-env-allowed-flags-are-documented.js index 4b41b51f904be1..2a40a821314ff3 100644 --- a/test/parallel/test-process-env-allowed-flags-are-documented.js +++ b/test/parallel/test-process-env-allowed-flags-are-documented.js @@ -86,6 +86,18 @@ const difference = (setA, setB) => { return new Set([...setA].filter((x) => !setB.has(x))); }; +// Remove heap prof options if the inspector is not enabled. +// NOTE: this is for ubuntuXXXX_sharedlibs_withoutssl_x64, no SSL, no inspector +// Refs: https://github.com/nodejs/node/pull/54259#issuecomment-2308256647 +if (!process.features.inspector) { + [ + '--heap-prof-dir', + '--heap-prof-interval', + '--heap-prof-name', + '--heap-prof', + ].forEach((opt) => documented.delete(opt)); +} + const overdocumented = difference(documented, process.allowedNodeEnvironmentFlags); assert.strictEqual(overdocumented.size, 0,