mirror of
https://github.com/nodejs/node.git
synced 2024-11-29 23:16:30 +01:00
5f38797ea5
Adds `v8.writeHeapSnapshot(filename)` with impl adapted from the `node-heapdump` module. Also, adds a v8.getHeapSnapshot() alternative that returns a Readable Stream PR-URL: https://github.com/nodejs/node/pull/26501 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.isMainThread)
|
|
common.skip('process.chdir is not available in Workers');
|
|
|
|
const { writeHeapSnapshot, getHeapSnapshot } = require('v8');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
|
process.chdir(tmpdir.path);
|
|
|
|
{
|
|
writeHeapSnapshot('my.heapdump');
|
|
fs.accessSync('my.heapdump');
|
|
}
|
|
|
|
{
|
|
const heapdump = writeHeapSnapshot();
|
|
assert.strictEqual(typeof heapdump, 'string');
|
|
fs.accessSync(heapdump);
|
|
}
|
|
|
|
[1, true, {}, [], null, Infinity, NaN].forEach((i) => {
|
|
common.expectsError(() => writeHeapSnapshot(i), {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "path" argument must be one of type string, Buffer, or URL.' +
|
|
` Received type ${typeof i}`
|
|
});
|
|
});
|
|
|
|
{
|
|
let data = '';
|
|
const snapshot = getHeapSnapshot();
|
|
snapshot.setEncoding('utf-8');
|
|
snapshot.on('data', common.mustCallAtLeast((chunk) => {
|
|
data += chunk.toString();
|
|
}));
|
|
snapshot.on('end', common.mustCall(() => {
|
|
JSON.parse(data);
|
|
}));
|
|
}
|