{"_id":"@atsjj/memwatch","_rev":"1-3cb6e8a7108e3692dcc3d8f55def3e4f","name":"@atsjj/memwatch","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@atsjj/memwatch","description":"Keep an eye on your memory usage, and discover and isolate leaks.","version":"1.0.0","main":"include.js","license":"wtfpl","auto-changelog":{"commitLimit":false,"issueUrl":"https://github.com/atsjj/memwatch/issues/{id}","package":"package.json","releaseSummary":true,"template":"https://gist.githubusercontent.com/atsjj/de6998d6750a8b32778fa3380da24301/raw/66a23990c3324f03aa756e45fed70d46389c7eab/normal.hbs"},"bugs":{"url":"https://github.com/atsjj/memwatch/issues"},"contributors":[{"name":"Lloyd Hilaiel","url":"http://lloyd.io"},{"name":"Jed Parsons","url":"https://github.com/jedp"},{"name":"Jeff Haynie","url":"https://github.com/jhaynie"},{"name":"Justin Matthews","url":"https://github.com/jmatthewsr-ms"},{"name":"Pavel Yasiukevich","url":"https://github.com/pavel-yasiukevich"},{"name":"Steve Jabour","url":"https://github.com/atsjj"}],"engines":{"node":">= 10"},"release-it":{"git":{"changelog":"npx auto-changelog --stdout --template https://gist.githubusercontent.com/atsjj/de6998d6750a8b32778fa3380da24301/raw/66a23990c3324f03aa756e45fed70d46389c7eab/compact.hbs","requireCleanWorkingDir":true,"requireUpstream":true,"requireCommits":false,"addUntrackedFiles":false,"commit":true,"commitMessage":"${version}","commitArgs":"--gpg-sign","tag":true,"tagName":"${version}","tagAnnotation":"${version}","tagArgs":"--sign","push":true,"pushArgs":"--follow-tags","pushRepo":"origin"},"npm":{"publish":true}},"repository":{"type":"git","url":"git+https://github.com/atsjj/memwatch.git"},"scripts":{"install":"node-gyp rebuild","test":"ava test.js"},"devDependencies":{"ava":"^3.8.1"},"dependencies":{"bindings":"^1.5.0","nan":"^2.14.1"},"gitHead":"19f0ae38e23a1913a481decb75fcc1a605dba622","gypfile":true,"homepage":"https://github.com/atsjj/memwatch#readme","_id":"@atsjj/memwatch@1.0.0","_nodeVersion":"12.16.0","_npmVersion":"6.14.2","dist":{"integrity":"sha512-P3MgveUQ+qz04sgT3rdGAMVYAyBZw8R6rJrTC+n4rGit4tw3PVkBxm2BW3WIksom1pvuy5tGPcJgMKx4jbkIQA==","shasum":"6c5280d02cae8b619c8bf9fe80f5932e8653eb1d","tarball":"https://registry.npmjs.org/@atsjj/memwatch/-/memwatch-1.0.0.tgz","fileCount":15,"unpackedSize":47403,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJetGu0CRA9TVsSAnZWagAAIdUP/AjJT0z/CFMiBmIY6HRL\nb5/ykLsxCOl40VJAzBhgk3SO9oqjtX4jQDCdtShJBdmJNRFhyth1NyyqMKOV\nsa4o8PVq6gYeHmDQ8qlt0kPnsGen6yk8iRFHDp/O9EaN82H8ey3rzo/T5B+V\np/aFD7vdH1YWHXY8In32HymfHgcnPTa1PY8v+h7LsIDiZQeUR6HIY8UANja+\ntSEhHVqWDgxH4geV9VNzbCtL2r9EXGJCaqZEvurUr+jLPgMWfolITluLSbvw\ny7IjptawD1zjfQu2NMcrk6Sap4XL+9vE7eefpMbISaYt0uRWseMJmlq/yDpF\nbwRBxxDiFD0CWgZg0b9S9RWYdGjjq7agbYP/RDjzTP/PUkYzmIb9gb0jzjJU\nWnpeBlwuPZVf1HJAzyJw/PtzEpODa90q8b/0vc5O7JbJAA65RcXPHi7lxoQi\n5BbVREUAbEOgIF5v1/abNnhMGw3VY4Bs/J8yy5ZSZ6VWIm9o+UbiU9qgV2aX\nFvGpMCVzih0tX2O5B1I1bZtWoBNTzxe14Yr1BPURfi7+kY5trj5EQZp3r88N\n//NEO0SW1ECFoY9mTUDXn2+688eL10nzEzlhzzuwkNzbgudXSl+6mwzNnn2l\nTiQNQPL6pEHoiRIjfwVDbZ8f9+UYzUAjgLzkfghmvFWGuV0hDxYeHHaOnJli\n6riA\r\n=/P5B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2HHCH6tqBvnpT/zyP2LEWg68lnzpKQc+BWvdx8TYbxQIgVnAqErxhf34o/NNZ50hMMZLCZhzoZG17MRLG/SDqmGo="}]},"maintainers":[{"name":"atsjj","email":"steve@jabour.me"}],"_npmUser":{"name":"atsjj","email":"steve@jabour.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/memwatch_1.0.0_1588882356075_0.05960844466784754"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-07T20:12:36.025Z","1.0.0":"2020-05-07T20:12:36.217Z","modified":"2022-04-04T16:19:55.333Z"},"maintainers":[{"name":"atsjj","email":"steve@jabour.me"}],"description":"Keep an eye on your memory usage, and discover and isolate leaks.","homepage":"https://github.com/atsjj/memwatch#readme","repository":{"type":"git","url":"git+https://github.com/atsjj/memwatch.git"},"contributors":[{"name":"Lloyd Hilaiel","url":"http://lloyd.io"},{"name":"Jed Parsons","url":"https://github.com/jedp"},{"name":"Jeff Haynie","url":"https://github.com/jhaynie"},{"name":"Justin Matthews","url":"https://github.com/jmatthewsr-ms"},{"name":"Pavel Yasiukevich","url":"https://github.com/pavel-yasiukevich"},{"name":"Steve Jabour","url":"https://github.com/atsjj"}],"bugs":{"url":"https://github.com/atsjj/memwatch/issues"},"license":"wtfpl","readme":"# Memwatch\n\n[![Latest npm release][npm-badge]][npm-badge-url]\n[![TravisCI Build Status][travis-badge]][travis-badge-url]\n\n[npm-badge]: https://img.shields.io/npm/v/@atsjj/memwatch.svg\n[npm-badge-url]: https://www.npmjs.com/package/@atsjj/memwatch\n[travis-badge]: https://img.shields.io/travis/com/atsjj/memwatch/master.svg?label=TravisCI\n[travis-badge-url]: https://travis-ci.com/atsjj/memwatch\n[license-url]: http://wtfpl.net\n[memwatch-next-url]: https://github.com/marcominetti/node-memwatch\n\nLeak Detection and Heap Diffing for Node.JS. This is a fork of [memwatch-next][memwatch-next-url]\nthat adds support for newer versions of Node.\n\n`memwatch` is here to help you detect and find memory leaks in\nNode.JS code.  It provides:\n\n* A `leak` event, emitted when it appears your code is leaking memory.\n\n* A `stats` event, emitted occasionally, giving you\n  data describing your heap usage and trends over time.\n\n* A `HeapDiff` class that lets you compare the state of your heap between\n  two points in time, telling you what has been allocated, and what\n  has been released.\n\n## Installation\n\n```\nnpm install --save @atsjj/memwatch\n```\n\n## Description\n\nThere are a growing number of tools for debugging and profiling memory usage in Node.JS\napplications, but there is still a need for a platform-independent native module that requires no\nspecial instrumentation.\n\nThis module attempts to satisfy that need.\n\nTo get started, import `memwatch` like so:\n\n```javascript\nconst memwatch = require('@atsjj/memwatch');\n```\n\n### Leak Detection\n\nYou can then subscribe to `leak` events.  A `leak` event will be emitted when your heap usage has\nincreased for five consecutive garbage collections:\n\n```javascript\nmemwatch.on('leak', function(info) { ... });\n```\n\nThe `info` object will look something like:\n\n```javascript\n{ start: Fri, 29 Jun 2012 14:12:13 GMT,\n  end: Fri, 29 Jun 2012 14:12:33 GMT,\n  growth: 67984,\n  reason: 'heap growth over 5 consecutive GCs (20s) - 11.67 mb/hr' }\n```\n\n### Heap Usage\n\nThe best way to evaluate your memory footprint is to look at heap\nusage right after V8 performs garbage collection.  `memwatch` does\nexactly this - it checks heap usage only after GC to give you a stable\nbaseline of your actual memory usage.\n\nWhen V8 performs a garbage collection (technically, we're talking\nabout a full GC with heap compaction), `memwatch` will emit a `stats`\nevent.\n\n```javascript\nmemwatch.on('stats', function(stats) { ... });\n```\n\nThe `stats` data will look something like this:\n\n```javascript\n{\n  \"num_full_gc\": 17,\n  \"num_inc_gc\": 8,\n  \"heap_compactions\": 8,\n  \"estimated_base\": 2592568,\n  \"current_base\": 2592568,\n  \"min\": 2499912,\n  \"max\": 2592568,\n  \"usage_trend\": 0\n}\n```\n\n`estimated_base` and `usage_trend` are tracked over time.  If usage\ntrend is consistently positive, it indicates that your base heap size\nis continuously growing and you might have a leak.\n\nV8 has its own idea of when it's best to perform a GC, and under a\nheavy load, it may defer this action for some time.  To aid in\nspeedier debugging, `memwatch` provides a `gc()` method to force V8 to\ndo a full GC and heap compaction.\n\n\n### Heap Diffing\n\nSo far we have seen how `memwatch` can aid in leak detection.  For\nleak isolation, it provides a `HeapDiff` class that takes two snapshots\nand computes a diff between them.  For example:\n\n```javascript\n// Take first snapshot\nconst hd = new memwatch.HeapDiff();\n\n// do some things ...\n\n// Take the second snapshot and compute the diff\nconst diff = hd.end();\n```\n\nThe contents of `diff` will look something like:\n\n```javascript\n{\n  \"before\": { \"nodes\": 11625, \"size_bytes\": 1869904, \"size\": \"1.78 mb\" },\n  \"after\":  { \"nodes\": 21435, \"size_bytes\": 2119136, \"size\": \"2.02 mb\" },\n  \"change\": { \"size_bytes\": 249232, \"size\": \"243.39 kb\", \"freed_nodes\": 197,\n    \"allocated_nodes\": 10007,\n    \"details\": [\n      { \"what\": \"String\",\n        \"size_bytes\": -2120,  \"size\": \"-2.07 kb\",  \"+\": 3,    \"-\": 62\n      },\n      { \"what\": \"Array\",\n        \"size_bytes\": 66687,  \"size\": \"65.13 kb\",  \"+\": 4,    \"-\": 78\n      },\n      { \"what\": \"LeakingClass\",\n        \"size_bytes\": 239952, \"size\": \"234.33 kb\", \"+\": 9998, \"-\": 0\n      }\n    ]\n  }\n}\n```\n\nThe diff shows that during the sample period, the total number of\nallocated `String` and `Array` classes decreased, but `Leaking Class`\ngrew by 9998 allocations.  Hmmm.\n\nYou can use `HeapDiff` in your `on('stats')` callback; even though it\ntakes a memory snapshot, which triggers a V8 GC, it will not trigger\nthe `stats` event itself.  Because that would be silly.\n\n## Tests\n\n```\nnpm install\nnpm test\n```\n\n## Contributing\n\nPlease see the Issues to share suggestions and contribute!\n\n## License\n\nThe original `memwatch` package is the original work of Lloyd Hilaiel\n([http://lloyd.io](http://lloyd.io)) and as such retains the original license.\n\nThis project is licensed under the [WTFPL][license-url].\n","readmeFilename":"README.md"}