forked from DebaucheryLibrarian/traxxx
Added memory profiling.
This commit is contained in:
parent
c1aea78496
commit
972b15e72d
|
@ -8,3 +8,4 @@ config/*
|
||||||
!config/default.js
|
!config/default.js
|
||||||
assets/js/config/
|
assets/js/config/
|
||||||
!assets/js/config/default.js
|
!assets/js/config/default.js
|
||||||
|
*.heapprofile
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -108,6 +108,7 @@
|
||||||
"html-entities": "^2.3.2",
|
"html-entities": "^2.3.2",
|
||||||
"iconv-lite": "^0.5.1",
|
"iconv-lite": "^0.5.1",
|
||||||
"inquirer": "^7.3.3",
|
"inquirer": "^7.3.3",
|
||||||
|
"inspector-api": "^1.4.2",
|
||||||
"jsdom": "^16.3.0",
|
"jsdom": "^16.3.0",
|
||||||
"knex": "^0.21.13",
|
"knex": "^0.21.13",
|
||||||
"knex-migrate": "^1.7.4",
|
"knex-migrate": "^1.7.4",
|
||||||
|
|
40
src/app.js
40
src/app.js
|
@ -2,11 +2,15 @@
|
||||||
|
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const log = require('why-is-node-running');
|
const log = require('why-is-node-running');
|
||||||
|
const Inspector = require('inspector-api');
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const dayjs = require('dayjs');
|
||||||
|
|
||||||
const argv = require('./argv');
|
const argv = require('./argv');
|
||||||
const initServer = require('./web/server');
|
const initServer = require('./web/server');
|
||||||
const http = require('./utils/http');
|
const http = require('./utils/http');
|
||||||
|
|
||||||
|
const logger = require('./logger')(__filename);
|
||||||
const knex = require('./knex');
|
const knex = require('./knex');
|
||||||
const fetchUpdates = require('./updates');
|
const fetchUpdates = require('./updates');
|
||||||
const { fetchScenes, fetchMovies } = require('./deep');
|
const { fetchScenes, fetchMovies } = require('./deep');
|
||||||
|
@ -17,6 +21,8 @@ const { deleteScenes, deleteMovies, flushScenes, flushMovies, flushBatches } = r
|
||||||
const { flushOrphanedMedia } = require('./media');
|
const { flushOrphanedMedia } = require('./media');
|
||||||
const getFileEntries = require('./utils/file-entries');
|
const getFileEntries = require('./utils/file-entries');
|
||||||
|
|
||||||
|
const inspector = new Inspector();
|
||||||
|
|
||||||
function logActive() {
|
function logActive() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
log();
|
log();
|
||||||
|
@ -24,7 +30,26 @@ function logActive() {
|
||||||
}, typeof argv.logActive === 'number' ? argv.logActive : 60000);
|
}, typeof argv.logActive === 'number' ? argv.logActive : 60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function stopMemorySample() {
|
||||||
|
const profile = await inspector.heap.stopSampling();
|
||||||
|
const filepath = `${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapprofile`;
|
||||||
|
|
||||||
|
await inspector.heap.disable();
|
||||||
|
|
||||||
|
fs.writeFile(filepath, JSON.stringify(profile));
|
||||||
|
|
||||||
|
logger.info(`Saved heap sample to ${filepath}`);
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
|
try {
|
||||||
|
if (argv.memory) {
|
||||||
|
await inspector.heap.enable();
|
||||||
|
await inspector.heap.startSampling();
|
||||||
|
|
||||||
|
logger.info('Started heap sampling');
|
||||||
|
}
|
||||||
|
|
||||||
if (argv.logActive) {
|
if (argv.logActive) {
|
||||||
logActive();
|
logActive();
|
||||||
}
|
}
|
||||||
|
@ -124,7 +149,22 @@ async function init() {
|
||||||
await associateMovieScenes(storedMovies, storedScenes);
|
await associateMovieScenes(storedMovies, storedScenes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argv.memory) {
|
||||||
|
await stopMemorySample();
|
||||||
|
}
|
||||||
|
|
||||||
knex.destroy();
|
knex.destroy();
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
|
||||||
|
if (argv.memory) {
|
||||||
|
await stopMemorySample();
|
||||||
|
}
|
||||||
|
|
||||||
|
knex.destroy();
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = init;
|
module.exports = init;
|
||||||
|
|
Loading…
Reference in New Issue