Added triggers to memory dump.

This commit is contained in:
DebaucheryLibrarian 2021-12-20 02:28:59 +01:00
parent 280032937f
commit 7d992f4129
1 changed files with 9 additions and 6 deletions

View File

@ -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);
}
async function startMemorySample() {
return snapshotTriggers;
}
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) {