Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test,inspector: add heap allocation tracker test #26089

Closed
Closed
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
46 changes: 46 additions & 0 deletions test/parallel/test-inspector-heap-allocation-tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const assert = require('assert');
const inspector = require('inspector');
const stream = require('stream');
const { Worker, workerData } = require('worker_threads');

const session = new inspector.Session();
session.connect();
session.post('HeapProfiler.enable');
session.post('HeapProfiler.startTrackingHeapObjects',
{ trackAllocations: true });

// Perform some silly heap allocations for the next 100 ms.
const interval = setInterval(() => {
new stream.PassThrough().end('abc').on('data', common.mustCall());
}, 1);

setTimeout(() => {
clearInterval(interval);

// Once the main test is done, we re-run it from inside a Worker thread
// and stop early, as that is a good way to make sure the timer handles
// internally created by the inspector are cleaned up properly.
if (workerData === 'stopEarly')
process.exit();

let data = '';
session.on('HeapProfiler.addHeapSnapshotChunk',
common.mustCallAtLeast((event) => {
data += event.params.chunk;
}));

// TODO(addaleax): Using `{ reportProgress: true }` crashes the process
// because the progress indication event would mean calling into JS while
// a heap snapshot is being taken, which is forbidden.
// What can we do about that?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, @eugeneo @nodejs/v8 any ideas for what to do about this?

session.post('HeapProfiler.stopTrackingHeapObjects');

assert(data.includes('PassThrough'), data);

new Worker(__filename, { workerData: 'stopEarly' });
}, 100);