From f6baa619447a13a145ebaf9eeb23aac01c073baa Mon Sep 17 00:00:00 2001 From: Jithil P Ponnan Date: Thu, 4 May 2023 19:49:52 +1000 Subject: [PATCH] process: add custom directory in heapsnapshot --- lib/internal/process/pre_execution.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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,