performance-nodejs
Get nodejs performance, such as: heap statistics, event loop delay
Installation
$ npm i performance-nodejs
Examples
View the ./examples directory for working examples.
Description
The performance()
function get node.js performance (include event loop, heap statistics and heap space statistics).
- If node.js support v8.getHeapSpaceStatistics(), the heap space will be return.
const timer = performance(fn, interval);
-
fn: The callback function to execute.
-
interval: Check interval, defaulted to 100ms.
-
unit: Set the heap format unit, eg: 'B', 'MB', 'GB', '0.0MB' defaulted to 'B'.
0.00MB
means set 2 precision and 'MB' unit.
Returns: A reference to the timer. Useful for clearing the timer.
cpuUsage
is new in node.js v6.x.
malloced_memory
, peak_malloced_memory
and does_zap_garbage
is new in node.js v7.x
// node.js performance
performance((data) => {
console.info(JSON.stringify(data));
}, 'MB', 100);
camelCase
Convert the result to camelCase
const performance = ;performancecamelCase = true;performance { // {"lag":4,"heap":{"totalHeapSize":6,"totalHeapSizeExecutable":4,"totalPhysicalSize":5 ... console;} 'MB' 100;
flatten
Flatten the result
const performance = ;performancecamelCase = true;performanceflatten = true;performance { // {"lag":1,"heapTotalHeapSize":34639872,"heapTotalHeapSizeExecutable":5767168,"heapTotalPhysicalSize": ... console;} 'MB' 100;
License
MIT