Skip to content

Commit

Permalink
Allow to configure nproc
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Dec 7, 2022
1 parent b57c631 commit 07f1a14
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/NProcFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
Expand Down

0 comments on commit 07f1a14

Please sign in to comment.