Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
`node-memwatch`: Leak Detection and Heap Diffing for Node.JS
============================================================

[![Build Status](https://travis-ci.org/deepak1556/node-memwatch.svg?branch=master)](https://travis-ci.org/deepak1556/node-memwatch)

`node-memwatch` is here to help you detect and find memory leaks in
Node.JS code. It provides:

Expand All @@ -19,11 +17,11 @@ Node.JS code. It provides:
Installation
------------

- `npm install memwatch-next`
- `npm install node-memwatch`

or

- `git clone git://github.com/marcominetti/node-memwatch.git`
- `git clone https://github.com/eduardbcom/node-memwatch.git`


Description
Expand All @@ -37,7 +35,7 @@ instrumentation. This module attempts to satisfy that need.
To get started, import `node-memwatch` like so:

```javascript
var memwatch = require('memwatch-next');
var memwatch = require('node-memwatch');
```

### Leak Detection
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "memwatch-next",
"name": "node-memwatch",
"description": "Keep an eye on your memory usage, and discover and isolate leaks.",
"version": "0.3.0",
"version": "1.0.0",
"author": "Lloyd Hilaiel (http://lloyd.io)",
"engines": {
"node": ">= 0.8.0"
"node": ">= 8"
},
"repository": {
"type": "git",
"url": "https://github.com/marcominetti/node-memwatch.git"
"url": "https://github.com/eduardbcom/node-memwatch.git"
},
"main": "include.js",
"licenses": [
Expand All @@ -17,7 +17,7 @@
}
],
"bugs": {
"url": "https://github.com/marcominetti/node-memwatch/issues"
"url": "https://github.com/eduardbcom/node-memwatch/issues"
},
"scripts": {
"install": "node-gyp rebuild",
Expand All @@ -30,7 +30,8 @@
"contributors": [
"Jed Parsons (@jedp)",
"Jeff Haynie (@jhaynie)",
"Justin Matthews (@jmatthewsr-ms)"
"Justin Matthews (@jmatthewsr-ms)",
"Eduard Bondarenko (@eduardbcom)"
],
"dependencies": {
"bindings": "^1.2.1",
Expand Down
7 changes: 5 additions & 2 deletions src/heapdiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ NAN_METHOD(heapdiff::HeapDiff::New)
info.GetReturnValue().Set(info.This());
}

static string handleToStr(const Handle<Value> & str)
static string handleToStr(const Local<Value> & str)
{
String::Utf8Value utfString(str->ToString());
v8::Isolate* isolate = v8::Isolate::GetCurrent();

String::Utf8Value utfString(isolate, str->ToString());

return *utfString;
}

Expand Down
4 changes: 3 additions & 1 deletion src/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
extern "C" {
void init (v8::Handle<v8::Object> target)
{
v8::Isolate * isolate = target->GetIsolate();

Nan::HandleScope scope;
heapdiff::HeapDiff::Initialize(target);

Nan::SetMethod(target, "upon_gc", memwatch::upon_gc);
Nan::SetMethod(target, "gc", memwatch::trigger_gc);

v8::V8::AddGCEpilogueCallback(memwatch::after_gc);
isolate->AddGCEpilogueCallback(memwatch::after_gc);
}

NODE_MODULE(memwatch, init);
Expand Down
12 changes: 8 additions & 4 deletions src/memwatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ static void AsyncMemwatchAfter(uv_work_t* request) {
// the type of event to emit
argv[1] = Nan::New("leak").ToLocalChecked();
argv[2] = getLeakReport(b->heapUsage);
g_cb->Call(3, argv);

Nan::AsyncResource async("nan:Callback:Call");
g_cb->Call(3, argv, &async);
}
} else {
s_stats.consecutive_growth = 0;
Expand Down Expand Up @@ -200,7 +202,9 @@ static void AsyncMemwatchAfter(uv_work_t* request) {
// the type of event to emit
argv[1] = Nan::New("stats").ToLocalChecked();
argv[2] = stats;
g_cb->Call(3, argv);

Nan::AsyncResource async("nan:Callback:Call");
g_cb->Call(3, argv, &async);
}
}

Expand All @@ -209,7 +213,7 @@ static void AsyncMemwatchAfter(uv_work_t* request) {

static void noop_work_func(uv_work_t *) { }

void memwatch::after_gc(GCType type, GCCallbackFlags flags)
void memwatch::after_gc(Isolate* isolate, GCType type, GCCallbackFlags flags)
{
if (heapdiff::HeapDiff::InProgress()) return;

Expand Down Expand Up @@ -246,7 +250,7 @@ NAN_METHOD(memwatch::trigger_gc) {
Nan::HandleScope scope;
int deadline_in_ms = 500;
if (info.Length() >= 1 && info[0]->IsNumber()) {
deadline_in_ms = (int)(info[0]->Int32Value());
deadline_in_ms = (int)(info[0]->Int32Value());
}
#if (NODE_MODULE_VERSION >= 0x002D)
Nan::IdleNotification(deadline_in_ms);
Expand Down
2 changes: 1 addition & 1 deletion src/memwatch.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace memwatch
{
NAN_METHOD(upon_gc);
NAN_METHOD(trigger_gc);
void after_gc(v8::GCType type, v8::GCCallbackFlags flags);
void after_gc(v8::Isolate* isolate, v8::GCType type, v8::GCCallbackFlags flags);
};

#endif
135 changes: 135 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


bindings@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"

commander@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-0.6.1.tgz#fa68a14f6a945d54dbbe50d8cdb3320e9e3b1a06"

commander@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.3.0.tgz#fd430e889832ec353b9acd1de217c11cb3eef873"

debug@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
dependencies:
ms "0.7.1"

diff@1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"

escape-string-regexp@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1"

glob@3.2.11:
version "3.2.11"
resolved "https://registry.yarnpkg.com/glob/-/glob-3.2.11.tgz#4a973f635b9190f715d10987d5c00fd2815ebe3d"
dependencies:
inherits "2"
minimatch "0.3"

growl@1.9.2:
version "1.9.2"
resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f"

inherits@2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

jade@0.26.3:
version "0.26.3"
resolved "https://registry.yarnpkg.com/jade/-/jade-0.26.3.tgz#8f10d7977d8d79f2f6ff862a81b0513ccb25686c"
dependencies:
commander "0.6.1"
mkdirp "0.3.0"

lru-cache@2:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"

minimatch@0.3:
version "0.3.0"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.3.0.tgz#275d8edaac4f1bb3326472089e7949c8394699dd"
dependencies:
lru-cache "2"
sigmund "~1.0.0"

minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"

mkdirp@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e"

mkdirp@0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
minimist "0.0.8"

mocha@^2.4.5:
version "2.5.3"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-2.5.3.tgz#161be5bdeb496771eb9b35745050b622b5aefc58"
dependencies:
commander "2.3.0"
debug "2.2.0"
diff "1.4.0"
escape-string-regexp "1.0.2"
glob "3.2.11"
growl "1.9.2"
jade "0.26.3"
mkdirp "0.5.1"
supports-color "1.2.0"
to-iso-string "0.0.2"

ms@0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"

nan@^2.3.2:
version "2.10.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"

should-equal@0.8.0:
version "0.8.0"
resolved "http://registry.npmjs.org/should-equal/-/should-equal-0.8.0.tgz#a3f05732ff45bac1b7ba412f8408856819641299"
dependencies:
should-type "0.2.0"

should-format@0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/should-format/-/should-format-0.3.2.tgz#a59831e01a2ddee149911bc7148be5c80319e1ff"
dependencies:
should-type "0.2.0"

should-type@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/should-type/-/should-type-0.2.0.tgz#6707ef95529d989dcc098fe0753ab1f9136bb7f6"

should@^8.3.1:
version "8.4.0"
resolved "https://registry.yarnpkg.com/should/-/should-8.4.0.tgz#5e60889d3e644bbdd397a30cd34fad28fcf90bc0"
dependencies:
should-equal "0.8.0"
should-format "0.3.2"
should-type "0.2.0"

sigmund@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"

supports-color@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-1.2.0.tgz#ff1ed1e61169d06b3cf2d588e188b18d8847e17e"

to-iso-string@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/to-iso-string/-/to-iso-string-0.0.2.tgz#4dc19e664dfccbe25bd8db508b00c6da158255d1"