This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix
takeHeapSnapshot()
truncation bug
Fix a logic bug in `takeHeapSnapshot()` where it interpreted the item count as the byte count, resulting in truncated snapshots. This change hinges on the observation that the completion callback always comes after any and all `'addHeapSnapshotChunk'` events. I'm 95% sure after digging into the V8 inspector and its integration with Node.js that the assumption above is correct. If it turns out I'm mistaken, then we will most likely treat that as a bug in Node.js, not node-inspect. Fixes: #56
- Loading branch information
1 parent
c07adb1
commit 94f0bf9
Showing
2 changed files
with
44 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
const { test } = require('tap'); | ||
const { readFileSync, unlinkSync } = require('fs'); | ||
|
||
const startCLI = require('./start-cli'); | ||
const filename = 'node.heapsnapshot'; | ||
|
||
function cleanup() { | ||
try { | ||
unlinkSync(filename); | ||
} catch (_) { | ||
// Ignore. | ||
} | ||
} | ||
|
||
cleanup(); | ||
|
||
test('Heap profiler take snapshot', (t) => { | ||
const cli = startCLI(['examples/empty.js']); | ||
|
||
function onFatal(error) { | ||
cli.quit(); | ||
throw error; | ||
} | ||
|
||
// Check that the snapshot is valid JSON. | ||
return cli.waitForInitialBreak() | ||
.then(() => cli.waitForPrompt()) | ||
.then(() => cli.command('takeHeapSnapshot()')) | ||
.then(() => JSON.parse(readFileSync(filename, 'utf8'))) | ||
.then(() => cleanup()) | ||
.then(() => cli.quit()) | ||
.then(null, onFatal); | ||
}); |