Skip to content

Commit 577ffbd

Browse files
committed
internal: add custom dir support for heapsnapshot-signal
1 parent 9e5e2f1 commit 577ffbd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/internal/process/pre_execution.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
ObjectGetOwnPropertyDescriptor,
99
SafeMap,
1010
StringPrototypeStartsWith,
11+
DateNow,
1112
globalThis,
1213
} = primordials;
1314

@@ -365,6 +366,7 @@ function initializeReportSignalHandlers() {
365366

366367
function initializeHeapSnapshotSignalHandlers() {
367368
const signal = getOptionValue('--heapsnapshot-signal');
369+
const diagnosticDir = getOptionValue('--diagnostic-dir');
368370

369371
if (!signal)
370372
return;
@@ -373,7 +375,8 @@ function initializeHeapSnapshotSignalHandlers() {
373375
const { writeHeapSnapshot } = require('v8');
374376

375377
function doWriteHeapSnapshot() {
376-
writeHeapSnapshot();
378+
const heapSnapshotFilename = getHeapSnapshotFilename(diagnosticDir);
379+
writeHeapSnapshot(heapSnapshotFilename);
377380
}
378381
process.on(signal, doWriteHeapSnapshot);
379382

@@ -650,6 +653,11 @@ function markBootstrapComplete() {
650653
internalBinding('performance').markBootstrapComplete();
651654
}
652655

656+
function getHeapSnapshotFilename(diagnosticDir) {
657+
if (!diagnosticDir) return undefined;
658+
return `${diagnosticDir}/Heap.${DateNow()}.heapsnapshot`;
659+
}
660+
653661
module.exports = {
654662
setupUserModules,
655663
prepareMainThreadExecution,

0 commit comments

Comments
 (0)