From c982a061634340730ff91a27c1e6cf2352001135 Mon Sep 17 00:00:00 2001 From: Sudhir Pradhan Date: Mon, 3 Jan 2022 02:15:30 +0530 Subject: [PATCH 1/4] remove sys/time.h, add gettimeofday via crono, it works on windows, imight not work on other os's --- src/memwatch.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index 26b9c64..8de8259 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -16,13 +16,29 @@ #include // for pow #include // for time -#include +// #include using namespace v8; using namespace node; Local g_context; + +#if defined(_WIN32) +#include + +int gettimeofday(struct timeval* tp, struct timezone* tzp) { + namespace sc = std::chrono; + sc::system_clock::duration d = sc::system_clock::now().time_since_epoch(); + sc::seconds s = sc::duration_cast(d); + tp->tv_sec = s.count(); + tp->tv_usec = sc::duration_cast(d - s).count(); + + return 0; +} + +#endif // _WIN32 + class UponGCCallback : public Nan::AsyncResource { public: UponGCCallback(v8::Local callback_) : Nan::AsyncResource("memwatch:upon_gc") { From 961ea2a356403107041451e175fb35146d04186a Mon Sep 17 00:00:00 2001 From: Sudhir Pradhan Date: Mon, 3 Jan 2022 03:37:25 +0530 Subject: [PATCH 2/4] runs on mac os, checking... --- src/memwatch.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index 8de8259..20bd616 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -15,8 +15,9 @@ #include #include // for pow -#include // for time +// #include // for time // #include +#include using namespace v8; using namespace node; @@ -24,8 +25,8 @@ using namespace node; Local g_context; -#if defined(_WIN32) -#include +// #if defined(_WIN32) + int gettimeofday(struct timeval* tp, struct timezone* tzp) { namespace sc = std::chrono; @@ -37,7 +38,7 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp) { return 0; } -#endif // _WIN32 +// #endif // _WIN32 class UponGCCallback : public Nan::AsyncResource { public: From 12372debfffd5a8742fa674c9f7c1df139a10afa Mon Sep 17 00:00:00 2001 From: Sudhir Pradhan Date: Mon, 3 Jan 2022 04:21:42 +0530 Subject: [PATCH 3/4] remove deprecated header sys/time.h, instead use chrono for gettimeofday It works on Windows 11, mac, ubuntu --- src/memwatch.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/memwatch.cc b/src/memwatch.cc index 20bd616..c5e5507 100644 --- a/src/memwatch.cc +++ b/src/memwatch.cc @@ -15,19 +15,16 @@ #include #include // for pow -// #include // for time +#include // for time // #include -#include +#include // use chrono instead of sys/time.h using namespace v8; using namespace node; Local g_context; - -// #if defined(_WIN32) - - +// define gettimeofday which uses chrono, earlier it was defined in header sys/time.h which is now deprecated int gettimeofday(struct timeval* tp, struct timezone* tzp) { namespace sc = std::chrono; sc::system_clock::duration d = sc::system_clock::now().time_since_epoch(); @@ -38,7 +35,6 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp) { return 0; } -// #endif // _WIN32 class UponGCCallback : public Nan::AsyncResource { public: From 05a6b17709447a569cbe7ff5c1ba8a3db56dc258 Mon Sep 17 00:00:00 2001 From: Sudhir Pradhan Date: Mon, 3 Jan 2022 05:15:49 +0530 Subject: [PATCH 4/4] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1d865fb..064de58 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@airbnb/node-memwatch", "description": "Keep an eye on your memory usage, and discover and isolate leaks.", - "version": "2.0.0", + "version": "2.0.1", "author": "Lloyd Hilaiel (http://lloyd.io)", "engines": { "node": ">= 10.0"