Giter VIP home page Giter VIP logo

performance-nodejs's Introduction

performance-nodejs

Build Status Coverage Status npm Github Releases

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
{
  "lag": 0,
  "heap": {
    "total_heap_size": 6,
    "total_heap_size_executable": 4,
    "total_physical_size": 6,
    "total_available_size": 1423,
    "used_heap_size": 4,
    "heap_size_limit": 1432,
    "malloced_memory": 0,
    "peak_malloced_memory": 1,
    "does_zap_garbage": 0
  },
  "heapSpace": {
    "new_space": {
      "size": 2,
      "used_size": 0,
      "available_size": 1,
      "physical_size": 2
    },
    "old_space": {
      "size": 2,
      "used_size": 2,
      "available_size": 0,
      "physical_size": 2
    },
    "code_space": {
      "size": 2,
      "used_size": 1,
      "available_size": 0,
      "physical_size": 1
    },
    "map_space": {
      "size": 1,
      "used_size": 0,
      "available_size": 0,
      "physical_size": 0
    },
    "large_object_space": {
      "size": 0,
      "used_size": 0,
      "available_size": 1422,
      "physical_size": 0
    }
  },
  "cpuUsage": {
    "user": 1344,
    "system": 197,
    "usedPercent": 0,
    "userUsedPercent": 0,
    "systemUsedPercent": 0,
    "total": 477549
  },
  "memoryUsage": {
    "rss": 23,
    "heapTotal": 6,
    "heapUsed": 4,
    "external": 0
  }
}
performance((data) => {
	console.info(JSON.stringify(data));
}, 'MB', 100);

camelCase

Convert the result to camelCase

const performance = require('performance-nodejs');
performance.camelCase = true;
performance((data) => {
  // {"lag":4,"heap":{"totalHeapSize":6,"totalHeapSizeExecutable":4,"totalPhysicalSize":5 ...
	console.info(JSON.stringify(data));
}, 'MB', 100);

flatten

Flatten the result

const performance = require('performance-nodejs');
performance.camelCase = true;
performance.flatten = true;
performance((data) => {
  // {"lag":1,"heapTotalHeapSize":34639872,"heapTotalHeapSizeExecutable":5767168,"heapTotalPhysicalSize": ...
	console.info(JSON.stringify(data));
}, 'MB', 100);

License

MIT

performance-nodejs's People

Contributors

vicanso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

performance-nodejs's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.