Skip to content

Commit 73fec7c

Browse files
HarshithaKPaddaleax
authored andcommitted
test: harden the tick sampling logic
Under peculiar system load conditions, the profiler thread does not get enough CPU slices to perform the sampling. Improve the interaction between worker and parent thread by performing a large disc read, which is a better blend of CPU and I/O bound work, than earlier versions. This produces x10 more samples than the existing one, in 10 iterations, as opposed to 1024. Also capture worker error situations to improve debugging Refs: #26401 (comment) PR-URL: #32190 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2ee684a commit 73fec7c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

test/sequential/test-worker-prof.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { spawnSync } = require('child_process');
1111
// Refs: https://github.com/nodejs/node/issues/24016
1212

1313
if (process.argv[2] === 'child') {
14+
const fs = require('fs');
1415
let files = fs.readdirSync(tmpdir.path);
1516
const plog = files.filter((name) => /\.log$/.test(name))[0];
1617
if (plog === undefined) {
@@ -19,20 +20,20 @@ if (process.argv[2] === 'child') {
1920
}
2021
const pingpong = `
2122
let counter = 0;
23+
const fs = require('fs');
2224
const { Worker, parentPort } = require('worker_threads');
2325
parentPort.on('message', (m) => {
24-
if (counter++ === 1024)
26+
if (counter++ === 10)
2527
process.exit(0);
2628
parentPort.postMessage(
27-
m.toString().split('').reverse().toString().replace(/,/g, ''));
29+
fs.readFileSync(m.toString()).slice(0, 1024 * 1024));
2830
});
2931
`;
3032

3133
const { Worker } = require('worker_threads');
32-
const data = 'x'.repeat(1024);
3334
const w = new Worker(pingpong, { eval: true });
3435
w.on('message', (m) => {
35-
w.postMessage(m.toString().split('').reverse().toString().replace(/,/g, ''));
36+
w.postMessage(process.execPath);
3637
});
3738

3839
w.on('exit', common.mustCall(() => {
@@ -45,7 +46,7 @@ if (process.argv[2] === 'child') {
4546
}
4647
process.exit(0);
4748
}));
48-
w.postMessage(data);
49+
w.postMessage(process.execPath);
4950
} else {
5051
tmpdir.refresh();
5152
const spawnResult = spawnSync(

0 commit comments

Comments
 (0)