Added centralized movie page fetcher. Added memory heap dump.

This commit is contained in:
DebaucheryLibrarian
2021-12-20 02:22:10 +01:00
parent d93670842b
commit 280032937f
3 changed files with 38 additions and 33 deletions

View File

@@ -34,33 +34,40 @@ function logActive() {
}, typeof argv.logActive === 'number' ? argv.logActive : 60000);
}
/*
function monitorMemory() {
logger.debug(`Memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
async function snapshotMemory() {
const profile = await inspector.heap.takeSnapshot();
const filepath = `${dayjs().format('traxxx_snapshot_YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
if (!done) {
setTimeout(() => monitorMemory(), 10000);
}
logger.info(`Start heap snapshots, memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
await inspector.heap.disable();
await fs.writeFile(filepath, JSON.stringify(profile));
logger.info(`Saved heap dump to ${filepath}`);
}
*/
async function stopMemorySample() {
const profile = await inspector.heap.stopSampling();
const filepath = `${dayjs().format('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;
await inspector.heap.disable();
await fs.writeFile(filepath, JSON.stringify(profile));
logger.info(`Saved heap sample to ${filepath}`);
if (usage > 1000) {
await snapshotMemory();
}
}
async function startMemorySample() {
await inspector.heap.enable();
await inspector.heap.startSampling();
// monitorMemory();
const usage = process.memoryUsage.rss() / 1000000;
logger.info(`Start heap sampling, memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
logger.info(`Start heap sampling, memory usage: ${usage} MB`);
setTimeout(async () => {
await stopMemorySample();
@@ -73,7 +80,7 @@ async function startMemorySample() {
async function init() {
try {
if (argv.memory) {
if (argv.sampleMemory) {
await startMemorySample();
}