{"id":18672946,"url":"https://github.com/vicanso/performance-nodejs","last_synced_at":"2025-04-12T01:31:21.304Z","repository":{"id":57322134,"uuid":"54557910","full_name":"vicanso/performance-nodejs","owner":"vicanso","description":"get nodejs performance, such as: heap statistics, event loop delay","archived":false,"fork":false,"pushed_at":"2017-06-28T14:10:41.000Z","size":54,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T05:04:54.272Z","etag":null,"topics":["cpu-usage","heap-statistics","memory-usage","nodejs-performance","performance"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vicanso.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-23T12:26:49.000Z","updated_at":"2024-01-12T17:58:45.000Z","dependencies_parsed_at":"2022-08-25T21:01:15.545Z","dependency_job_id":null,"html_url":"https://github.com/vicanso/performance-nodejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fperformance-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fperformance-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fperformance-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fperformance-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicanso","download_url":"https://codeload.github.com/vicanso/performance-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248504245,"owners_count":21115138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu-usage","heap-statistics","memory-usage","nodejs-performance","performance"],"created_at":"2024-11-07T09:13:31.482Z","updated_at":"2025-04-12T01:31:20.977Z","avatar_url":"https://github.com/vicanso.png","language":"JavaScript","readme":"# performance-nodejs\n\n\n[![Build Status](https://travis-ci.org/vicanso/performance-nodejs.svg?style=flat-square)](https://travis-ci.org/vicanso/performance-nodejs)\n[![Coverage Status](https://img.shields.io/coveralls/vicanso/performance-nodejs/master.svg?style=flat)](https://coveralls.io/r/vicanso/performance-nodejs?branch=master)\n[![npm](http://img.shields.io/npm/v/performance-nodejs.svg?style=flat-square)](https://www.npmjs.org/package/performance-nodejs)\n[![Github Releases](https://img.shields.io/npm/dm/performance-nodejs.svg?style=flat-square)](https://github.com/vicanso/performance-nodejs)\n\n  Get nodejs performance, such as: heap statistics, event loop delay\n\n## Installation\n\n```\n$ npm i performance-nodejs\n```\n\n## Examples\n\nView the [./examples](examples) directory for working examples.\n\n\n## Description\n\n  The `performance()` function get node.js performance (include event loop, heap statistics and heap space statistics).\n\n  * If node.js support v8.getHeapSpaceStatistics(), the heap space will be return.\n\n```\nconst timer = performance(fn, interval);\n```\n\n* fn: The callback function to execute.\n\n* interval: Check interval, defaulted to 100ms.\n\n* unit: Set the heap format unit, eg: 'B', 'MB', 'GB', '0.0MB' defaulted to 'B'. `0.00MB` means set 2 precision and 'MB' unit.\n\nReturns: A reference to the timer. Useful for clearing the timer.\n\n\n`cpuUsage` is new in node.js v6.x.\n\n`malloced_memory`, `peak_malloced_memory` and `does_zap_garbage` is new in node.js v7.x\n\n```json\n// node.js performance\n{\n  \"lag\": 0,\n  \"heap\": {\n    \"total_heap_size\": 6,\n    \"total_heap_size_executable\": 4,\n    \"total_physical_size\": 6,\n    \"total_available_size\": 1423,\n    \"used_heap_size\": 4,\n    \"heap_size_limit\": 1432,\n    \"malloced_memory\": 0,\n    \"peak_malloced_memory\": 1,\n    \"does_zap_garbage\": 0\n  },\n  \"heapSpace\": {\n    \"new_space\": {\n      \"size\": 2,\n      \"used_size\": 0,\n      \"available_size\": 1,\n      \"physical_size\": 2\n    },\n    \"old_space\": {\n      \"size\": 2,\n      \"used_size\": 2,\n      \"available_size\": 0,\n      \"physical_size\": 2\n    },\n    \"code_space\": {\n      \"size\": 2,\n      \"used_size\": 1,\n      \"available_size\": 0,\n      \"physical_size\": 1\n    },\n    \"map_space\": {\n      \"size\": 1,\n      \"used_size\": 0,\n      \"available_size\": 0,\n      \"physical_size\": 0\n    },\n    \"large_object_space\": {\n      \"size\": 0,\n      \"used_size\": 0,\n      \"available_size\": 1422,\n      \"physical_size\": 0\n    }\n  },\n  \"cpuUsage\": {\n    \"user\": 1344,\n    \"system\": 197,\n    \"usedPercent\": 0,\n    \"userUsedPercent\": 0,\n    \"systemUsedPercent\": 0,\n    \"total\": 477549\n  },\n  \"memoryUsage\": {\n    \"rss\": 23,\n    \"heapTotal\": 6,\n    \"heapUsed\": 4,\n    \"external\": 0\n  }\n}\n```\n\n```\nperformance((data) =\u003e {\n\tconsole.info(JSON.stringify(data));\n}, 'MB', 100);\n```\n\n### camelCase\n\nConvert the result to camelCase\n\n```js\nconst performance = require('performance-nodejs');\nperformance.camelCase = true;\nperformance((data) =\u003e {\n  // {\"lag\":4,\"heap\":{\"totalHeapSize\":6,\"totalHeapSizeExecutable\":4,\"totalPhysicalSize\":5 ...\n\tconsole.info(JSON.stringify(data));\n}, 'MB', 100);\n```\n\n### flatten\n\nFlatten the result\n\n```js\nconst performance = require('performance-nodejs');\nperformance.camelCase = true;\nperformance.flatten = true;\nperformance((data) =\u003e {\n  // {\"lag\":1,\"heapTotalHeapSize\":34639872,\"heapTotalHeapSizeExecutable\":5767168,\"heapTotalPhysicalSize\": ...\n\tconsole.info(JSON.stringify(data));\n}, 'MB', 100);\n```\n\n# License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fperformance-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicanso%2Fperformance-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fperformance-nodejs/lists"}