Skip to content

Commit

Permalink
Parallel scheduler becomes DiagnoseExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 15, 2024
1 parent b116e71 commit c7c9689
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ services:
jobSize: %parallel.jobSize%
maximumNumberOfProcesses: %parallel.maximumNumberOfProcesses%
minimumNumberOfJobsPerProcess: %parallel.minimumNumberOfJobsPerProcess%
tags:
- phpstan.diagnoseExtension

-
class: PHPStan\Parser\FunctionCallStatementFinder
Expand Down
34 changes: 32 additions & 2 deletions src/Parallel/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace PHPStan\Parallel;

use PHPStan\Command\Output;
use PHPStan\Diagnose\DiagnoseExtension;
use function array_chunk;
use function count;
use function floor;
use function max;
use function min;
use function sprintf;

class Scheduler
class Scheduler implements DiagnoseExtension
{

/** @var array{int, int, int, int}|null */
private ?array $storedData = null;

/**
* @param positive-int $jobSize
* @param positive-int $maximumNumberOfProcesses
Expand Down Expand Up @@ -38,7 +44,31 @@ public function scheduleWork(
$cpuCores,
);

return new Schedule(min($numberOfProcesses, $this->maximumNumberOfProcesses), $jobs);
$usedNumberOfProcesses = min($numberOfProcesses, $this->maximumNumberOfProcesses);
$this->storedData = [$cpuCores, count($files), count($jobs), $usedNumberOfProcesses];

return new Schedule($usedNumberOfProcesses, $jobs);
}

public function print(Output $output): void
{
if ($this->storedData === null) {
return;
}

[$cpuCores, $filesCount, $jobsCount, $usedNumberOfProcesses] = $this->storedData;

$output->writeLineFormatted('<info>Parallel processing scheduler:</info>');
$output->writeLineFormatted(sprintf(
'# of detected CPU %s: %s%d',
$cpuCores === 1 ? 'core' : 'cores',
$cpuCores === 1 ? '' : ' ',
$cpuCores,
));
$output->writeLineFormatted(sprintf('# of analysed files: %d', $filesCount));
$output->writeLineFormatted(sprintf('# of jobs: %d', $jobsCount));
$output->writeLineFormatted(sprintf('# of spawned processes: %d', $usedNumberOfProcesses));
$output->writeLineFormatted('');
}

}

0 comments on commit c7c9689

Please sign in to comment.