Skip to content

Commit 4820056

Browse files
committed
Removed parallel processing from output, when using '--debug'.
1 parent 0e8fb2d commit 4820056

5 files changed

Lines changed: 24 additions & 39 deletions

File tree

.github/workflows/e2e-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ jobs:
440440
cd e2e/vvv-with-debug
441441
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv --debug test.php 2>&1)
442442
echo "$OUTPUT"
443-
../bashunit -a contains '# of spawned processes: 1' "$OUTPUT"
443+
../bashunit -a not_contains 'Parallel processing scheduler' "$OUTPUT"
444444
- script: |
445445
cd e2e/vvv-with-debug
446446
OUTPUT=$(../../bin/phpstan analyze -l 0 -vvv --debug --configuration parallel.neon test.php 2>&1)
447447
echo "$OUTPUT"
448-
../bashunit -a contains '# of spawned processes: 1' "$OUTPUT"
448+
../bashunit -a not_contains 'Parallel processing scheduler' "$OUTPUT"
449449
450450
steps:
451451
- name: Harden the runner (Audit all outbound calls)

src/Command/AnalyserRunner.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,27 @@ public function runAnalyser(
7171
);
7272
}
7373

74-
$schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files, $debug);
75-
$mainScript = null;
76-
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
77-
$mainScript = $_SERVER['argv'][0];
78-
}
74+
if (!$debug && $allowParallel && function_exists('proc_open')) {
75+
$schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files);
76+
77+
$mainScript = null;
78+
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
79+
$mainScript = $_SERVER['argv'][0];
80+
}
7981

80-
if (
81-
!$debug
82-
&& $allowParallel
83-
&& function_exists('proc_open')
84-
&& $mainScript !== null
85-
&& $schedule->getNumberOfProcesses() > 0
86-
) {
87-
$loop = new StreamSelectLoop();
88-
$result = null;
89-
$promise = $this->parallelAnalyser->analyse($loop, $schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input, null);
90-
$promise->then(static function (AnalyserResult $tmp) use (&$result): void {
91-
$result = $tmp;
92-
});
93-
$loop->run();
94-
if ($result === null) {
95-
throw new ShouldNotHappenException();
82+
if (($mainScript !== null) && ($schedule->getNumberOfProcesses() > 0)) {
83+
$loop = new StreamSelectLoop();
84+
$result = null;
85+
$promise = $this->parallelAnalyser->analyse($loop, $schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input, null);
86+
$promise->then(static function (AnalyserResult $tmp) use (&$result): void {
87+
$result = $tmp;
88+
});
89+
$loop->run();
90+
if ($result === null) {
91+
throw new ShouldNotHappenException();
92+
}
93+
return $result;
9694
}
97-
return $result;
9895
}
9996

10097
return $this->analyser->analyse(

src/Command/FixerWorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ private function runAnalyser(LoopInterface $loop, Container $container, array $f
413413
/** @var CpuCoreCounter $cpuCoreCounter */
414414
$cpuCoreCounter = $container->getByType(CpuCoreCounter::class);
415415

416-
$schedule = $scheduler->scheduleWork($cpuCoreCounter->getNumberOfCpuCores(), $files, false);
416+
$schedule = $scheduler->scheduleWork($cpuCoreCounter->getNumberOfCpuCores(), $files);
417417
$mainScript = null;
418418
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
419419
$mainScript = $_SERVER['argv'][0];

src/Parallel/Scheduler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ public function __construct(
4242
public function scheduleWork(
4343
int $cpuCores,
4444
array $files,
45-
bool $debug = false,
4645
): Schedule
4746
{
4847
$jobs = array_chunk($files, $this->jobSize);
49-
$numberOfProcesses = $debug ? 1 : min(
48+
$numberOfProcesses = min(
5049
max((int) floor(count($jobs) / $this->minimumNumberOfJobsPerProcess), 1),
5150
$cpuCores,
5251
);

tests/PHPStan/Parallel/SchedulerTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ public static function dataSchedule(): array
6868
1,
6969
[1],
7070
],
71-
[
72-
16,
73-
16,
74-
2,
75-
20,
76-
100,
77-
1,
78-
[20, 20, 20, 20, 20],
79-
true,
80-
],
8171
];
8272
}
8373

@@ -97,12 +87,11 @@ public function testSchedule(
9787
int $numberOfFiles,
9888
int $expectedNumberOfProcesses,
9989
array $expectedJobSizes,
100-
bool $debug = false,
10190
): void
10291
{
10392
$files = array_fill(0, $numberOfFiles, 'file.php');
10493
$scheduler = new Scheduler($jobSize, $maximumNumberOfProcesses, $minimumNumberOfJobsPerProcess);
105-
$schedule = $scheduler->scheduleWork($cpuCores, $files, $debug);
94+
$schedule = $scheduler->scheduleWork($cpuCores, $files);
10695

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

0 commit comments

Comments
 (0)