node-oom-heapdump 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
1
|
+
27-10-2023 Paul Rütter
|
2
|
+
- 3.2.0
|
3
|
+
- https://github.com/blueconic/node-oom-heapdump/issues/31: Node20 support
|
4
|
+
- Change native code to use different method signature for Node20 and above, remain compatible for Node18 and below.
|
5
|
+
|
6
|
+
26-10-2023 Paul Rütter
|
2
7
|
- 3.1.0
|
3
8
|
- https://github.com/blueconic/node-oom-heapdump/issues/28: only build prebuilt binaries for > 16.x, as Github Actions no longer supports older versions.
|
4
9
|
|
@@ -48,7 +48,7 @@
|
|
48
48
|
</PropertyGroup>
|
49
49
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
50
50
|
<ClCompile>
|
51
|
-
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\
|
51
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
52
52
|
<AdditionalOptions>/Zc:__cplusplus -std:c++17 %(AdditionalOptions)</AdditionalOptions>
|
53
53
|
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
54
54
|
<BufferSecurityCheck>true</BufferSecurityCheck>
|
@@ -72,7 +72,7 @@
|
|
72
72
|
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
73
73
|
</Lib>
|
74
74
|
<Link>
|
75
|
-
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;"C:\\Users\\paul.BLUECONIC\\AppData\\Local\\node-gyp\\Cache\\
|
75
|
+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;"C:\\Users\\paul.BLUECONIC\\AppData\\Local\\node-gyp\\Cache\\20.9.0\\x64\\node.lib"</AdditionalDependencies>
|
76
76
|
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
77
77
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
78
78
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
@@ -83,13 +83,13 @@
|
|
83
83
|
<TargetMachine>MachineX64</TargetMachine>
|
84
84
|
</Link>
|
85
85
|
<ResourceCompile>
|
86
|
-
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\
|
86
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
87
87
|
<PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node_oom_heapdump_native;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;BUILDING_NODE_EXTENSION;DEBUG;_DEBUG;V8_ENABLE_CHECKS;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
88
88
|
</ResourceCompile>
|
89
89
|
</ItemDefinitionGroup>
|
90
90
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
91
91
|
<ClCompile>
|
92
|
-
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\
|
92
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
93
93
|
<AdditionalOptions>/Zc:__cplusplus -std:c++17 %(AdditionalOptions)</AdditionalOptions>
|
94
94
|
<BufferSecurityCheck>true</BufferSecurityCheck>
|
95
95
|
<DebugInformationFormat>OldStyle</DebugInformationFormat>
|
@@ -116,7 +116,7 @@
|
|
116
116
|
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
117
117
|
</Lib>
|
118
118
|
<Link>
|
119
|
-
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;"C:\\Users\\paul.BLUECONIC\\AppData\\Local\\node-gyp\\Cache\\
|
119
|
+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;DelayImp.lib;"C:\\Users\\paul.BLUECONIC\\AppData\\Local\\node-gyp\\Cache\\20.9.0\\x64\\node.lib"</AdditionalDependencies>
|
120
120
|
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
121
121
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
122
122
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
@@ -127,7 +127,7 @@
|
|
127
127
|
<TargetMachine>MachineX64</TargetMachine>
|
128
128
|
</Link>
|
129
129
|
<ResourceCompile>
|
130
|
-
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\
|
130
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\20.9.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
131
131
|
<PreprocessorDefinitions>NODE_GYP_MODULE_NAME=node_oom_heapdump_native;USING_UV_SHARED=1;USING_V8_SHARED=1;V8_DEPRECATION_WARNINGS=1;V8_DEPRECATION_WARNINGS;V8_IMMINENT_DEPRECATION_WARNINGS;_GLIBCXX_USE_CXX11_ABI=1;WIN32;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_HAS_EXCEPTIONS=0;OPENSSL_NO_PINSHARED;OPENSSL_THREADS;BUILDING_NODE_EXTENSION;%(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
132
132
|
</ResourceCompile>
|
133
133
|
</ItemDefinitionGroup>
|
@@ -2,10 +2,10 @@
|
|
2
2
|
#include <v8-profiler.h>
|
3
3
|
#include <stdlib.h>
|
4
4
|
#if defined(_WIN32)
|
5
|
-
|
6
|
-
|
5
|
+
#include <time.h>
|
6
|
+
#define snprintf _snprintf
|
7
7
|
#else
|
8
|
-
|
8
|
+
#include <sys/time.h>
|
9
9
|
#endif
|
10
10
|
|
11
11
|
using namespace v8;
|
@@ -14,47 +14,54 @@ char filename[256];
|
|
14
14
|
bool addTimestamp;
|
15
15
|
bool processingOOM = false;
|
16
16
|
|
17
|
-
class FileOutputStream: public OutputStream
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
17
|
+
class FileOutputStream : public OutputStream
|
18
|
+
{
|
19
|
+
public:
|
20
|
+
FileOutputStream(FILE *stream) : stream_(stream) {}
|
21
|
+
virtual int GetChunkSize()
|
22
|
+
{
|
23
|
+
return 65536;
|
24
|
+
}
|
25
|
+
virtual void EndOfStream() {}
|
26
|
+
virtual WriteResult WriteAsciiChunk(char *data, int size)
|
27
|
+
{
|
28
|
+
const size_t len = static_cast<size_t>(size);
|
29
|
+
size_t off = 0;
|
30
|
+
while (off < len && !feof(stream_) && !ferror(stream_))
|
31
|
+
off += fwrite(data + off, 1, len - off, stream_);
|
32
|
+
return off == len ? kContinue : kAbort;
|
33
|
+
}
|
34
|
+
|
35
|
+
private:
|
36
|
+
FILE *stream_;
|
34
37
|
};
|
35
38
|
|
36
|
-
size_t RaiseLimit(void*
|
39
|
+
size_t RaiseLimit(void *data, size_t current_heap_limit, size_t initial_heap_limit)
|
40
|
+
{
|
37
41
|
return current_heap_limit + 10u * 1024 * 1024; // 10MiB
|
38
42
|
}
|
39
43
|
|
40
|
-
void
|
41
|
-
|
44
|
+
void OnOOMErrorHandler()
|
45
|
+
{
|
46
|
+
if (processingOOM)
|
47
|
+
{
|
42
48
|
fprintf(stderr, "FATAL: OnOOMError called more than once.\n");
|
43
49
|
exit(2);
|
44
50
|
}
|
45
51
|
processingOOM = true;
|
46
52
|
|
47
|
-
if (addTimestamp)
|
53
|
+
if (addTimestamp)
|
54
|
+
{
|
48
55
|
// Add timestamp to filename
|
49
56
|
time_t rawtime;
|
50
|
-
struct tm*
|
57
|
+
struct tm *timeinfo;
|
51
58
|
time(&rawtime);
|
52
59
|
timeinfo = localtime(&rawtime);
|
53
60
|
|
54
|
-
char *
|
55
|
-
pch = strstr
|
56
|
-
strncpy
|
57
|
-
strcat
|
61
|
+
char *pch;
|
62
|
+
pch = strstr(filename, ".heapsnapshot");
|
63
|
+
strncpy(pch, "", 1);
|
64
|
+
strcat(filename, "-%Y%m%dT%H%M%S.heapsnapshot");
|
58
65
|
|
59
66
|
char newFilename[256];
|
60
67
|
strftime(newFilename, sizeof(filename), filename, timeinfo);
|
@@ -62,10 +69,11 @@ void OnOOMError(const char *location, bool is_heap_oom) {
|
|
62
69
|
}
|
63
70
|
|
64
71
|
fprintf(stderr, "Generating Heapdump to '%s' now...\n", filename);
|
65
|
-
FILE*
|
66
|
-
if (fp == NULL)
|
72
|
+
FILE *fp = fopen(filename, "w");
|
73
|
+
if (fp == NULL)
|
74
|
+
abort();
|
67
75
|
|
68
|
-
auto*
|
76
|
+
auto *isolate = v8::Isolate::GetCurrent();
|
69
77
|
|
70
78
|
// Capturing a heap snapshot forces a garbage collection which can, in turn,
|
71
79
|
// trigger the OOM flow which causes recursion. To prevent this, this callback
|
@@ -76,7 +84,7 @@ void OnOOMError(const char *location, bool is_heap_oom) {
|
|
76
84
|
|
77
85
|
// Create heapdump, depending on which Node.js version this can differ
|
78
86
|
// for now, just support Node.js 7 and higher
|
79
|
-
const HeapSnapshot*
|
87
|
+
const HeapSnapshot *snap = isolate->GetHeapProfiler()->TakeHeapSnapshot();
|
80
88
|
|
81
89
|
FileOutputStream stream(fp);
|
82
90
|
snap->Serialize(&stream, HeapSnapshot::kJSON);
|
@@ -86,33 +94,53 @@ void OnOOMError(const char *location, bool is_heap_oom) {
|
|
86
94
|
exit(1);
|
87
95
|
}
|
88
96
|
|
89
|
-
void
|
90
|
-
|
91
|
-
|
97
|
+
void OnOOMErrorNode20(const char *location, const OOMDetails &details)
|
98
|
+
{
|
99
|
+
// Node20+
|
100
|
+
OnOOMErrorHandler();
|
101
|
+
}
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
//
|
96
|
-
|
103
|
+
void OnOOMErrorNode18(const char *location, bool is_heap_oom)
|
104
|
+
{
|
105
|
+
// Up until Node18
|
106
|
+
OnOOMErrorHandler();
|
107
|
+
}
|
108
|
+
|
109
|
+
void ParseArgumentsAndSetErrorHandler(const FunctionCallbackInfo<Value> &args)
|
110
|
+
{
|
111
|
+
Isolate *isolate = args.GetIsolate();
|
112
|
+
#if NODE_VERSION_AT_LEAST(20, 0, 0)
|
113
|
+
// Node20+
|
114
|
+
isolate->SetOOMErrorHandler(OnOOMErrorNode20);
|
115
|
+
#else
|
116
|
+
// Up until Node18
|
117
|
+
isolate->SetOOMErrorHandler(OnOOMErrorNode18);
|
118
|
+
#endif
|
119
|
+
|
120
|
+
// parse JS arguments
|
121
|
+
// 1: filename
|
122
|
+
// 2: addTimestamp boolean
|
123
|
+
#if NODE_VERSION_AT_LEAST(13, 0, 0)
|
97
124
|
Local<Context> context = isolate->GetCurrentContext();
|
98
125
|
String::Utf8Value fArg(isolate, args[0]->ToString(context).ToLocalChecked());
|
99
|
-
|
126
|
+
#elif NODE_VERSION_AT_LEAST(12, 0, 0)
|
100
127
|
String::Utf8Value fArg(isolate, args[0]->ToString(isolate));
|
101
|
-
|
128
|
+
#elif NODE_VERSION_AT_LEAST(9, 0, 0)
|
102
129
|
String::Utf8Value fArg(isolate, args[0]->ToString());
|
103
|
-
|
130
|
+
#else
|
104
131
|
String::Utf8Value fArg(args[0]->ToString());
|
105
|
-
|
106
|
-
strncpy(filename, (const char*)(*fArg), sizeof(filename) - 1);
|
132
|
+
#endif
|
133
|
+
strncpy(filename, (const char *)(*fArg), sizeof(filename) - 1);
|
107
134
|
|
108
|
-
|
135
|
+
#if NODE_VERSION_AT_LEAST(12, 0, 0)
|
109
136
|
addTimestamp = args[1]->BooleanValue(isolate);
|
110
|
-
|
137
|
+
#else
|
111
138
|
addTimestamp = args[1]->BooleanValue();
|
112
|
-
|
139
|
+
#endif
|
113
140
|
}
|
114
141
|
|
115
|
-
void init(Local<Object> exports)
|
142
|
+
void init(Local<Object> exports)
|
143
|
+
{
|
116
144
|
NODE_SET_METHOD(exports, "call", ParseArgumentsAndSetErrorHandler);
|
117
145
|
}
|
118
146
|
|
package/package.json
CHANGED