From 0a6c1decfb21926855a68a40e477ab212e7eef7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Wed, 7 Aug 2024 18:32:59 -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 --- doc/api/cli.md | 4 ++++ src/node_options.cc | 12 ++++++++---- test/parallel/test-cli-node-options.js | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/api/cli.md b/doc/api/cli.md index c0dfcd418b96a1..aa4f6d5820c954 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -2932,6 +2932,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 210e3647d0b7eb..8058178378c47e 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -604,19 +604,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-cli-node-options.js b/test/parallel/test-cli-node-options.js index 8d614e607177cd..2cbcf284bb23e8 100644 --- a/test/parallel/test-cli-node-options.js +++ b/test/parallel/test-cli-node-options.js @@ -22,6 +22,7 @@ expectNoWorker(`-r ${JSON.stringify(printSpaceA)}`, 'A\nB\n'); expectNoWorker(`-r ${printA} -r ${printA}`, 'A\nB\n'); expectNoWorker(` -r ${printA} -r ${printA}`, 'A\nB\n'); expectNoWorker(` --require ${printA} --require ${printA}`, 'A\nB\n'); +expect('--heap-prof', 'B\n'); expect('--no-deprecation', 'B\n'); expect('--no-warnings', 'B\n'); expect('--no_warnings', 'B\n');