Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fbf6dd5

Browse filesBrowse files
addaleaxrvagg
authored andcommitted
test,inspector: add heap allocation tracker test
This provides coverage for the `InspectorTimer` instances created as part of heap allocation tracking. PR-URL: #26089 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8881c0b commit fbf6dd5
Copy full SHA for fbf6dd5

File tree

Expand file treeCollapse file tree

1 file changed

+46
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+46
-0
lines changed
Open diff view settings
Collapse file
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
common.skipIfInspectorDisabled();
5+
6+
const assert = require('assert');
7+
const inspector = require('inspector');
8+
const stream = require('stream');
9+
const { Worker, workerData } = require('worker_threads');
10+
11+
const session = new inspector.Session();
12+
session.connect();
13+
session.post('HeapProfiler.enable');
14+
session.post('HeapProfiler.startTrackingHeapObjects',
15+
{ trackAllocations: true });
16+
17+
// Perform some silly heap allocations for the next 100 ms.
18+
const interval = setInterval(() => {
19+
new stream.PassThrough().end('abc').on('data', common.mustCall());
20+
}, 1);
21+
22+
setTimeout(() => {
23+
clearInterval(interval);
24+
25+
// Once the main test is done, we re-run it from inside a Worker thread
26+
// and stop early, as that is a good way to make sure the timer handles
27+
// internally created by the inspector are cleaned up properly.
28+
if (workerData === 'stopEarly')
29+
process.exit();
30+
31+
let data = '';
32+
session.on('HeapProfiler.addHeapSnapshotChunk',
33+
common.mustCallAtLeast((event) => {
34+
data += event.params.chunk;
35+
}));
36+
37+
// TODO(addaleax): Using `{ reportProgress: true }` crashes the process
38+
// because the progress indication event would mean calling into JS while
39+
// a heap snapshot is being taken, which is forbidden.
40+
// What can we do about that?
41+
session.post('HeapProfiler.stopTrackingHeapObjects');
42+
43+
assert(data.includes('PassThrough'), data);
44+
45+
new Worker(__filename, { workerData: 'stopEarly' });
46+
}, 100);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.