node-oom-heapdump 2.1.0-progress.1 → 3.0.1-beta
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/.eslintrc.js +2 -2
- package/.travis.yml +13 -9
- package/CHANGELOG.md +107 -84
- package/LICENSE +21 -21
- package/README.md +129 -143
- package/build/binding.sln +19 -0
- package/build/node_oom_heapdump_native.vcxproj +145 -0
- package/build/node_oom_heapdump_native.vcxproj.filters +14 -0
- package/index.js +112 -133
- package/lib/cpuProfileWorker.js +48 -48
- package/lib/heapdumpWorker.js +48 -48
- package/lib/index.js +186 -227
- package/package.json +40 -51
- package/.github/workflows/publish-native-assets-to-github-releases.yml +0 -37
- package/binding.gyp +0 -10
- package/build/Makefile +0 -324
- package/build/binding.Makefile +0 -6
- package/build/node_oom_heapdump_native.target.mk +0 -157
- package/lib/node_oom_heapdump_native.cc +0 -110
- package/tests/index.js +0 -27
- package/tests/long_running_process.js +0 -27
- package/tests/long_running_process_cpu.js +0 -35
- package/tests/oom_app.js +0 -22
@@ -0,0 +1,145 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
|
+
<ItemGroup Label="ProjectConfigurations">
|
4
|
+
<ProjectConfiguration Include="Debug|x64">
|
5
|
+
<Configuration>Debug</Configuration>
|
6
|
+
<Platform>x64</Platform>
|
7
|
+
</ProjectConfiguration>
|
8
|
+
<ProjectConfiguration Include="Release|x64">
|
9
|
+
<Configuration>Release</Configuration>
|
10
|
+
<Platform>x64</Platform>
|
11
|
+
</ProjectConfiguration>
|
12
|
+
</ItemGroup>
|
13
|
+
<PropertyGroup Label="Globals">
|
14
|
+
<ProjectGuid>{B44BD8E7-8AB3-68F6-9D96-154D16CEC9C0}</ProjectGuid>
|
15
|
+
<Keyword>Win32Proj</Keyword>
|
16
|
+
<RootNamespace>node_oom_heapdump_native</RootNamespace>
|
17
|
+
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
|
18
|
+
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
|
19
|
+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
20
|
+
</PropertyGroup>
|
21
|
+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
|
22
|
+
<PropertyGroup Label="Configuration">
|
23
|
+
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
24
|
+
</PropertyGroup>
|
25
|
+
<PropertyGroup Label="Locals">
|
26
|
+
<PlatformToolset>v141</PlatformToolset>
|
27
|
+
</PropertyGroup>
|
28
|
+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
|
29
|
+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props"/>
|
30
|
+
<ImportGroup Label="ExtensionSettings"/>
|
31
|
+
<ImportGroup Label="PropertySheets">
|
32
|
+
<Import Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"/>
|
33
|
+
</ImportGroup>
|
34
|
+
<PropertyGroup Label="UserMacros"/>
|
35
|
+
<PropertyGroup>
|
36
|
+
<ExecutablePath>$(ExecutablePath);$(MSBuildProjectDirectory)\..\bin\;$(MSBuildProjectDirectory)\..\bin\</ExecutablePath>
|
37
|
+
<IgnoreImportLibrary>true</IgnoreImportLibrary>
|
38
|
+
<IntDir>$(Configuration)\obj\$(ProjectName)\</IntDir>
|
39
|
+
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
|
40
|
+
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
41
|
+
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
|
42
|
+
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
|
43
|
+
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.node</TargetExt>
|
44
|
+
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
|
45
|
+
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.node</TargetExt>
|
46
|
+
<TargetName>$(ProjectName)</TargetName>
|
47
|
+
<TargetPath>$(OutDir)\$(ProjectName).node</TargetPath>
|
48
|
+
</PropertyGroup>
|
49
|
+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
50
|
+
<ClCompile>
|
51
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
52
|
+
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
53
|
+
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
54
|
+
<BufferSecurityCheck>true</BufferSecurityCheck>
|
55
|
+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
|
56
|
+
<DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
57
|
+
<ExceptionHandling>false</ExceptionHandling>
|
58
|
+
<MinimalRebuild>false</MinimalRebuild>
|
59
|
+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
60
|
+
<OmitFramePointers>false</OmitFramePointers>
|
61
|
+
<Optimization>Disabled</Optimization>
|
62
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
63
|
+
<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>
|
64
|
+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
65
|
+
<StringPooling>true</StringPooling>
|
66
|
+
<SuppressStartupBanner>true</SuppressStartupBanner>
|
67
|
+
<TreatWarningAsError>false</TreatWarningAsError>
|
68
|
+
<WarningLevel>Level3</WarningLevel>
|
69
|
+
<WholeProgramOptimization>true</WholeProgramOptimization>
|
70
|
+
</ClCompile>
|
71
|
+
<Lib>
|
72
|
+
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
73
|
+
</Lib>
|
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\\16.14.0\\x64\\node.lib"</AdditionalDependencies>
|
76
|
+
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
77
|
+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
78
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
79
|
+
<OptimizeReferences>true</OptimizeReferences>
|
80
|
+
<OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
|
81
|
+
<SuppressStartupBanner>true</SuppressStartupBanner>
|
82
|
+
<TargetExt>.node</TargetExt>
|
83
|
+
<TargetMachine>MachineX64</TargetMachine>
|
84
|
+
</Link>
|
85
|
+
<ResourceCompile>
|
86
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
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
|
+
</ResourceCompile>
|
89
|
+
</ItemDefinitionGroup>
|
90
|
+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
91
|
+
<ClCompile>
|
92
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
93
|
+
<AdditionalOptions>/Zc:__cplusplus %(AdditionalOptions)</AdditionalOptions>
|
94
|
+
<BufferSecurityCheck>true</BufferSecurityCheck>
|
95
|
+
<DebugInformationFormat>OldStyle</DebugInformationFormat>
|
96
|
+
<DisableSpecificWarnings>4351;4355;4800;4251;4275;4244;4267;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
97
|
+
<ExceptionHandling>false</ExceptionHandling>
|
98
|
+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
99
|
+
<FunctionLevelLinking>true</FunctionLevelLinking>
|
100
|
+
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
101
|
+
<IntrinsicFunctions>true</IntrinsicFunctions>
|
102
|
+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
103
|
+
<OmitFramePointers>true</OmitFramePointers>
|
104
|
+
<Optimization>Full</Optimization>
|
105
|
+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
106
|
+
<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>
|
107
|
+
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
108
|
+
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
109
|
+
<StringPooling>true</StringPooling>
|
110
|
+
<SuppressStartupBanner>true</SuppressStartupBanner>
|
111
|
+
<TreatWarningAsError>false</TreatWarningAsError>
|
112
|
+
<WarningLevel>Level3</WarningLevel>
|
113
|
+
<WholeProgramOptimization>true</WholeProgramOptimization>
|
114
|
+
</ClCompile>
|
115
|
+
<Lib>
|
116
|
+
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
117
|
+
</Lib>
|
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\\16.14.0\\x64\\node.lib"</AdditionalDependencies>
|
120
|
+
<AdditionalOptions>/LTCG:INCREMENTAL %(AdditionalOptions)</AdditionalOptions>
|
121
|
+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
122
|
+
<GenerateDebugInformation>true</GenerateDebugInformation>
|
123
|
+
<OptimizeReferences>true</OptimizeReferences>
|
124
|
+
<OutputFile>$(OutDir)$(ProjectName).node</OutputFile>
|
125
|
+
<SuppressStartupBanner>true</SuppressStartupBanner>
|
126
|
+
<TargetExt>.node</TargetExt>
|
127
|
+
<TargetMachine>MachineX64</TargetMachine>
|
128
|
+
</Link>
|
129
|
+
<ResourceCompile>
|
130
|
+
<AdditionalIncludeDirectories>C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\include\node;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\src;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\config;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\openssl\openssl\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\uv\include;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\zlib;C:\Users\paul.BLUECONIC\AppData\Local\node-gyp\Cache\16.14.0\deps\v8\include;..\node_modules\nan;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
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
|
+
</ResourceCompile>
|
133
|
+
</ItemDefinitionGroup>
|
134
|
+
<ItemGroup>
|
135
|
+
<None Include="..\binding.gyp"/>
|
136
|
+
</ItemGroup>
|
137
|
+
<ItemGroup>
|
138
|
+
<ClCompile Include="..\lib\node_oom_heapdump_native.cc">
|
139
|
+
<ObjectFileName>$(IntDir)\lib\node_oom_heapdump_native.obj</ObjectFileName>
|
140
|
+
</ClCompile>
|
141
|
+
</ItemGroup>
|
142
|
+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
|
143
|
+
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets"/>
|
144
|
+
<ImportGroup Label="ExtensionTargets"/>
|
145
|
+
</Project>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
3
|
+
<ItemGroup>
|
4
|
+
<Filter Include="lib">
|
5
|
+
<UniqueIdentifier>{2739B19F-16DF-601C-060A-FF86F6A40045}</UniqueIdentifier>
|
6
|
+
</Filter>
|
7
|
+
</ItemGroup>
|
8
|
+
<ItemGroup>
|
9
|
+
<ClCompile Include="..\lib\node_oom_heapdump_native.cc">
|
10
|
+
<Filter>lib</Filter>
|
11
|
+
</ClCompile>
|
12
|
+
<None Include="..\binding.gyp"/>
|
13
|
+
</ItemGroup>
|
14
|
+
</Project>
|
package/index.js
CHANGED
@@ -1,134 +1,113 @@
|
|
1
|
-
let nodeOomLib = require("./lib");
|
2
|
-
|
3
|
-
// private
|
4
|
-
let instance;
|
5
|
-
|
6
|
-
// expose API, which is a singleton
|
7
|
-
module.exports = function (options) {
|
8
|
-
if (!instance) {
|
9
|
-
instance = new NodeOomHeapdumpAPI(options);
|
10
|
-
}
|
11
|
-
return instance;
|
12
|
-
}
|
13
|
-
|
14
|
-
// API class
|
15
|
-
class NodeOomHeapdumpAPI {
|
16
|
-
constructor(options) {
|
17
|
-
parseOptions(options || {});
|
18
|
-
|
19
|
-
// verify connectibility on the configured port
|
20
|
-
checkPort(options.port);
|
21
|
-
|
22
|
-
this._impl = new nodeOomLib(options);
|
23
|
-
}
|
24
|
-
|
25
|
-
/**
|
26
|
-
* Returns the path to the created heap snapshot in a promise, or rejects on error
|
27
|
-
* @param {String} snapshotPath - path of the snapshot
|
28
|
-
* @return {Promise} the heap snapshot path on success or error on rejection
|
29
|
-
*/
|
30
|
-
createHeapSnapshot(snapshotPath) {
|
31
|
-
return this._impl.createHeapSnapshot(snapshotPath);
|
32
|
-
}
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Deletes all previously created heapsnapshots from disk
|
36
|
-
*/
|
37
|
-
deleteAllHeapSnapshots() {
|
38
|
-
this._impl.deleteAllHeapSnapshots();
|
39
|
-
}
|
40
|
-
|
41
|
-
/**
|
42
|
-
* Deletes a particular snapshot from disk
|
43
|
-
* @param {String} snapshotPath - path of the heap snapshot to delete
|
44
|
-
* @return {Promise}
|
45
|
-
*/
|
46
|
-
deleteHeapSnapshot(snapshotPath) {
|
47
|
-
return this._impl.deleteHeapSnapshot(snapshotPath);
|
48
|
-
}
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Returns the path to the created CPU profile in a promise, or rejects on error
|
52
|
-
* @param {String} cpuProfilePath - path of the CPU profile
|
53
|
-
* @param {number} duration - the duration of the CPU profile in ms
|
54
|
-
* @return {Promise} the CPU profile path on success or error on rejection
|
55
|
-
*/
|
56
|
-
createCpuProfile(cpuProfilePath, duration) {
|
57
|
-
if (duration === undefined) {
|
58
|
-
duration = 30000;
|
59
|
-
} else {
|
60
|
-
duration = parseInt(duration);
|
61
|
-
}
|
62
|
-
return this._impl.createCpuProfile(cpuProfilePath, duration);
|
63
|
-
}
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Deletes all previously created CPU profiles from disk
|
67
|
-
*/
|
68
|
-
deleteAllCpuProfiles() {
|
69
|
-
this._impl.deleteAllCpuProfiles();
|
70
|
-
}
|
71
|
-
|
72
|
-
/**
|
73
|
-
* Deletes a particular CPU profile from disk
|
74
|
-
* @param {String} cpuProfilePath - path to the CPU profile to delete from disk
|
75
|
-
* @return {Promise}
|
76
|
-
*/
|
77
|
-
deleteCpuProfile(cpuProfilePath) {
|
78
|
-
return this._impl.deleteCpuProfile(cpuProfilePath);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
// utility functions
|
83
|
-
function parseOptions(options) {
|
84
|
-
if (options.
|
85
|
-
options.
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
options.
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
}
|
113
|
-
options.addTimestamp = options.addTimestamp === true;
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
function checkPort(port) {
|
118
|
-
const WebSocket = require('ws');
|
119
|
-
|
120
|
-
const ws = new WebSocket('ws://127.0.0.1:' + port);
|
121
|
-
try {
|
122
|
-
ws.on('error', function error(e) {
|
123
|
-
if (e.code !== 'ECONNREFUSED') {
|
124
|
-
// this is good; this port should already be taken
|
125
|
-
console.log("Debugger is listening on port %s, 'node-oom-heapdump' can function correctly.", port);
|
126
|
-
} else {
|
127
|
-
// ECONNREFUSED, this is not good
|
128
|
-
console.warn("Debugger is not listening on port %s, 'node-oom-heapdump' cannot function correctly. Is the Node.js process started with the --inspect=%s flag?", port, port, e);
|
129
|
-
}
|
130
|
-
});
|
131
|
-
} catch (err) {
|
132
|
-
console.error(err);
|
133
|
-
}
|
1
|
+
let nodeOomLib = require("./lib");
|
2
|
+
|
3
|
+
// private
|
4
|
+
let instance;
|
5
|
+
|
6
|
+
// expose API, which is a singleton
|
7
|
+
module.exports = function (options) {
|
8
|
+
if (!instance) {
|
9
|
+
instance = new NodeOomHeapdumpAPI(options);
|
10
|
+
}
|
11
|
+
return instance;
|
12
|
+
}
|
13
|
+
|
14
|
+
// API class
|
15
|
+
class NodeOomHeapdumpAPI {
|
16
|
+
constructor(options) {
|
17
|
+
parseOptions(options || {});
|
18
|
+
|
19
|
+
// verify connectibility on the configured port
|
20
|
+
checkPort(options.port);
|
21
|
+
|
22
|
+
this._impl = new nodeOomLib(options);
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Returns the path to the created heap snapshot in a promise, or rejects on error
|
27
|
+
* @param {String} snapshotPath - path of the snapshot
|
28
|
+
* @return {Promise} the heap snapshot path on success or error on rejection
|
29
|
+
*/
|
30
|
+
createHeapSnapshot(snapshotPath) {
|
31
|
+
return this._impl.createHeapSnapshot(snapshotPath);
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Deletes all previously created heapsnapshots from disk
|
36
|
+
*/
|
37
|
+
deleteAllHeapSnapshots() {
|
38
|
+
this._impl.deleteAllHeapSnapshots();
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Deletes a particular snapshot from disk
|
43
|
+
* @param {String} snapshotPath - path of the heap snapshot to delete
|
44
|
+
* @return {Promise}
|
45
|
+
*/
|
46
|
+
deleteHeapSnapshot(snapshotPath) {
|
47
|
+
return this._impl.deleteHeapSnapshot(snapshotPath);
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Returns the path to the created CPU profile in a promise, or rejects on error
|
52
|
+
* @param {String} cpuProfilePath - path of the CPU profile
|
53
|
+
* @param {number} duration - the duration of the CPU profile in ms
|
54
|
+
* @return {Promise} the CPU profile path on success or error on rejection
|
55
|
+
*/
|
56
|
+
createCpuProfile(cpuProfilePath, duration) {
|
57
|
+
if (duration === undefined) {
|
58
|
+
duration = 30000;
|
59
|
+
} else {
|
60
|
+
duration = parseInt(duration);
|
61
|
+
}
|
62
|
+
return this._impl.createCpuProfile(cpuProfilePath, duration);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Deletes all previously created CPU profiles from disk
|
67
|
+
*/
|
68
|
+
deleteAllCpuProfiles() {
|
69
|
+
this._impl.deleteAllCpuProfiles();
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Deletes a particular CPU profile from disk
|
74
|
+
* @param {String} cpuProfilePath - path to the CPU profile to delete from disk
|
75
|
+
* @return {Promise}
|
76
|
+
*/
|
77
|
+
deleteCpuProfile(cpuProfilePath) {
|
78
|
+
return this._impl.deleteCpuProfile(cpuProfilePath);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
// utility functions
|
83
|
+
function parseOptions(options) {
|
84
|
+
if (options.port === undefined) {
|
85
|
+
options.port = 9229;
|
86
|
+
} else {
|
87
|
+
options.port = parseInt(options.port);
|
88
|
+
}
|
89
|
+
if (options.addTimestamp === undefined) {
|
90
|
+
options.addTimestamp = false;
|
91
|
+
} else {
|
92
|
+
options.addTimestamp = options.addTimestamp === true;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
function checkPort(port) {
|
97
|
+
const WebSocket = require('ws');
|
98
|
+
|
99
|
+
const ws = new WebSocket('ws://127.0.0.1:' + port);
|
100
|
+
try {
|
101
|
+
ws.on('error', function error(e) {
|
102
|
+
if (e.code !== 'ECONNREFUSED') {
|
103
|
+
// this is good; this port should already be taken
|
104
|
+
console.log("Debugger is listening on port %s, 'node-oom-heapdump' can function correctly.", port);
|
105
|
+
} else {
|
106
|
+
// ECONNREFUSED, this is not good
|
107
|
+
console.warn("Debugger is not listening on port %s, 'node-oom-heapdump' cannot function correctly. Is the Node.js process started with the --inspect=%s flag?", port, port, e);
|
108
|
+
}
|
109
|
+
});
|
110
|
+
} catch (err) {
|
111
|
+
console.error(err);
|
112
|
+
}
|
134
113
|
}
|
package/lib/cpuProfileWorker.js
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
let fs = require('fs');
|
2
|
-
|
3
|
-
// set global variables based on args passed on to this CPU profile worker
|
4
|
-
let devToolsPort = process.argv[2];
|
5
|
-
let path = process.argv[3];
|
6
|
-
let duration = process.argv[4];
|
7
|
-
|
8
|
-
console.error('Started CPU profile (duration: %sms) %s worker on DevTools port \'%s\'.', duration, path, devToolsPort);
|
9
|
-
|
10
|
-
let CDP = require('chrome-remote-interface');
|
11
|
-
let writeStream = fs.createWriteStream(path);
|
12
|
-
let handleError = function (arg1, arg2) {
|
13
|
-
console.error("Error occurred while creating CPU profile", arg1, arg2 || "");
|
14
|
-
writeStream.end();
|
15
|
-
process.exit(-1);
|
16
|
-
};
|
17
|
-
writeStream.on('error', (err) => {
|
18
|
-
handleError("CPU profile path not valid or writable", err);
|
19
|
-
});
|
20
|
-
|
21
|
-
CDP({
|
22
|
-
host: 'localhost',
|
23
|
-
port: devToolsPort
|
24
|
-
}, (debugInstance) => {
|
25
|
-
let cpuProfiler = debugInstance.Profiler;
|
26
|
-
cpuProfiler.enable();
|
27
|
-
cpuProfiler.start();
|
28
|
-
|
29
|
-
setTimeout(() => {
|
30
|
-
let Profile = cpuProfiler.stop();
|
31
|
-
Profile.then((p) => {
|
32
|
-
writeStream.write(JSON.stringify(p.profile));
|
33
|
-
writeStream.end();
|
34
|
-
|
35
|
-
cpuProfiler.disable();
|
36
|
-
|
37
|
-
console.error('CPU profile created in \'%s\'. Exiting worker now.', path);
|
38
|
-
|
39
|
-
// were done, exit normally
|
40
|
-
process.exit(0);
|
41
|
-
}).catch((err) => {
|
42
|
-
handleError(err);
|
43
|
-
});
|
44
|
-
}, duration);
|
45
|
-
}).on('error', (err) => {
|
46
|
-
// cannot connect to the remote endpoint
|
47
|
-
handleError(err);
|
48
|
-
});
|
1
|
+
let fs = require('fs');
|
2
|
+
|
3
|
+
// set global variables based on args passed on to this CPU profile worker
|
4
|
+
let devToolsPort = process.argv[2];
|
5
|
+
let path = process.argv[3];
|
6
|
+
let duration = process.argv[4];
|
7
|
+
|
8
|
+
console.error('Started CPU profile (duration: %sms) %s worker on DevTools port \'%s\'.', duration, path, devToolsPort);
|
9
|
+
|
10
|
+
let CDP = require('chrome-remote-interface');
|
11
|
+
let writeStream = fs.createWriteStream(path);
|
12
|
+
let handleError = function (arg1, arg2) {
|
13
|
+
console.error("Error occurred while creating CPU profile", arg1, arg2 || "");
|
14
|
+
writeStream.end();
|
15
|
+
process.exit(-1);
|
16
|
+
};
|
17
|
+
writeStream.on('error', (err) => {
|
18
|
+
handleError("CPU profile path not valid or writable", err);
|
19
|
+
});
|
20
|
+
|
21
|
+
CDP({
|
22
|
+
host: 'localhost',
|
23
|
+
port: devToolsPort
|
24
|
+
}, (debugInstance) => {
|
25
|
+
let cpuProfiler = debugInstance.Profiler;
|
26
|
+
cpuProfiler.enable();
|
27
|
+
cpuProfiler.start();
|
28
|
+
|
29
|
+
setTimeout(() => {
|
30
|
+
let Profile = cpuProfiler.stop();
|
31
|
+
Profile.then((p) => {
|
32
|
+
writeStream.write(JSON.stringify(p.profile));
|
33
|
+
writeStream.end();
|
34
|
+
|
35
|
+
cpuProfiler.disable();
|
36
|
+
|
37
|
+
console.error('CPU profile created in \'%s\'. Exiting worker now.', path);
|
38
|
+
|
39
|
+
// were done, exit normally
|
40
|
+
process.exit(0);
|
41
|
+
}).catch((err) => {
|
42
|
+
handleError(err);
|
43
|
+
});
|
44
|
+
}, duration);
|
45
|
+
}).on('error', (err) => {
|
46
|
+
// cannot connect to the remote endpoint
|
47
|
+
handleError(err);
|
48
|
+
});
|
package/lib/heapdumpWorker.js
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
let fs = require('fs');
|
2
|
-
|
3
|
-
// set global variables based on args passed on to this heapdump worker
|
4
|
-
let devToolsPort = process.argv[2];
|
5
|
-
let path = process.argv[3];
|
6
|
-
let logPrefix = (process.argv[4]) ? process.argv[4] + " " : "";
|
7
|
-
|
8
|
-
console.error('Started heapdump %sworker for \'%s\' on DevTools port \'%s\'.', logPrefix, path, devToolsPort);
|
9
|
-
|
10
|
-
let CDP = require('chrome-remote-interface');
|
11
|
-
let writeStream = fs.createWriteStream(path);
|
12
|
-
let handleError = function (arg1, arg2) {
|
13
|
-
console.error("Error occurred while creating heapdump", arg1, arg2 || "");
|
14
|
-
writeStream.end();
|
15
|
-
process.exit(-1);
|
16
|
-
};
|
17
|
-
writeStream.on('error', (err) => {
|
18
|
-
handleError("Heapdump path not valid or writable", err);
|
19
|
-
});
|
20
|
-
|
21
|
-
CDP({
|
22
|
-
host: 'localhost',
|
23
|
-
port: devToolsPort
|
24
|
-
}, (debugInstance) => {
|
25
|
-
debugInstance.Debugger.enable();
|
26
|
-
debugInstance.Debugger.pause();
|
27
|
-
|
28
|
-
let heapProfiler = debugInstance.HeapProfiler;
|
29
|
-
heapProfiler.enable();
|
30
|
-
|
31
|
-
debugInstance.on('HeapProfiler.addHeapSnapshotChunk', function (evt) {
|
32
|
-
writeStream.write(evt.chunk);
|
33
|
-
});
|
34
|
-
heapProfiler.takeHeapSnapshot({
|
35
|
-
reportProgress: false
|
36
|
-
}, function () {
|
37
|
-
heapProfiler.disable();
|
38
|
-
writeStream.end();
|
39
|
-
|
40
|
-
console.error('%sHeapdump created in \'%s\'. Exiting worker now.', logPrefix, path);
|
41
|
-
|
42
|
-
debugInstance.Debugger.resume();
|
43
|
-
|
44
|
-
// were done, exit normally
|
45
|
-
process.exit(0);
|
46
|
-
});
|
47
|
-
}).on('error', (err) => {
|
48
|
-
handleError(err);
|
1
|
+
let fs = require('fs');
|
2
|
+
|
3
|
+
// set global variables based on args passed on to this heapdump worker
|
4
|
+
let devToolsPort = process.argv[2];
|
5
|
+
let path = process.argv[3];
|
6
|
+
let logPrefix = (process.argv[4]) ? process.argv[4] + " " : "";
|
7
|
+
|
8
|
+
console.error('Started heapdump %sworker for \'%s\' on DevTools port \'%s\'.', logPrefix, path, devToolsPort);
|
9
|
+
|
10
|
+
let CDP = require('chrome-remote-interface');
|
11
|
+
let writeStream = fs.createWriteStream(path);
|
12
|
+
let handleError = function (arg1, arg2) {
|
13
|
+
console.error("Error occurred while creating heapdump", arg1, arg2 || "");
|
14
|
+
writeStream.end();
|
15
|
+
process.exit(-1);
|
16
|
+
};
|
17
|
+
writeStream.on('error', (err) => {
|
18
|
+
handleError("Heapdump path not valid or writable", err);
|
19
|
+
});
|
20
|
+
|
21
|
+
CDP({
|
22
|
+
host: 'localhost',
|
23
|
+
port: devToolsPort
|
24
|
+
}, (debugInstance) => {
|
25
|
+
debugInstance.Debugger.enable();
|
26
|
+
debugInstance.Debugger.pause();
|
27
|
+
|
28
|
+
let heapProfiler = debugInstance.HeapProfiler;
|
29
|
+
heapProfiler.enable();
|
30
|
+
|
31
|
+
debugInstance.on('HeapProfiler.addHeapSnapshotChunk', function (evt) {
|
32
|
+
writeStream.write(evt.chunk);
|
33
|
+
});
|
34
|
+
heapProfiler.takeHeapSnapshot({
|
35
|
+
reportProgress: false
|
36
|
+
}, function () {
|
37
|
+
heapProfiler.disable();
|
38
|
+
writeStream.end();
|
39
|
+
|
40
|
+
console.error('%sHeapdump created in \'%s\'. Exiting worker now.', logPrefix, path);
|
41
|
+
|
42
|
+
debugInstance.Debugger.resume();
|
43
|
+
|
44
|
+
// were done, exit normally
|
45
|
+
process.exit(0);
|
46
|
+
});
|
47
|
+
}).on('error', (err) => {
|
48
|
+
handleError(err);
|
49
49
|
});
|