memory-visualizer v1.0.4
Package for Node.js.
Table Of Contents
Installation
npm i --save-dev memory-visualizerExamples
First example:
And the second example where user logs are stacked above the memory meter:
Usage
This is a simple library with which you can display memory usage in the termianl window. You can include it in your root file and either start it programatically with parameters or pass the parameters in the cli options and then trigger the toggle in the terminal with CTRL + S on your keyboard. Programatic usage:
const memoryVisualizer = require('memory-visualizer')
const stop = memoryVisualizer.start(13, 'rss')
setTimeout(() => stop(), 1e4) // Stop in 10 seconds.Terminal usage (in my-root-file.js memory-visualizer must be included):
OR node my-root-file.js --memoryVisualizerFps=13 --memoryVisualizerMemoryName=rss
OR node my-root-file.js --memoryVisualizerFps=13
OR node my-root-file.js --memoryVisualizerMemoryName=rssTip
This utility may be useful, during the memory leak(s) detection process.
Tests
Works on the following Node.js versions: 7.0.0, 8.0.0, 9.0.0, 10.0.0, 11.0.0, 12.0.0, 12.7.0. Tested on the following OSs: Ubuntu 18.04.2 LTS, MacOS 10.11 "El Capitan" & Windows 10 Pro.
Specs
- {Function} start(fps, memoryName, memoryCapacityForDisplay): Function - starts the visualization
process.
- param {number} fps- (Frames Per Second) is the paramter which
specifies how many times per second must the process reprint the memory
usage. Defaults to
30. If a value type will not be anumberit will throw aTypeError; Maximum threshold is60, passing more then that will throw anError. - param {string} memoryName - this can be set to
rss,heapTotal,heapUsedorexternal(defaults torss). Passing other value will throw anError. - param {number} memoryCapacityForDisplay - after a lot of search, I
wasn't able to find the default value of
--max-old-space-sizeanywhere, so I set the approximation (1200 MB) based on my observations (but still - on different operating systems, when I tried to reach the maximum memory capacity it showed more less diferent results, so this value is not precise). Because of that you can set this value as a third parameter of start function and also you can pass it as a CLI option. - return {Function} stop(): void - this function is used to stop the printing process.
- param {number} fps- (Frames Per Second) is the paramter which
specifies how many times per second must the process reprint the memory
usage. Defaults to
- CTRL + S - turns on and off the megabyte meter on both programtic stratup
and by only requiring the package into the root file. When it is only
included and not
start()ed, it won't be shown by default.
- Starting using CLI
node my-root-file.js- {number} --memoryVisualizerFps - same definition as
startmethod'sfpsparam. - {string} --memoryVisualizerMemoryName - same definition as
startmethod'smemoryNameparam. - {number} --memoryVisualizerMemoryCapacityForDisplay - same definition
as
startmethod'smemoryCapacityForDisplayparam.
- {number} --memoryVisualizerFps - same definition as
Important Notes
- Node.js API returns used memory in bytes. Then it is converted to megabytes. Bytes are converted into megabytes not in mebibytes.
- Some terminals may not support ANSI colors, so the megabyte meter pipes will have white or the color you have set as a default option for the text.
Error Reporting
For any issue, feel free to create the GitHub issue.
