|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 |
| -const { fork } = require('child_process'); |
| 3 | +const { spawn, fork } = require('child_process'); |
4 | 4 | const { inspect } = require('util');
|
5 | 5 | const path = require('path');
|
6 | 6 | const CLI = require('./_cli.js');
|
@@ -40,6 +40,12 @@ if (benchmarks.length === 0) {
|
40 | 40 | return;
|
41 | 41 | }
|
42 | 42 |
|
| 43 | +const cpuCoreSetting = cli.optional.set.find(s => s.startsWith('CPUCORE=')); |
| 44 | +let cpuCore = null; |
| 45 | +if (cpuCoreSetting) { |
| 46 | + cpuCore = cpuCoreSetting.split('=')[1]; |
| 47 | +} |
| 48 | + |
43 | 49 | // Create queue from the benchmarks list such both node versions are tested
|
44 | 50 | // `runs` amount of times each.
|
45 | 51 | // Note: BenchmarkProgress relies on this order to estimate
|
@@ -70,9 +76,23 @@ if (showProgress) {
|
70 | 76 | (function recursive(i) {
|
71 | 77 | const job = queue[i];
|
72 | 78 |
|
73 |
| - const child = fork(path.resolve(__dirname, job.filename), cli.optional.set, { |
74 |
| - execPath: cli.optional[job.binary], |
75 |
| - }); |
| 79 | + const resolvedPath = path.resolve(__dirname, job.filename); |
| 80 | + let child; |
| 81 | + if (cpuCore !== null) { |
| 82 | + const spawnArgs = ['-c', cpuCore, cli.optional[job.binary], resolvedPath, ...cli.optional.set]; |
| 83 | + child = spawn('taskset', spawnArgs, { |
| 84 | + env: process.env, |
| 85 | + stdio: ['inherit', 'pipe', 'ipc'], |
| 86 | + }); |
| 87 | + |
| 88 | + child.stdout.on('data', (data) => { |
| 89 | + process.stdout.write(data); |
| 90 | + }); |
| 91 | + } else { |
| 92 | + child = fork(resolvedPath, cli.optional.set, { |
| 93 | + execPath: cli.optional[job.binary], |
| 94 | + }); |
| 95 | + } |
76 | 96 |
|
77 | 97 | child.on('message', (data) => {
|
78 | 98 | if (data.type === 'report') {
|
|
0 commit comments