From a40e7daf3ceca3cddc208c1c82222f52762f4650 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Wed, 11 Mar 2020 01:41:54 -0400 Subject: [PATCH] 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 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- test/sequential/test-worker-prof.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/sequential/test-worker-prof.js b/test/sequential/test-worker-prof.js index 80596a76f94f66..f89ff962ff785d 100644 --- a/test/sequential/test-worker-prof.js +++ b/test/sequential/test-worker-prof.js @@ -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(