Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow set directory for heapsnapshot #39493

Closed
cheskayang opened this issue Jul 23, 2021 · 14 comments
Closed

allow set directory for heapsnapshot #39493

cheskayang opened this issue Jul 23, 2021 · 14 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@cheskayang
Copy link

Is your feature request related to a problem? Please describe.
Please describe the problem you are trying to solve.
the --heapsnapshot-signal and --heap snapshot-near-heap-limit is very handy when dealing with memory issues.
if we can add a flag to allow setting the directory where the heap snapshop is written to, it would give a lot of flexibility.

Describe the solution you'd like
Please describe the desired behavior.
allow set the directory where heap snapshot is written to

Describe alternatives you've considered
Please describe alternative solutions or features you have considered.

@gireeshpunathil
Copy link
Member

looks like a valid requirement to me!

@gireeshpunathil gireeshpunathil added the feature request Issues that request new features to be added to Node.js. label Jul 31, 2021
@himadriganguly
Copy link
Contributor

I would like to pick this up. Can you please assign this to me?

@gireeshpunathil
Copy link
Member

@himadriganguly - no need of assignment, the above note is sufficient. go ahead!

@himadriganguly
Copy link
Contributor

Ok. Thank you.

@simllll
Copy link
Contributor

simllll commented Jan 17, 2022

Is this possible already somehow?

@tholcman
Copy link

tholcman commented May 4, 2022

Hi,
for those who haven't found it yet:

node --version
v16.15.0

and

--heapsnapshot-near-heap-limit=1 --diagnostic-dir=/diags

works for us, but I guess the same override as with --cpu-prof-dir and others should be possible.

@sergeyampo
Copy link

sergeyampo commented Oct 13, 2022

If I run node with next flags:

node --heapsnapshot-near-heap-limit=2 --heapsnapshot-signal=SIGUSR2 --diagnostic-dir=/diags concurrent.mjs

and try to send a SIGUSR2 signal to a running process I'll notice that .heapsnapshot file will be generated in working directory and --diagnostic-dir flag will be ignored.
Suddenly, --heapsnapshot-near-heap-limit flag generates a snapshot file in --diagnostic-dir directory.
I think it's a bug and it's reproduced on LTS node version 16.18.0 and on 18.10.0 too.

@bnoordhuis
Copy link
Member

Do you have the heapdump module installed? If find node_modules -name \*heapdump* prints anything, the answer is 'yes'.

@mhdawson
Copy link
Member

@bnoordhuis I think their comment is about the heapsnapshot functionality built into node core versus the external module?

@bnoordhuis
Copy link
Member

If you load node-heapdump, it overrides node's own SIGUSR2 handler. You'll get snapshots but not in the directory you specified.

@mhdawson
Copy link
Member

@bnoordhuis got it thanks.

@bnoordhuis
Copy link
Member

Original feature request has been implemented and no follow-up from @sergeyampo so I'm going to go ahead and close this as done.

@thefloweringash
Copy link

If I run node with next flags:

node --heapsnapshot-near-heap-limit=2 --heapsnapshot-signal=SIGUSR2 --diagnostic-dir=/diags concurrent.mjs

and try to send a SIGUSR2 signal to a running process I'll notice that .heapsnapshot file will be generated in working directory and --diagnostic-dir flag will be ignored. Suddenly, --heapsnapshot-near-heap-limit flag generates a snapshot file in --diagnostic-dir directory. I think it's a bug and it's reproduced on LTS node version 16.18.0 and on 18.10.0 too.

I'm also seeing this behavior. Specifically the handler for the signal does not use the diagnostic directory.


Looking at the code, Environment::NearHeapLimitCallback uses diagnostic_dir

node/src/env.cc

Lines 1830 to 1842 in 38e6ac7

std::string dir = env->options()->diagnostic_dir;
if (dir.empty()) {
dir = env->GetCwd();
}
DiagnosticFilename name(env, "Heap", "heapsnapshot");
std::string filename = dir + kPathSeparator + (*name);
Debug(env, DebugCategory::DIAGNOSTICS, "Start generating %s...\n", *name);
HeapProfiler::HeapSnapshotOptions options;
options.numerics_mode = HeapProfiler::NumericsMode::kExposeNumericValues;
options.snapshot_mode = HeapProfiler::HeapSnapshotMode::kExposeInternals;
heap::WriteSnapshot(env, filename.c_str(), options);

but TriggerHeapSnapshot (without an explicit filename) does not:

node/src/heap_utils.cc

Lines 456 to 457 in 38e6ac7

DiagnosticFilename name(env, "Heap", "heapsnapshot");
if (WriteSnapshot(env, *name, options).IsNothing()) return;

@SteffenLanger
Copy link

In case anyone else finds this issue and wonders about a solution for @thefloweringash's message: There is a pending pull request by @MrJithil 💪🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

10 participants