Added total run time indicator.

This commit is contained in:
DebaucheryLibrarian 2024-10-26 02:12:46 +02:00
parent 24cd92807c
commit b5b09a7dce
1 changed files with 7 additions and 3 deletions

View File

@ -1,12 +1,14 @@
'use strict'; 'use strict';
const startTime = new Date();
const config = require('config'); const config = require('config');
const util = require('util'); const util = require('util');
const unprint = require('unprint'); const unprint = require('unprint');
// const log = require('why-is-node-running'); // const log = require('why-is-node-running');
const Inspector = require('inspector-api'); const Inspector = require('inspector-api');
const fs = require('fs').promises; const fs = require('fs').promises;
const dayjs = require('dayjs'); const { format, formatDistanceStrict } = require('date-fns');
const argv = require('./argv'); const argv = require('./argv');
const initServer = require('./web/server'); const initServer = require('./web/server');
@ -53,7 +55,7 @@ function logActive() {
async function snapshotMemory(trigger) { async function snapshotMemory(trigger) {
const profile = await inspector.heap.takeSnapshot(); const profile = await inspector.heap.takeSnapshot();
const filepath = `traxxx_snapshot_${trigger}M_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapsnapshot`; const filepath = `traxxx_snapshot_${trigger}M_${format(new Date(), 'yyyy-MM-dd_HH-mm-ss')}.heapsnapshot`;
logger.info(`Starting heap snapshot, memory usage: ${process.memoryUsage.rss() / 1000000} MB`); logger.info(`Starting heap snapshot, memory usage: ${process.memoryUsage.rss() / 1000000} MB`);
@ -67,7 +69,7 @@ async function stopMemorySample(snapshotTriggers) {
const usage = process.memoryUsage.rss() / 1000000; const usage = process.memoryUsage.rss() / 1000000;
const profile = await inspector.heap.stopSampling(); const profile = await inspector.heap.stopSampling();
const filepath = `traxxx_sample_${dayjs().format('YYYY-MM-DD_HH-mm-ss')}.heapprofile`; const filepath = `traxxx_sample_${format(new Date(), 'yyyy-MM-dd_HH-mm-ss')}.heapprofile`;
await inspector.heap.disable(); await inspector.heap.disable();
await fs.writeFile(filepath, JSON.stringify(profile)); await fs.writeFile(filepath, JSON.stringify(profile));
@ -208,6 +210,8 @@ async function init() {
await associateMovieScenes(storedMovies, [...storedScenes, ...storedMovieScenes]); await associateMovieScenes(storedMovies, [...storedScenes, ...storedMovieScenes]);
} }
logger.info(`Completed in ${formatDistanceStrict(new Date(), startTime)}`);
} catch (error) { } catch (error) {
console.trace(error); console.trace(error);
logger.error(error); logger.error(error);