2021-04-08 23:55:45 -07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
|
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
|
|
|
|
const fixtures = require('../common/fixtures');
|
2021-05-03 21:58:42 -07:00
|
|
|
const startCLI = require('../common/debugger');
|
2021-04-08 23:55:45 -07:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
|
|
|
|
tmpdir.refresh();
|
|
|
|
|
|
|
|
const { readFileSync } = require('fs');
|
|
|
|
|
2023-08-15 22:45:44 +09:00
|
|
|
const filename = tmpdir.resolve('node.heapsnapshot');
|
2021-04-08 23:55:45 -07:00
|
|
|
|
|
|
|
// Heap profiler take snapshot.
|
|
|
|
{
|
2021-08-06 12:59:28 -04:00
|
|
|
const opts = { cwd: tmpdir.path };
|
2023-03-28 00:03:40 +02:00
|
|
|
const cli = startCLI(['--port=0', fixtures.path('debugger/empty.js')], [], opts);
|
2021-04-08 23:55:45 -07:00
|
|
|
|
2022-09-16 17:47:04 -04:00
|
|
|
async function waitInitialBreak() {
|
|
|
|
try {
|
|
|
|
await cli.waitForInitialBreak();
|
|
|
|
await cli.waitForPrompt();
|
|
|
|
await cli.command('takeHeapSnapshot()');
|
|
|
|
JSON.parse(readFileSync(filename, 'utf8'));
|
|
|
|
// Check that two simultaneous snapshots don't step all over each other.
|
|
|
|
// Refs: https://github.com/nodejs/node/issues/39555
|
|
|
|
await cli.command('takeHeapSnapshot(); takeHeapSnapshot()');
|
|
|
|
JSON.parse(readFileSync(filename, 'utf8'));
|
|
|
|
} finally {
|
|
|
|
await cli.quit();
|
|
|
|
}
|
2021-04-08 23:55:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the snapshot is valid JSON.
|
2022-09-16 17:47:04 -04:00
|
|
|
waitInitialBreak().then(common.mustCall());
|
2021-04-08 23:55:45 -07:00
|
|
|
}
|