Skip to content

Commit

Permalink
internal: add custom dir support for heapsnapshot-signal
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJithil committed May 4, 2023
1 parent 9e5e2f1 commit 577ffbd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
ObjectGetOwnPropertyDescriptor,
SafeMap,
StringPrototypeStartsWith,
DateNow,
globalThis,
} = primordials;

Expand Down Expand Up @@ -365,6 +366,7 @@ function initializeReportSignalHandlers() {

function initializeHeapSnapshotSignalHandlers() {
const signal = getOptionValue('--heapsnapshot-signal');
const diagnosticDir = getOptionValue('--diagnostic-dir');

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

function doWriteHeapSnapshot() {
writeHeapSnapshot();
const heapSnapshotFilename = getHeapSnapshotFilename(diagnosticDir);
writeHeapSnapshot(heapSnapshotFilename);
}
process.on(signal, doWriteHeapSnapshot);

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 577ffbd

Please sign in to comment.