Skip to content

Commit c7c9689

Browse files
committed
Parallel scheduler becomes DiagnoseExtension
1 parent b116e71 commit c7c9689

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

conf/config.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ services:
720720
jobSize: %parallel.jobSize%
721721
maximumNumberOfProcesses: %parallel.maximumNumberOfProcesses%
722722
minimumNumberOfJobsPerProcess: %parallel.minimumNumberOfJobsPerProcess%
723+
tags:
724+
- phpstan.diagnoseExtension
723725

724726
-
725727
class: PHPStan\Parser\FunctionCallStatementFinder

src/Parallel/Scheduler.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
namespace PHPStan\Parallel;
44

5+
use PHPStan\Command\Output;
6+
use PHPStan\Diagnose\DiagnoseExtension;
57
use function array_chunk;
68
use function count;
79
use function floor;
810
use function max;
911
use function min;
12+
use function sprintf;
1013

11-
class Scheduler
14+
class Scheduler implements DiagnoseExtension
1215
{
1316

17+
/** @var array{int, int, int, int}|null */
18+
private ?array $storedData = null;
19+
1420
/**
1521
* @param positive-int $jobSize
1622
* @param positive-int $maximumNumberOfProcesses
@@ -38,7 +44,31 @@ public function scheduleWork(
3844
$cpuCores,
3945
);
4046

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('');
4272
}
4373

4474
}

0 commit comments

Comments
 (0)