|
2 | 2 |
|
3 | 3 | namespace PHPStan\Parallel;
|
4 | 4 |
|
| 5 | +use PHPStan\Command\Output; |
| 6 | +use PHPStan\Diagnose\DiagnoseExtension; |
5 | 7 | use function array_chunk;
|
6 | 8 | use function count;
|
7 | 9 | use function floor;
|
8 | 10 | use function max;
|
9 | 11 | use function min;
|
| 12 | +use function sprintf; |
10 | 13 |
|
11 |
| -class Scheduler |
| 14 | +class Scheduler implements DiagnoseExtension |
12 | 15 | {
|
13 | 16 |
|
| 17 | + /** @var array{int, int, int, int}|null */ |
| 18 | + private ?array $storedData = null; |
| 19 | + |
14 | 20 | /**
|
15 | 21 | * @param positive-int $jobSize
|
16 | 22 | * @param positive-int $maximumNumberOfProcesses
|
@@ -38,7 +44,31 @@ public function scheduleWork(
|
38 | 44 | $cpuCores,
|
39 | 45 | );
|
40 | 46 |
|
41 |
| - return new Schedule(min($numberOfProcesses, $this->maximumNumberOfProcesses), $jobs); |
| 47 | + $usedNumberOfProcesses = min($numberOfProcesses, $this->maximumNumberOfProcesses); |
| 48 | + $this->storedData = [$cpuCores, count($files), count($jobs), $usedNumberOfProcesses]; |
| 49 | + |
| 50 | + return new Schedule($usedNumberOfProcesses, $jobs); |
| 51 | + } |
| 52 | + |
| 53 | + public function print(Output $output): void |
| 54 | + { |
| 55 | + if ($this->storedData === null) { |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + [$cpuCores, $filesCount, $jobsCount, $usedNumberOfProcesses] = $this->storedData; |
| 60 | + |
| 61 | + $output->writeLineFormatted('<info>Parallel processing scheduler:</info>'); |
| 62 | + $output->writeLineFormatted(sprintf( |
| 63 | + '# of detected CPU %s: %s%d', |
| 64 | + $cpuCores === 1 ? 'core' : 'cores', |
| 65 | + $cpuCores === 1 ? '' : ' ', |
| 66 | + $cpuCores, |
| 67 | + )); |
| 68 | + $output->writeLineFormatted(sprintf('# of analysed files: %d', $filesCount)); |
| 69 | + $output->writeLineFormatted(sprintf('# of jobs: %d', $jobsCount)); |
| 70 | + $output->writeLineFormatted(sprintf('# of spawned processes: %d', $usedNumberOfProcesses)); |
| 71 | + $output->writeLineFormatted(''); |
42 | 72 | }
|
43 | 73 |
|
44 | 74 | }
|
0 commit comments