Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ jobs:
cd e2e/bug-14036
composer install
../../bin/phpstan analyze
- script: |
cd e2e/vvv-with-debug
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv --debug test.php 2>&1)
echo "$OUTPUT"
../bashunit -a contains '# of spawned processes: 1' "$OUTPUT"
Comment thread
esthezia marked this conversation as resolved.
Outdated
- script: |
cd e2e/vvv-with-debug
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv --debug --configuration parallel.neon test.php 2>&1)
echo "$OUTPUT"
../bashunit -a contains '# of spawned processes: 1' "$OUTPUT"

steps:
- name: Harden the runner (Audit all outbound calls)
Expand Down
3 changes: 3 additions & 0 deletions e2e/vvv-with-debug/parallel.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
parallel:
maximumNumberOfProcesses: 2
1 change: 1 addition & 0 deletions e2e/vvv-with-debug/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
2 changes: 1 addition & 1 deletion src/Command/AnalyserRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function runAnalyser(
);
}

$schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files);
$schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files, $debug);
$mainScript = null;
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
$mainScript = $_SERVER['argv'][0];
Expand Down
2 changes: 1 addition & 1 deletion src/Command/FixerWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private function runAnalyser(LoopInterface $loop, Container $container, array $f
/** @var CpuCoreCounter $cpuCoreCounter */
$cpuCoreCounter = $container->getByType(CpuCoreCounter::class);

$schedule = $scheduler->scheduleWork($cpuCoreCounter->getNumberOfCpuCores(), $files);
$schedule = $scheduler->scheduleWork($cpuCoreCounter->getNumberOfCpuCores(), $files, false);
$mainScript = null;
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
$mainScript = $_SERVER['argv'][0];
Expand Down
3 changes: 2 additions & 1 deletion src/Parallel/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ public function __construct(
public function scheduleWork(
int $cpuCores,
array $files,
bool $debug = false,
): Schedule
{
$jobs = array_chunk($files, $this->jobSize);
$numberOfProcesses = min(
$numberOfProcesses = $debug ? 1 : min(
max((int) floor(count($jobs) / $this->minimumNumberOfJobsPerProcess), 1),
$cpuCores,
);
Expand Down
13 changes: 12 additions & 1 deletion tests/PHPStan/Parallel/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static function dataSchedule(): array
1,
[1],
],
[
16,
16,
2,
20,
100,
1,
[20, 20, 20, 20, 20],
true,
],
];
}

Expand All @@ -87,11 +97,12 @@ public function testSchedule(
int $numberOfFiles,
int $expectedNumberOfProcesses,
array $expectedJobSizes,
bool $debug = false,
): void
{
$files = array_fill(0, $numberOfFiles, 'file.php');
$scheduler = new Scheduler($jobSize, $maximumNumberOfProcesses, $minimumNumberOfJobsPerProcess);
$schedule = $scheduler->scheduleWork($cpuCores, $files);
$schedule = $scheduler->scheduleWork($cpuCores, $files, $debug);

$this->assertSame($expectedNumberOfProcesses, $schedule->getNumberOfProcesses());
$jobSizes = array_map(static fn (array $job): int => count($job), $schedule->getJobs());
Expand Down
Loading