Added triggers to memory dump.
This commit is contained in:
parent
280032937f
commit
7d992f4129
15
src/app.js
15
src/app.js
|
@ -46,7 +46,7 @@ async function snapshotMemory() {
|
||||||
logger.info(`Saved heap dump to ${filepath}`);
|
logger.info(`Saved heap dump to ${filepath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stopMemorySample() {
|
async function stopMemorySample(snapshotTriggers) {
|
||||||
const profile = await inspector.heap.stopSampling();
|
const profile = await inspector.heap.stopSampling();
|
||||||
const filepath = `${dayjs().format('traxxx_sample_YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
const filepath = `${dayjs().format('traxxx_sample_YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
||||||
const usage = process.memoryUsage.rss() / 1000000;
|
const usage = process.memoryUsage.rss() / 1000000;
|
||||||
|
@ -56,12 +56,15 @@ async function stopMemorySample() {
|
||||||
|
|
||||||
logger.info(`Saved heap sample to ${filepath}`);
|
logger.info(`Saved heap sample to ${filepath}`);
|
||||||
|
|
||||||
if (usage > 1000) {
|
if (usage > snapshotTriggers[0]) {
|
||||||
await snapshotMemory();
|
await snapshotMemory();
|
||||||
|
return snapshotTriggers.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return snapshotTriggers;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startMemorySample() {
|
async function startMemorySample(snapshotTriggers = []) {
|
||||||
await inspector.heap.enable();
|
await inspector.heap.enable();
|
||||||
await inspector.heap.startSampling();
|
await inspector.heap.startSampling();
|
||||||
|
|
||||||
|
@ -70,10 +73,10 @@ async function startMemorySample() {
|
||||||
logger.info(`Start heap sampling, memory usage: ${usage} MB`);
|
logger.info(`Start heap sampling, memory usage: ${usage} MB`);
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await stopMemorySample();
|
const newSnapshotTriggers = await stopMemorySample(snapshotTriggers);
|
||||||
|
|
||||||
if (!done) {
|
if (!done) {
|
||||||
await startMemorySample();
|
await startMemorySample(newSnapshotTriggers);
|
||||||
}
|
}
|
||||||
}, 30000);
|
}, 30000);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +84,7 @@ async function startMemorySample() {
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
if (argv.sampleMemory) {
|
if (argv.sampleMemory) {
|
||||||
await startMemorySample();
|
await startMemorySample([1000]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.logActive) {
|
if (argv.logActive) {
|
||||||
|
|
Loading…
Reference in New Issue