From 3bc27f883f7d530c418247e88889b92da941caca Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Sat, 7 Feb 2015 10:34:53 +0100 Subject: [PATCH 01/33] Fixed v8::IdleNotification for nodejs 0.12 --- src/memwatch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index abbaefb..b59c066 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -244,6 +244,6 @@ NAN_METHOD(memwatch::upon_gc) { NAN_METHOD(memwatch::trigger_gc) { NanScope(); - while(!V8::IdleNotification()) {}; + while(!V8::Isolate::GetCurrent()->IdleNotification(0)) {}; NanReturnValue(NanUndefined()); } From a9e1443f8908220d32796befeeff24cc5824e752 Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Sat, 7 Feb 2015 10:49:56 +0100 Subject: [PATCH 02/33] Fixed v8::IdleNotification for nodejs 0.12 --- src/memwatch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index b59c066..6c276d5 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -244,6 +244,6 @@ NAN_METHOD(memwatch::upon_gc) { NAN_METHOD(memwatch::trigger_gc) { NanScope(); - while(!V8::Isolate::GetCurrent()->IdleNotification(0)) {}; + while(!V8::Isolate::GetCurrent()->IdleNotification(500)) {}; NanReturnValue(NanUndefined()); } From ce306b3aaefaf5eeeb420e6edcd16e791dd08159 Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Sat, 7 Feb 2015 10:50:35 +0100 Subject: [PATCH 03/33] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f77d3ca..866c640 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,6 @@ ], "dependencies": { "bindings": "^1.2.0", - "nan": "^1.2.0" + "nan": "^1.6.0" } } From 708c3cf4d5b9b33b87f5c5b61167e5f57ca8f2bf Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Sat, 7 Feb 2015 11:34:48 +0100 Subject: [PATCH 04/33] Fixed v8::IdleNotification for nodejs 0.12 Using NAN. --- src/memwatch.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index 6c276d5..13e3b6f 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -244,6 +244,6 @@ NAN_METHOD(memwatch::upon_gc) { NAN_METHOD(memwatch::trigger_gc) { NanScope(); - while(!V8::Isolate::GetCurrent()->IdleNotification(500)) {}; + while(!NanIdleNotification(500)) {}; NanReturnValue(NanUndefined()); } From c736f948086cdb5c7a0f997552fe99c3f9ed7be5 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Mon, 30 Mar 2015 13:40:12 +0200 Subject: [PATCH 05/33] Updated package.json file. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 866c640..a92309f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "memwatch", + "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.2", + "version": "0.2.3", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From c1d8026db222af930d0664fe603251f683ca725d Mon Sep 17 00:00:00 2001 From: Markus Padourek Date: Thu, 7 May 2015 10:27:51 +0100 Subject: [PATCH 06/33] Link to the right git repository --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a92309f..68f1b52 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/lloyd/node-memwatch.git" + "url": "https://github.com/marcominetti/node-memwatch.git" }, "main": "include.js", "licenses": [ @@ -17,7 +17,7 @@ } ], "bugs": { - "url": "https://github.com/lloyd/node-memwatch/issues" + "url": "https://github.com/marcominetti/node-memwatch/issues" }, "scripts": { "install": "node-gyp rebuild", From b7db604e6a58b371037c1fdbcd848aba90be2494 Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Thu, 7 May 2015 14:09:32 +0200 Subject: [PATCH 07/33] Updated package.json file. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 68f1b52..14100cb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.3", + "version": "0.2.4", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" @@ -34,6 +34,6 @@ ], "dependencies": { "bindings": "^1.2.0", - "nan": "^1.6.0" + "nan": "^1.8.0" } } From b70ee74ab8bc7636a380274335bc2186cd80740e Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Thu, 7 May 2015 15:39:11 +0200 Subject: [PATCH 08/33] Fixed nodegyp broken by path with spaces. --- .travis.yml | 1 + binding.gyp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0eca6e7..f7461c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,3 +3,4 @@ language: node_js node_js: - 0.10 - 0.11 + - 0.12 diff --git a/binding.gyp b/binding.gyp index 43f1482..a72f618 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,7 @@ { 'target_name': 'memwatch', 'include_dirs': [ - ' Date: Thu, 7 May 2015 15:40:13 +0200 Subject: [PATCH 09/33] Updated package.json file. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 14100cb..7ab39b6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.4", + "version": "0.2.5", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From a308f77f70af6cb83185151f29697dc3a2602cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Gu=C3=A9pin?= Date: Tue, 12 May 2015 10:44:36 +0200 Subject: [PATCH 10/33] Update module name in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 10b2cbf..7cc8b8a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Installation or -- `git clone git://github.com/lloyd/node-memwatch.git` +- `git clone git://github.com/marcominetti/node-memwatch.git` Description @@ -37,7 +37,7 @@ instrumentation. This module attempts to satisfy that need. To get started, import `node-memwatch` like so: ```javascript -var memwatch = require('memwatch'); +var memwatch = require('memwatch-next'); ``` ### Leak Detection From e816eca001ccb6823e6ed78766a6ec0e5edc5ac5 Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Tue, 12 May 2015 19:20:44 +0200 Subject: [PATCH 11/33] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ab39b6..4e309ba 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.5", + "version": "0.2.5-1", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From d1b66c4459037c86e97252e54dd0b52ee5d7737e Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Tue, 12 May 2015 19:25:07 +0200 Subject: [PATCH 12/33] Added iojs to Travis CI --- .travis.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7461c9..4d2dc84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,16 @@ language: node_js node_js: - - 0.10 - - 0.11 - - 0.12 + - "0.10" + - "0.11" + - "0.12" + - "iojs-v1.0" + - "iojs-v1.1" + - "iojs-v1.2" + - "iojs-v1.3" + - "iojs-v1.4" + - "iojs-v1.5" + - "iojs-v1.6" + - "iojs-v1.7" + - "iojs-v1.8" + - "iojs-v2.0" From 661f35b84c1e0d0a2b7e41c01f21d98dac2ba79e Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Tue, 12 May 2015 19:39:30 +0200 Subject: [PATCH 13/33] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e309ba..5a998f0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.5-1", + "version": "0.2.6", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From 9b619fc857692e661f4ff66986411087877c85ea Mon Sep 17 00:00:00 2001 From: Pier-Luc Gendreau Date: Thu, 25 Jun 2015 23:35:15 -0400 Subject: [PATCH 14/33] fix(bindings): support for npm@3 flatness --- binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index a72f618..4581c8e 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,7 @@ { 'target_name': 'memwatch', 'include_dirs': [ - 'node_modules/nan' + " Date: Thu, 9 Jul 2015 10:22:23 -0700 Subject: [PATCH 15/33] fix readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cc8b8a..b6d7b91 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Node.JS code. It provides: Installation ------------ -- `npm install memwatch` +- `npm install memwatch-next` or From f88aa00ba19f9acb81c4647d22255cdbceb98f7f Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Sat, 11 Jul 2015 16:33:24 +0200 Subject: [PATCH 16/33] Bump version 0.2.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5a998f0..70fa9b2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.6", + "version": "0.2.7", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From 1dcfda88467995c6ff7da0056606951991b13f3a Mon Sep 17 00:00:00 2001 From: Thomas Shafer Date: Wed, 19 Aug 2015 11:05:07 -0700 Subject: [PATCH 17/33] include iojs-v3 in travis ci build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4d2dc84..f7a0fc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,3 +14,4 @@ node_js: - "iojs-v1.7" - "iojs-v1.8" - "iojs-v2.0" + - "iojs-v3.0" From 165dceccdf906a9beed1a06b93fbc13c589ea532 Mon Sep 17 00:00:00 2001 From: Marco Minetti Date: Fri, 21 Aug 2015 00:09:07 +0200 Subject: [PATCH 18/33] Upgraded NaN to 2.x. Supporting now iojs 3.x branch. --- package.json | 2 +- src/heapdiff.cc | 112 ++++++++++++++++++++++++++---------------------- src/heapdiff.hh | 2 +- src/init.cc | 6 +-- src/memwatch.cc | 66 ++++++++++++++-------------- 5 files changed, 98 insertions(+), 90 deletions(-) diff --git a/package.json b/package.json index 70fa9b2..72da894 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,6 @@ ], "dependencies": { "bindings": "^1.2.0", - "nan": "^1.8.0" + "nan": "^2.0.0" } } diff --git a/src/heapdiff.cc b/src/heapdiff.cc index da5a0ae..c83a3ef 100644 --- a/src/heapdiff.cc +++ b/src/heapdiff.cc @@ -45,15 +45,15 @@ heapdiff::HeapDiff::~HeapDiff() void heapdiff::HeapDiff::Initialize ( v8::Handle target ) { - NanScope(); + Nan::HandleScope scope; - v8::Local t = NanNew(New); + v8::Local t = Nan::New(New); t->InstanceTemplate()->SetInternalFieldCount(1); - t->SetClassName(NanNew("HeapDiff")); + t->SetClassName(Nan::New("HeapDiff").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(t, "end", End); + Nan::SetPrototypeMethod(t, "end", End); - target->Set(NanNew( "HeapDiff"), t->GetFunction()); + target->Set(Nan::New("HeapDiff").ToLocalChecked(), t->GetFunction()); } NAN_METHOD(heapdiff::HeapDiff::New) @@ -61,29 +61,33 @@ NAN_METHOD(heapdiff::HeapDiff::New) // Don't blow up when the caller says "new require('memwatch').HeapDiff()" // issue #30 // stolen from: https://github.com/kkaefer/node-cpp-modules/commit/bd9432026affafd8450ecfd9b49b7dc647b6d348 - if (!args.IsConstructCall()) { - return NanThrowTypeError("Use the new operator to create instances of this object."); + if (!info.IsConstructCall()) { + return Nan::ThrowTypeError("Use the new operator to create instances of this object."); } - NanScope(); + Nan::HandleScope scope; // allocate the underlying c++ class and wrap it up in the this pointer HeapDiff * self = new HeapDiff(); - self->Wrap(args.This()); + self->Wrap(info.This()); // take a snapshot and save a pointer to it s_inProgress = true; s_startTime = time(NULL); +#if (NODE_MODULE_VERSION >= 0x002D) + self->before = v8::Isolate::GetCurrent()->GetHeapProfiler()->TakeHeapSnapshot(NULL); +#else #if (NODE_MODULE_VERSION > 0x000B) - self->before = v8::Isolate::GetCurrent()->GetHeapProfiler()->TakeHeapSnapshot(NanNew(""), NULL); + self->before = v8::Isolate::GetCurrent()->GetHeapProfiler()->TakeHeapSnapshot(Nan::New("").ToLocalChecked(), NULL); #else - self->before = v8::HeapProfiler::TakeSnapshot(NanNew(""), HeapSnapshot::kFull, NULL); + self->before = v8::HeapProfiler::TakeSnapshot(Nan::New("").ToLocalChecked(), HeapSnapshot::kFull, NULL); +#endif #endif s_inProgress = false; - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); } static string handleToStr(const Handle & str) @@ -95,7 +99,7 @@ static string handleToStr(const Handle & str) static void buildIDSet(set * seen, const HeapGraphNode* cur, int & s) { - NanScope(); + Nan::HandleScope scope; // cycle detection if (seen->find(cur->GetId()) != seen->end()) { @@ -109,7 +113,7 @@ buildIDSet(set * seen, const HeapGraphNode* cur, int & s) } // update memory usage as we go - s += cur->GetSelfSize(); + s += cur->GetShallowSize(); seen->insert(cur->GetId()); @@ -200,7 +204,7 @@ static void manageChange(changeset & changes, const HeapGraphNode * node, bool a changeset::iterator i = changes.find(type); - i->second.size += node->GetSelfSize() * (added ? 1 : -1); + i->second.size += node->GetShallowSize() * (added ? 1 : -1); if (added) i->second.added++; else i->second.released++; @@ -211,66 +215,66 @@ static void manageChange(changeset & changes, const HeapGraphNode * node, bool a static Handle changesetToObject(changeset & changes) { - NanEscapableScope(); - Local a = NanNew(); + Nan::EscapableHandleScope scope; + Local a = Nan::New(); for (changeset::iterator i = changes.begin(); i != changes.end(); i++) { - Local d = NanNew(); - d->Set(NanNew("what"), NanNew(i->first.c_str())); - d->Set(NanNew("size_bytes"), NanNew(i->second.size)); - d->Set(NanNew("size"), NanNew(mw_util::niceSize(i->second.size).c_str())); - d->Set(NanNew("+"), NanNew(i->second.added)); - d->Set(NanNew("-"), NanNew(i->second.released)); + Local d = Nan::New(); + d->Set(Nan::New("what").ToLocalChecked(), Nan::New(i->first.c_str()).ToLocalChecked()); + d->Set(Nan::New("size_bytes").ToLocalChecked(), Nan::New(i->second.size)); + d->Set(Nan::New("size").ToLocalChecked(), Nan::New(mw_util::niceSize(i->second.size).c_str()).ToLocalChecked()); + d->Set(Nan::New("+").ToLocalChecked(), Nan::New(i->second.added)); + d->Set(Nan::New("-").ToLocalChecked(), Nan::New(i->second.released)); a->Set(a->Length(), d); } - return NanEscapeScope(a); + return scope.Escape(a); } static v8::Handle compare(const v8::HeapSnapshot * before, const v8::HeapSnapshot * after) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; int s, diffBytes; - Local o = NanNew(); + Local o = Nan::New(); // first let's append summary information - Local b = NanNew(); - b->Set(NanNew("nodes"), NanNew(before->GetNodesCount())); - //b->Set(NanNew("time"), s_startTime); - o->Set(NanNew("before"), b); + Local b = Nan::New(); + b->Set(Nan::New("nodes").ToLocalChecked(), Nan::New(before->GetNodesCount())); + //b->Set(Nan::New("time"), s_startTime); + o->Set(Nan::New("before").ToLocalChecked(), b); - Local a = NanNew(); - a->Set(NanNew("nodes"), NanNew(after->GetNodesCount())); - //a->Set(NanNew("time"), time(NULL)); - o->Set(NanNew("after"), a); + Local a = Nan::New(); + a->Set(Nan::New("nodes").ToLocalChecked(), Nan::New(after->GetNodesCount())); + //a->Set(Nan::New("time"), time(NULL)); + o->Set(Nan::New("after").ToLocalChecked(), a); // now let's get allocations by name set beforeIDs, afterIDs; s = 0; buildIDSet(&beforeIDs, before->GetRoot(), s); - b->Set(NanNew("size_bytes"), NanNew(s)); - b->Set(NanNew("size"), NanNew(mw_util::niceSize(s).c_str())); + b->Set(Nan::New("size_bytes").ToLocalChecked(), Nan::New(s)); + b->Set(Nan::New("size").ToLocalChecked(), Nan::New(mw_util::niceSize(s).c_str()).ToLocalChecked()); diffBytes = s; s = 0; buildIDSet(&afterIDs, after->GetRoot(), s); - a->Set(NanNew("size_bytes"), NanNew(s)); - a->Set(NanNew("size"), NanNew(mw_util::niceSize(s).c_str())); + a->Set(Nan::New("size_bytes").ToLocalChecked(), Nan::New(s)); + a->Set(Nan::New("size").ToLocalChecked(), Nan::New(mw_util::niceSize(s).c_str()).ToLocalChecked()); diffBytes = s - diffBytes; - Local c = NanNew(); - c->Set(NanNew("size_bytes"), NanNew(diffBytes)); - c->Set(NanNew("size"), NanNew(mw_util::niceSize(diffBytes).c_str())); - o->Set(NanNew("change"), c); + Local c = Nan::New(); + c->Set(Nan::New("size_bytes").ToLocalChecked(), Nan::New(diffBytes)); + c->Set(Nan::New("size").ToLocalChecked(), Nan::New(mw_util::niceSize(diffBytes).c_str()).ToLocalChecked()); + o->Set(Nan::New("change").ToLocalChecked(), c); // before - after will reveal nodes released (memory freed) vector changedIDs; setDiff(beforeIDs, afterIDs, changedIDs); - c->Set(NanNew("freed_nodes"), NanNew(changedIDs.size())); + c->Set(Nan::New("freed_nodes").ToLocalChecked(), Nan::New(changedIDs.size())); // here's where we'll collect all the summary information changeset changes; @@ -286,38 +290,42 @@ compare(const v8::HeapSnapshot * before, const v8::HeapSnapshot * after) // after - before will reveal nodes added (memory allocated) setDiff(afterIDs, beforeIDs, changedIDs); - c->Set(NanNew("allocated_nodes"), NanNew(changedIDs.size())); + c->Set(Nan::New("allocated_nodes").ToLocalChecked(), Nan::New(changedIDs.size())); for (unsigned long i = 0; i < changedIDs.size(); i++) { const HeapGraphNode * n = after->GetNodeById(changedIDs[i]); manageChange(changes, n, true); } - c->Set(NanNew("details"), changesetToObject(changes)); + c->Set(Nan::New("details").ToLocalChecked(), changesetToObject(changes)); - return NanEscapeScope(o); + return scope.Escape(o); } NAN_METHOD(heapdiff::HeapDiff::End) { // take another snapshot and compare them - NanScope(); + Nan::HandleScope scope; - HeapDiff *t = Unwrap( args.This() ); + HeapDiff *t = Unwrap( info.This() ); // How shall we deal with double .end()ing? The only reasonable // approach seems to be an exception, cause nothing else makes // sense. if (t->ended) { - return NanThrowError("attempt to end() a HeapDiff that was already ended"); + return Nan::ThrowError("attempt to end() a HeapDiff that was already ended"); } t->ended = true; s_inProgress = true; +#if (NODE_MODULE_VERSION >= 0x002D) + t->after = v8::Isolate::GetCurrent()->GetHeapProfiler()->TakeHeapSnapshot(NULL); +#else #if (NODE_MODULE_VERSION > 0x000B) - t->after = v8::Isolate::GetCurrent()->GetHeapProfiler()->TakeHeapSnapshot(NanNew(""), NULL); + t->after = v8::Isolate::GetCurrent()->GetHeapProfiler()->TakeHeapSnapshot(Nan::New("").ToLocalChecked(), NULL); #else - t->after = v8::HeapProfiler::TakeSnapshot(NanNew(""), HeapSnapshot::kFull, NULL); + t->after = v8::HeapProfiler::TakeSnapshot(Nan::New("").ToLocalChecked(), HeapSnapshot::kFull, NULL); +#endif #endif s_inProgress = false; @@ -329,5 +337,5 @@ NAN_METHOD(heapdiff::HeapDiff::End) ((HeapSnapshot *) t->after)->Delete(); t->after = NULL; - NanReturnValue(comparison); + info.GetReturnValue().Set(comparison); } diff --git a/src/heapdiff.hh b/src/heapdiff.hh index 592858c..917d7a6 100644 --- a/src/heapdiff.hh +++ b/src/heapdiff.hh @@ -12,7 +12,7 @@ namespace heapdiff { - class HeapDiff : public node::ObjectWrap + class HeapDiff : public Nan::ObjectWrap { public: static void Initialize ( v8::Handle target ); diff --git a/src/init.cc b/src/init.cc index 00df1a2..36feae9 100644 --- a/src/init.cc +++ b/src/init.cc @@ -11,11 +11,11 @@ extern "C" { void init (v8::Handle target) { - NanScope(); + Nan::HandleScope scope; heapdiff::HeapDiff::Initialize(target); - NODE_SET_METHOD(target, "upon_gc", memwatch::upon_gc); - NODE_SET_METHOD(target, "gc", memwatch::trigger_gc); + Nan::SetMethod(target, "upon_gc", memwatch::upon_gc); + Nan::SetMethod(target, "gc", memwatch::trigger_gc); v8::V8::AddGCEpilogueCallback(memwatch::after_gc); } diff --git a/src/memwatch.cc b/src/memwatch.cc index 13e3b6f..c73a14b 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -21,7 +21,7 @@ using namespace v8; using namespace node; Handle g_context; -NanCallback *g_cb; +Nan::Callback *g_cb; struct Baton { uv_work_t req; @@ -67,29 +67,29 @@ static struct static Handle getLeakReport(size_t heapUsage) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; size_t growth = heapUsage - s_stats.leak_base_start; int now = time(NULL); int delta = now - s_stats.leak_time_start; - Local leakReport = NanNew(); - //leakReport->Set(NanNew("start"), NODE_UNIXTIME_V8(s_stats.leak_time_start)); - //leakReport->Set(NanNew("end"), NODE_UNIXTIME_V8(now)); - leakReport->Set(NanNew("growth"), NanNew(growth)); + Local leakReport = Nan::New(); + //leakReport->Set(Nan::New("start").ToLocalChecked(), NODE_UNIXTIME_V8(s_stats.leak_time_start)); + //leakReport->Set(Nan::New("end").ToLocalChecked(), NODE_UNIXTIME_V8(now)); + leakReport->Set(Nan::New("growth").ToLocalChecked(), Nan::New(growth)); std::stringstream ss; ss << "heap growth over 5 consecutive GCs (" << mw_util::niceDelta(delta) << ") - " << mw_util::niceSize(growth / ((double) delta / (60.0 * 60.0))) << "/hr"; - leakReport->Set(NanNew("reason"), NanNew(ss.str().c_str())); + leakReport->Set(Nan::New("reason").ToLocalChecked(), Nan::New(ss.str().c_str()).ToLocalChecked()); - return NanEscapeScope(leakReport); + return scope.Escape(leakReport); } static void AsyncMemwatchAfter(uv_work_t* request) { - NanScope(); + Nan::HandleScope scope; Baton * b = (Baton *) request->data; @@ -121,9 +121,9 @@ static void AsyncMemwatchAfter(uv_work_t* request) { // emit a leak report! Handle argv[3]; - argv[0] = NanNew(false); + argv[0] = Nan::New(false); // the type of event to emit - argv[1] = NanNew("leak"); + argv[1] = Nan::New("leak").ToLocalChecked(); argv[2] = getLeakReport(b->heapUsage); g_cb->Call(3, argv); } @@ -175,7 +175,7 @@ static void AsyncMemwatchAfter(uv_work_t* request) { Handle argv[3]; // magic argument to indicate to the callback all we want to know is whether there are // listeners (here we don't) - argv[0] = NanNew(true); + argv[0] = Nan::New(true); //Handle haveListeners = g_cb->call(1, argv); @@ -187,18 +187,18 @@ static void AsyncMemwatchAfter(uv_work_t* request) { } // ok, there are listeners, we actually must serialize and emit this stats event - Local stats = NanNew(); - stats->Set(NanNew("num_full_gc"), NanNew(s_stats.gc_full)); - stats->Set(NanNew("num_inc_gc"), NanNew(s_stats.gc_inc)); - stats->Set(NanNew("heap_compactions"), NanNew(s_stats.gc_compact)); - stats->Set(NanNew("usage_trend"), NanNew(ut)); - stats->Set(NanNew("estimated_base"), NanNew(s_stats.base_recent)); - stats->Set(NanNew("current_base"), NanNew(s_stats.last_base)); - stats->Set(NanNew("min"), NanNew(s_stats.base_min)); - stats->Set(NanNew("max"), NanNew(s_stats.base_max)); - argv[0] = NanNew(false); + Local stats = Nan::New(); + stats->Set(Nan::New("num_full_gc").ToLocalChecked(), Nan::New(s_stats.gc_full)); + stats->Set(Nan::New("num_inc_gc").ToLocalChecked(), Nan::New(s_stats.gc_inc)); + stats->Set(Nan::New("heap_compactions").ToLocalChecked(), Nan::New(s_stats.gc_compact)); + stats->Set(Nan::New("usage_trend").ToLocalChecked(), Nan::New(ut)); + stats->Set(Nan::New("estimated_base").ToLocalChecked(), Nan::New(s_stats.base_recent)); + stats->Set(Nan::New("current_base").ToLocalChecked(), Nan::New(s_stats.last_base)); + stats->Set(Nan::New("min").ToLocalChecked(), Nan::New(s_stats.base_min)); + stats->Set(Nan::New("max").ToLocalChecked(), Nan::New(s_stats.base_max)); + argv[0] = Nan::New(false); // the type of event to emit - argv[1] = NanNew("stats"); + argv[1] = Nan::New("stats").ToLocalChecked(); argv[2] = stats; g_cb->Call(3, argv); } @@ -213,12 +213,12 @@ void memwatch::after_gc(GCType type, GCCallbackFlags flags) { if (heapdiff::HeapDiff::InProgress()) return; - NanScope(); + Nan::HandleScope scope; Baton * baton = new Baton; v8::HeapStatistics hs; - NanGetHeapStatistics(&hs); + Nan::GetHeapStatistics(&hs); baton->heapUsage = hs.used_heap_size(); baton->type = type; @@ -235,15 +235,15 @@ void memwatch::after_gc(GCType type, GCCallbackFlags flags) } NAN_METHOD(memwatch::upon_gc) { - NanScope(); - if (args.Length() >= 1 && args[0]->IsFunction()) { - g_cb = new NanCallback(args[0].As()); + Nan::HandleScope scope; + if (info.Length() >= 1 && info[0]->IsFunction()) { + g_cb = new Nan::Callback(info[0].As()); } - NanReturnValue(NanUndefined()); + info.GetReturnValue().Set(Nan::Undefined()); } NAN_METHOD(memwatch::trigger_gc) { - NanScope(); - while(!NanIdleNotification(500)) {}; - NanReturnValue(NanUndefined()); -} + Nan::HandleScope scope; + while(!Nan::IdleNotification(500)) {}; + info.GetReturnValue().Set(Nan::Undefined()); +} \ No newline at end of file From 64dd89e51f9a5e1c842fcdd886831986cf2a06a8 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Fri, 21 Aug 2015 10:41:48 +0200 Subject: [PATCH 19/33] Fixed support for iojs/nodejs version < 3.x with Nan 2.x. --- src/heapdiff.cc | 13 ++++++++++--- src/memwatch.cc | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/heapdiff.cc b/src/heapdiff.cc index c83a3ef..aeb2621 100644 --- a/src/heapdiff.cc +++ b/src/heapdiff.cc @@ -113,8 +113,11 @@ buildIDSet(set * seen, const HeapGraphNode* cur, int & s) } // update memory usage as we go +#if (NODE_MODULE_VERSION >= 0x002D) s += cur->GetShallowSize(); - +#else + s += cur->GetSelfSize(); +#endif seen->insert(cur->GetId()); for (int i=0; i < cur->GetChildrenCount(); i++) { @@ -204,7 +207,11 @@ static void manageChange(changeset & changes, const HeapGraphNode * node, bool a changeset::iterator i = changes.find(type); +#if (NODE_MODULE_VERSION >= 0x002D) i->second.size += node->GetShallowSize() * (added ? 1 : -1); +#else + i->second.size += node->GetSelfSize() * (added ? 1 : -1); +#endif if (added) i->second.added++; else i->second.released++; @@ -232,7 +239,7 @@ static Handle changesetToObject(changeset & changes) } -static v8::Handle +static v8::Local compare(const v8::HeapSnapshot * before, const v8::HeapSnapshot * after) { Nan::EscapableHandleScope scope; @@ -329,7 +336,7 @@ NAN_METHOD(heapdiff::HeapDiff::End) #endif s_inProgress = false; - v8::Handle comparison = compare(t->before, t->after); + v8::Local comparison = compare(t->before, t->after); // free early, free often. I mean, after all, this process we're in is // probably having memory problems. We want to help her. ((HeapSnapshot *) t->before)->Delete(); diff --git a/src/memwatch.cc b/src/memwatch.cc index c73a14b..0654464 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -65,7 +65,7 @@ static struct unsigned int consecutive_growth; } s_stats; -static Handle getLeakReport(size_t heapUsage) +static Local getLeakReport(size_t heapUsage) { Nan::EscapableHandleScope scope; @@ -120,7 +120,7 @@ static void AsyncMemwatchAfter(uv_work_t* request) { s_stats.consecutive_growth = 0; // emit a leak report! - Handle argv[3]; + Local argv[3]; argv[0] = Nan::New(false); // the type of event to emit argv[1] = Nan::New("leak").ToLocalChecked(); @@ -172,7 +172,7 @@ static void AsyncMemwatchAfter(uv_work_t* request) { // if there are any listeners, it's time to emit! if (!g_cb->IsEmpty()) { - Handle argv[3]; + Local argv[3]; // magic argument to indicate to the callback all we want to know is whether there are // listeners (here we don't) argv[0] = Nan::New(true); @@ -246,4 +246,4 @@ NAN_METHOD(memwatch::trigger_gc) { Nan::HandleScope scope; while(!Nan::IdleNotification(500)) {}; info.GetReturnValue().Set(Nan::Undefined()); -} \ No newline at end of file +} From 1dbb83de08e53cbea8c1909918539144fa28e6f0 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Fri, 21 Aug 2015 10:42:50 +0200 Subject: [PATCH 20/33] Bump version 0.2.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 72da894..bb40d65 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.7", + "version": "0.2.8", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From cb5fe9f0d91f0f5e125a4527b0a74bb0e959cc6a Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Fri, 21 Aug 2015 11:40:56 +0200 Subject: [PATCH 21/33] Reworked gc() implementation. Now uses both IdleNotification and LowMemoryNotification to ensure 'stats' event is triggered. The gc function now accepts custom deadline in milliseconds for IdleNotification. In iojs/nodejs version 3.x the full collection could not indeed occur. --- src/memwatch.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index 0654464..6ebed41 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -244,6 +244,16 @@ NAN_METHOD(memwatch::upon_gc) { NAN_METHOD(memwatch::trigger_gc) { Nan::HandleScope scope; - while(!Nan::IdleNotification(500)) {}; + int deadline_in_ms = 500; + if (info.Length() >= 1 && info[0]->IsNumber()) { + deadline_in_ms = (int)(info[0]->Int32Value()); + } +#if (NODE_MODULE_VERSION >= 0x002D) + Nan::IdleNotification(deadline_in_ms); + Nan::LowMemoryNotification(); +#else + while(!Nan::IdleNotification(deadline_in_ms)) {}; + Nan::LowMemoryNotification(); +#endif info.GetReturnValue().Set(Nan::Undefined()); } From 3c624fdd55ff680b7edaa64c75f50256477da512 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Fri, 21 Aug 2015 11:44:14 +0200 Subject: [PATCH 22/33] Bump version 0.2.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb40d65..ff988c3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.8", + "version": "0.2.9", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From b4d6bb28b35da3c7c3b6a739071fd488f85204a0 Mon Sep 17 00:00:00 2001 From: Todd Bluhm Date: Tue, 3 Nov 2015 18:34:23 -0500 Subject: [PATCH 23/33] Make compatible with Alpine linux by using cmath instead of math.h --- src/platformcompat.hh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/platformcompat.hh b/src/platformcompat.hh index fb41fd5..ad49e20 100644 --- a/src/platformcompat.hh +++ b/src/platformcompat.hh @@ -1,8 +1,6 @@ #ifndef __PLATFORMCOMPAT_H #define __PLATFORMCOMPAT_H -#include // round() - #if defined(_MSC_VER) #include //isinf, isnan #include //min @@ -11,10 +9,11 @@ #define FMIN __min #define ROUND(x) floor(x + 0.5) #else -#define ISINF isinf -#define ISNAN isnan +#include // round(), isinf, isnan +#define ISINF std::isinf +#define ISNAN std::isnan #define FMIN fmin #define ROUND round #endif -#endif \ No newline at end of file +#endif From d586015524f56b70571152ae1c1fc6b41401e2f8 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Mon, 9 Nov 2015 19:43:48 +0100 Subject: [PATCH 24/33] Bump version 0.2.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff988c3..1896ca3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.9", + "version": "0.2.10", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" From 08617bdf689344436595ec45f6d0c55327b70cb3 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 22 Dec 2015 08:21:50 -0800 Subject: [PATCH 25/33] Update README.md Minor, but JSON for heapdiff was missing one bracket. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b6d7b91..d58911e 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ The contents of `diff` will look something like: } ] } +} ``` The diff shows that during the sample period, the total number of From fc1b88d7baebb73d38a92234b2ed497fb7199c77 Mon Sep 17 00:00:00 2001 From: Pier-Luc Gendreau Date: Wed, 27 Apr 2016 19:12:37 -0400 Subject: [PATCH 26/33] chore(ci): add Node 4, 5 & 6 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index f7a0fc8..0e101c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,3 +15,6 @@ node_js: - "iojs-v1.8" - "iojs-v2.0" - "iojs-v3.0" + - "4" + - "5" + - "6" From 436ce0d0df8e744b2e669f0c09da979d1cc678d5 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Sat, 30 Apr 2016 09:02:09 +0200 Subject: [PATCH 27/33] Updated dependencies, travis targets and bump version 0.3.0. --- .travis.yml | 12 ------------ package.json | 10 +++++----- tests.js | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0e101c0..6fca480 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,19 +2,7 @@ language: node_js node_js: - "0.10" - - "0.11" - "0.12" - - "iojs-v1.0" - - "iojs-v1.1" - - "iojs-v1.2" - - "iojs-v1.3" - - "iojs-v1.4" - - "iojs-v1.5" - - "iojs-v1.6" - - "iojs-v1.7" - - "iojs-v1.8" - - "iojs-v2.0" - - "iojs-v3.0" - "4" - "5" - "6" diff --git a/package.json b/package.json index 1896ca3..1f9d0d7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "memwatch-next", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "0.2.10", + "version": "0.3.0", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 0.8.0" @@ -24,8 +24,8 @@ "test": "mocha tests --reporter spec" }, "devDependencies": { - "mocha": "1.2.2", - "should": "0.6.3" + "mocha": "^2.4.5", + "should": "^8.3.1" }, "contributors": [ "Jed Parsons (@jedp)", @@ -33,7 +33,7 @@ "Justin Matthews (@jmatthewsr-ms)" ], "dependencies": { - "bindings": "^1.2.0", - "nan": "^2.0.0" + "bindings": "^1.2.1", + "nan": "^2.3.2" } } diff --git a/tests.js b/tests.js index 498d752..2b8a93f 100644 --- a/tests.js +++ b/tests.js @@ -15,7 +15,7 @@ describe('the library', function() { describe('calling .gc()', function() { it('should cause a stats() event to be emitted', function(done) { memwatch.once('stats', function(s) { - s.should.be.a('object'); + s.should.be.object; done(); }); memwatch.gc(); From f05f77def4c08dd3cfcdfefd1a0cb63e3712b1a8 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Sat, 30 Apr 2016 09:07:30 +0200 Subject: [PATCH 28/33] Fix travis ci build for nodejs 4+. --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6fca480..9e94329 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,10 @@ language: node_js - +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - gcc-4.8 node_js: - "0.10" - "0.12" From 23b2da5b986b9f6db776e4a236437500a6ddbf68 Mon Sep 17 00:00:00 2001 From: "marco.minetti" Date: Sat, 30 Apr 2016 09:13:07 +0200 Subject: [PATCH 29/33] Fix travis ci build for nodejs 4+. --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9e94329..4f3d5cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ language: node_js +env: + - CXX=g++-4.8 addons: apt: sources: - - ubuntu-toolchain-r-test + - ubuntu-toolchain-r-test packages: - - gcc-4.8 + - g++-4.8 node_js: - "0.10" - "0.12" From 35aad779a2d0b26ead21c971cc66edc731b3c83a Mon Sep 17 00:00:00 2001 From: Varatep Buranintu Date: Fri, 23 Sep 2016 00:21:30 -0700 Subject: [PATCH 30/33] update license page license page is previously incorrect --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d58911e..a166de0 100644 --- a/README.md +++ b/README.md @@ -157,4 +157,4 @@ Please see the Issues to share suggestions and contribute! License ------- -http://wtfpl.org +http://wtfpl.net From 35a9b6188cffb61fc912d332f1c6a5c1d4f994e4 Mon Sep 17 00:00:00 2001 From: Espen Klem Date: Fri, 27 Jan 2017 11:59:35 +0100 Subject: [PATCH 31/33] aver --> after ? Just a little typo? --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d58911e..4597804 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ The `info` object will look something like: ### Heap Usage The best way to evaluate your memory footprint is to look at heap -usage right aver V8 performs garbage collection. `memwatch` does +usage right after V8 performs garbage collection. `memwatch` does exactly this - it checks heap usage only after GC to give you a stable baseline of your actual memory usage. From b638c908affb6803fea368918e477fa5778fda4d Mon Sep 17 00:00:00 2001 From: Marco Minetti <4608324+marcominetti@users.noreply.github.com> Date: Mon, 22 Mar 2021 17:34:27 +0100 Subject: [PATCH 32/33] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 65ac102..95b61ef 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# DEPRECATED + `node-memwatch`: Leak Detection and Heap Diffing for Node.JS ============================================================ From de2ee6f3de32df10316b2c2b3c4a98ef1a59e8c7 Mon Sep 17 00:00:00 2001 From: Joris W Date: Thu, 29 Dec 2022 13:35:32 +0100 Subject: [PATCH 33/33] Update README.md Refer diretctly to @airbnb/node-memwatch --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95b61ef..a20f9ad 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# DEPRECATED +# This project is DEPRECATED + +See https://github.com/airbnb/node-memwatch for an actively maintained fork. + `node-memwatch`: Leak Detection and Heap Diffing for Node.JS ============================================================