mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 23:36:56 +00:00

This patch adds a --heapsnapshot-near-heap-limit CLI option that takes heap snapshots when the V8 heap is approaching the heap size limit. It will try to write the snapshots to disk before the program crashes due to OOM. PR-URL: https://github.com/nodejs/node/pull/33010 Refs: https://github.com/nodejs/node/issues/27552 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
37 lines
964 B
JavaScript
37 lines
964 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const assert = require('assert');
|
|
const { spawnSync } = require('child_process');
|
|
const fixtures = require('../common/fixtures');
|
|
const fs = require('fs');
|
|
const env = {
|
|
...process.env,
|
|
TEST_ALLOCATION: 50000,
|
|
TEST_CHUNK: 1000,
|
|
TEST_CLEAN_INTERVAL: 500,
|
|
NODE_DEBUG_NATIVE: 'diagnostics'
|
|
};
|
|
|
|
{
|
|
console.log('\nTesting limit = 1');
|
|
tmpdir.refresh();
|
|
const child = spawnSync(process.execPath, [
|
|
'--trace-gc',
|
|
'--heapsnapshot-near-heap-limit=1',
|
|
'--max-old-space-size=50',
|
|
fixtures.path('workload', 'bounded.js')
|
|
], {
|
|
cwd: tmpdir.path,
|
|
env,
|
|
});
|
|
console.log(child.stdout.toString());
|
|
console.log(child.stderr.toString());
|
|
assert.strictEqual(child.signal, null);
|
|
assert.strictEqual(child.status, 0);
|
|
const list = fs.readdirSync(tmpdir.path)
|
|
.filter((file) => file.endsWith('.heapsnapshot'));
|
|
assert.strictEqual(list.length, 0);
|
|
}
|