Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

fix: Make takeHeapSnapshot() work #57

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/internal/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Path = require('path');
const Repl = require('repl');
const util = require('util');
const vm = require('vm');
const JSONSplitStream = require('json-split-stream');

const debuglog = util.debuglog('inspect');

Expand Down Expand Up @@ -900,10 +901,10 @@ function createRepl(inspector) {
return new Promise((resolve, reject) => {
const absoluteFile = Path.resolve(filename);
const writer = FS.createWriteStream(absoluteFile);
let totalSize;
const jsonChunker = new JSONSplitStream({ storeData: false });
jsonChunker.on('finishedJSON', onFinishedJSON);
let sizeWritten = 0;
function onProgress({ done, total, finished }) {
totalSize = total;
if (finished) {
print('Heap snaphost prepared.');
} else {
Expand All @@ -912,14 +913,16 @@ function createRepl(inspector) {
}
function onChunk({ chunk }) {
sizeWritten += chunk.length;
writer.write(chunk);
print(`Writing snapshot: ${sizeWritten}/${totalSize}`, true);
if (sizeWritten >= totalSize) {
writer.end();
teardown();
print(`Wrote snapshot: ${absoluteFile}`);
resolve();
}
writer.write(chunk, () => {
print(`Writing snapshot: ${sizeWritten} bytes`, true);
jsonChunker.write(chunk);
});
}
function onFinishedJSON() {
writer.end();
teardown();
print(`Wrote snapshot: ${absoluteFile} (${sizeWritten} bytes)`);
resolve();
}
function teardown() {
HeapProfiler.removeListener(
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
]
}
},
"dependencies": {},
"dependencies": {
"json-split-stream": "^1.1.0"
},
"devDependencies": {
"eslint": "^3.10.2",
"nlm": "^3.0.0",
Expand Down