From 7d992f41296030324c26ed56bc0023f2343725a1 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Mon, 20 Dec 2021 02:28:59 +0100 Subject: [PATCH] Added triggers to memory dump. --- src/app.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/app.js b/src/app.js index 923503f8..3d98d188 100644 --- a/src/app.js +++ b/src/app.js @@ -46,7 +46,7 @@ async function snapshotMemory() { logger.info(`Saved heap dump to ${filepath}`); } -async function stopMemorySample() { +async function stopMemorySample(snapshotTriggers) { const profile = await inspector.heap.stopSampling(); const filepath = `${dayjs().format('traxxx_sample_YYYY-MM-DD_HH-mm-ss')}.heapprofile`; const usage = process.memoryUsage.rss() / 1000000; @@ -56,12 +56,15 @@ async function stopMemorySample() { logger.info(`Saved heap sample to ${filepath}`); - if (usage > 1000) { + if (usage > snapshotTriggers[0]) { await snapshotMemory(); + return snapshotTriggers.slice(1); } + + return snapshotTriggers; } -async function startMemorySample() { +async function startMemorySample(snapshotTriggers = []) { await inspector.heap.enable(); await inspector.heap.startSampling(); @@ -70,10 +73,10 @@ async function startMemorySample() { logger.info(`Start heap sampling, memory usage: ${usage} MB`); setTimeout(async () => { - await stopMemorySample(); + const newSnapshotTriggers = await stopMemorySample(snapshotTriggers); if (!done) { - await startMemorySample(); + await startMemorySample(newSnapshotTriggers); } }, 30000); } @@ -81,7 +84,7 @@ async function startMemorySample() { async function init() { try { if (argv.sampleMemory) { - await startMemorySample(); + await startMemorySample([1000]); } if (argv.logActive) {