-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib,src,doc: add --heapsnapshot-signal CLI flag
This flag allows heap snapshots to be captured without modifying application code. PR-URL: #27133 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
Showing
6 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
if (common.isWindows) | ||
common.skip('test not supported on Windows'); | ||
|
||
const assert = require('assert'); | ||
|
||
if (process.argv[2] === 'child') { | ||
const fs = require('fs'); | ||
|
||
assert.strictEqual(process.listenerCount('SIGUSR2'), 1); | ||
process.kill(process.pid, 'SIGUSR2'); | ||
process.kill(process.pid, 'SIGUSR2'); | ||
|
||
// Asynchronously wait for the snapshot. Use an async loop to be a bit more | ||
// robust in case platform or machine differences throw off the timing. | ||
(function validate() { | ||
const files = fs.readdirSync(process.cwd()); | ||
|
||
if (files.length === 0) | ||
return setImmediate(validate); | ||
|
||
assert.strictEqual(files.length, 2); | ||
|
||
for (let i = 0; i < files.length; i++) { | ||
assert(/^Heap\..+\.heapsnapshot$/.test(files[i])); | ||
JSON.parse(fs.readFileSync(files[i])); | ||
} | ||
})(); | ||
} else { | ||
const { spawnSync } = require('child_process'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
tmpdir.refresh(); | ||
const args = ['--heapsnapshot-signal', 'SIGUSR2', __filename, 'child']; | ||
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path }); | ||
|
||
assert.strictEqual(child.status, 0); | ||
assert.strictEqual(child.signal, null); | ||
} |