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: https://github.com/nodejs/node/issues/26401#issuecomment-597438516

PR-URL: https://github.com/nodejs/node/pull/32190
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Harshitha KP 2020-03-11 01:41:54 -04:00 committed by Anna Henningsen
parent 5e05f8ac09
commit bffc9324a1
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9

View File

@ -11,6 +11,7 @@ const { spawnSync } = require('child_process');
// Refs: https://github.com/nodejs/node/issues/24016
if (process.argv[2] === 'child') {
const fs = require('fs');
let files = fs.readdirSync(tmpdir.path);
const plog = files.filter((name) => /\.log$/.test(name))[0];
if (plog === undefined) {
@ -19,20 +20,20 @@ if (process.argv[2] === 'child') {
}
const pingpong = `
let counter = 0;
const fs = require('fs');
const { Worker, parentPort } = require('worker_threads');
parentPort.on('message', (m) => {
if (counter++ === 1024)
if (counter++ === 10)
process.exit(0);
parentPort.postMessage(
m.toString().split('').reverse().toString().replace(/,/g, ''));
fs.readFileSync(m.toString()).slice(0, 1024 * 1024));
});
`;
const { Worker } = require('worker_threads');
const data = 'x'.repeat(1024);
const w = new Worker(pingpong, { eval: true });
w.on('message', (m) => {
w.postMessage(m.toString().split('').reverse().toString().replace(/,/g, ''));
w.postMessage(process.execPath);
});
w.on('exit', common.mustCall(() => {
@ -45,7 +46,7 @@ if (process.argv[2] === 'child') {
}
process.exit(0);
}));
w.postMessage(data);
w.postMessage(process.execPath);
} else {
tmpdir.refresh();
const spawnResult = spawnSync(