diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index fc6d9ccf4f517b..803d2c8c9b86b3 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -8,6 +8,7 @@ const { ObjectGetOwnPropertyDescriptor, SafeMap, StringPrototypeStartsWith, + DateNow, globalThis, } = primordials; @@ -365,6 +366,7 @@ function initializeReportSignalHandlers() { function initializeHeapSnapshotSignalHandlers() { const signal = getOptionValue('--heapsnapshot-signal'); + const diagnosticDir = getOptionValue('--diagnostic-dir'); if (!signal) return; @@ -373,7 +375,8 @@ function initializeHeapSnapshotSignalHandlers() { const { writeHeapSnapshot } = require('v8'); function doWriteHeapSnapshot() { - writeHeapSnapshot(); + const heapSnapshotFilename = getHeapSnapshotFilename(diagnosticDir); + writeHeapSnapshot(heapSnapshotFilename); } process.on(signal, doWriteHeapSnapshot); @@ -650,6 +653,11 @@ function markBootstrapComplete() { internalBinding('performance').markBootstrapComplete(); } +function getHeapSnapshotFilename(diagnosticDir) { + if (!diagnosticDir) return undefined; + return `${diagnosticDir}/Heap.${DateNow()}.heapsnapshot`; +} + module.exports = { setupUserModules, prepareMainThreadExecution,