From d9531c850d52bd91083d7afc2ad47fbeb933539b Mon Sep 17 00:00:00 2001 From: David de Boer Date: Mon, 27 May 2024 12:24:31 +0200 Subject: [PATCH] feat: Monitor memory consumption (#61) --- src/lib/Pipeline.class.ts | 14 +++++++++----- src/utils/memory.ts | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 src/utils/memory.ts diff --git a/src/lib/Pipeline.class.ts b/src/lib/Pipeline.class.ts index dfdcc31..8af3194 100644 --- a/src/lib/Pipeline.class.ts +++ b/src/lib/Pipeline.class.ts @@ -10,6 +10,8 @@ import path from 'node:path'; import * as fs from 'node:fs'; import {isFilePathString, isTriplyDBPathString} from '../utils/guards.js'; import TriplyDB from './TriplyDB.class.js'; +import prettyMilliseconds from 'pretty-ms'; +import {memoryConsumption} from '../utils/memory.js'; interface PipelineOptions { startFromStageName?: string; silent?: boolean; @@ -191,7 +193,10 @@ class Pipeline { iterationsProcessed )}\n Generated quads: ${millify( quadsGenerated - )}\n Duration: ${formatDuration(startTime, performance.now())} `; + )}\n Duration: ${formatDuration( + startTime, + performance.now() + )}\n Memory: ${memoryConsumption()} MB`; }); stage.on('error', e => { spinner.fail(); @@ -229,10 +234,9 @@ class Pipeline { chalk.green( `✔ your pipeline "${chalk.bold( this.name - )}" was completed in ${formatDuration( - this.startTime, - performance.now() - )}` + )}" was completed in ${prettyMilliseconds( + performance.now() - this.startTime + )} using ${memoryConsumption()} MB of memory.` ) ); } diff --git a/src/utils/memory.ts b/src/utils/memory.ts new file mode 100644 index 0000000..00a63c9 --- /dev/null +++ b/src/utils/memory.ts @@ -0,0 +1,2 @@ +export const memoryConsumption = () => + Math.round(process.memoryUsage().heapUsed / 1024 / 1024);