From 7fff7c8012af5c3c2a1b909185b2b1c4d2eff440 Mon Sep 17 00:00:00 2001 From: curvedriver <54622444+curvedriver@users.noreply.github.com> Date: Mon, 9 Nov 2020 17:24:40 +0100 Subject: [PATCH 1/3] Fix windows compatibility by using uv_hrtime() --- src/memwatch.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index 26b9c64..a922f55 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -16,7 +16,6 @@ #include // for pow #include // for time -#include using namespace v8; using namespace node; @@ -176,10 +175,7 @@ NAN_GC_CALLBACK(memwatch::after_gc) { Nan::GetHeapStatistics(&hs); - timeval tv; - gettimeofday(&tv, NULL); - - baton->gc_ts = (tv.tv_sec * 1000000) + tv.tv_usec; + baton->gc_ts = uv_hrtime() / 1000; baton->total_heap_size = hs.total_heap_size(); baton->total_heap_size_executable = hs.total_heap_size_executable(); From 3f176e6aac12a4f5c92e9570f38e941eed88d739 Mon Sep 17 00:00:00 2001 From: curvedriver <54622444+curvedriver@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:00:24 +0100 Subject: [PATCH 2/3] Assert gc_ts stats() event --- tests.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests.js b/tests.js index 2b8a93f..3c9e07d 100644 --- a/tests.js +++ b/tests.js @@ -2,6 +2,10 @@ const should = require('should'), memwatch = require('./'); +function hrtimeInMicroseconds() { + return process.hrtime.bigint() / 1000n; +} + describe('the library', function() { it('should export a couple functions', function(done) { should.exist(memwatch.gc); @@ -14,10 +18,23 @@ describe('the library', function() { }); describe('calling .gc()', function() { it('should cause a stats() event to be emitted', function(done) { + let timeBeforeGc; + memwatch.once('stats', function(s) { + const timeAfterEvent = hrtimeInMicroseconds(); + s.should.be.object; + + (typeof timeBeforeGc).should.equal("bigint"); + timeAfterEvent.should.be.greaterThan(timeBeforeGc); + + s.gc_ts.should.be.a.Number(); + s.gc_ts.should.be.within(timeBeforeGc, timeAfterEvent); + done(); }); + + timeBeforeGc = hrtimeInMicroseconds(); memwatch.gc(); }); }); From 4a0856edfcb82cc776e28eea7320f3fe4f5c128b Mon Sep 17 00:00:00 2001 From: curvedriver <54622444+curvedriver@users.noreply.github.com> Date: Thu, 17 Feb 2022 19:05:12 +0100 Subject: [PATCH 3/3] Update Changelog --- ChangeLog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index e8ee9de..e86df19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Unreleased + * Fix windows compatibility of memwatch.cc + v2.0.0 * BREAKING: Drop support for Node <= 9. * Add support for Node >= 10.