diff --git a/src/NProcFinder.php b/src/NProcFinder.php index 3a3aa25..545a12a 100644 --- a/src/NProcFinder.php +++ b/src/NProcFinder.php @@ -22,14 +22,26 @@ use const FILTER_VALIDATE_INT; /** - * The number of processing units available. Usually matches the number of - * logical cores. + * The number of (logical) cores. * * @see https://github.com/infection/infection/blob/fbd8c44/src/Resource/Processor/CpuCoresCountProvider.php#L69-L82 * @see https://unix.stackexchange.com/questions/146051/number-of-processors-in-proc-cpuinfo */ final class NProcFinder implements CpuCoreFinder { + /** + * @var bool + */ + private $all; + + /** + * @param bool $all If disabled will give the number of cores available for the current process only. + */ + public function __construct(bool $all) + { + $this->all = $all; + } + /** * @return positive-int|null */ @@ -40,7 +52,7 @@ public function find(): ?int } try { - $nproc = ShellExec::execute('nproc --all'); + $nproc = ShellExec::execute('nproc'.($this->all ? ' --all' : '')); } catch (ExecException $nprocFailed) { return null; }