Skip to content

Commit 8c5ee83

Browse files
committed
Debugging messages for parallel analysis
1 parent 4d81b68 commit 8c5ee83

File tree

5 files changed

+28
-10
lines changed

5 files changed

+28
-10
lines changed

src/Command/AnalyseApplication.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private function runAnalyser(
189189
$postFileCallback = null;
190190
}
191191

192-
$analyserResult = $this->analyserRunner->runAnalyser($files, $allAnalysedFiles, $preFileCallback, $postFileCallback, $debug, true, $projectConfigFile, null, null, $input);
192+
$analyserResult = $this->analyserRunner->runAnalyser($files, $allAnalysedFiles, $preFileCallback, $postFileCallback, $debug, true, $projectConfigFile, null, null, $input, $errorOutput);
193193

194194
if (isset($progressStarted) && $progressStarted) {
195195
$errorOutput->getStyle()->progressFinish();

src/Command/AnalyserRunner.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function runAnalyser(
5757
?string $projectConfigFile,
5858
?string $tmpFile,
5959
?string $insteadOfFile,
60-
InputInterface $input
60+
InputInterface $input,
61+
Output $output
6162
): AnalyserResult
6263
{
6364
$filesCount = count($files);
@@ -71,13 +72,17 @@ public function runAnalyser(
7172
$mainScript = $_SERVER['argv'][0];
7273
}
7374

75+
if ($output->isDebug()) {
76+
$output->writeLineFormatted(sprintf('Schedule: %d processes, %d jobs', $schedule->getNumberOfProcesses(), count($schedule->getJobs())));
77+
}
78+
7479
if (
7580
!$debug
7681
&& $allowParallel
7782
&& $mainScript !== null
7883
&& $schedule->getNumberOfProcesses() > 1
7984
) {
80-
return $this->parallelAnalyser->analyse($schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input);
85+
return $this->parallelAnalyser->analyse($schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input, $output);
8186
}
8287

8388
return $this->analyser->analyse(

src/Command/FixerWorkerCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
154154
$configuration,
155155
$tmpFile,
156156
$insteadOfFile,
157-
$input
157+
$input,
158+
$inceptionResult->getErrorOutput()
158159
);
159160
$result = $resultCacheManager->process(
160161
$this->switchTmpFileInAnalyserResult($intermediateAnalyserResult, $tmpFile, $insteadOfFile),

src/Parallel/ParallelAnalyser.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Nette\Utils\Random;
88
use PHPStan\Analyser\AnalyserResult;
99
use PHPStan\Analyser\Error;
10+
use PHPStan\Command\Output;
1011
use PHPStan\Dependency\ExportedNode;
1112
use PHPStan\Process\ProcessHelper;
1213
use React\EventLoop\StreamSelectLoop;
@@ -52,7 +53,8 @@ public function analyse(
5253
?string $projectConfigFile,
5354
?string $tmpFile,
5455
?string $insteadOfFile,
55-
InputInterface $input
56+
InputInterface $input,
57+
Output $errorOutput
5658
): AnalyserResult
5759
{
5860
$jobs = array_reverse($schedule->getJobs());
@@ -131,7 +133,7 @@ public function analyse(
131133
$commandOptions,
132134
$input
133135
), $loop, $this->processTimeout);
134-
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$dependencies, &$exportedNodes, &$jobs, $postFileCallback, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier): void {
136+
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$dependencies, &$exportedNodes, &$jobs, $postFileCallback, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier, $errorOutput): void {
135137
foreach ($json['errors'] as $jsonError) {
136138
if (is_string($jsonError)) {
137139
$internalErrors[] = sprintf('Internal error: %s', $jsonError);
@@ -175,14 +177,24 @@ public function analyse(
175177
}
176178

177179
if (count($jobs) === 0) {
180+
if ($errorOutput->isDebug()) {
181+
$errorOutput->writeLineFormatted(sprintf('Process %s ended successfully - no more jobs remaining.', $processIdentifier));
182+
}
178183
$this->processPool->quitProcess($processIdentifier);
179184
return;
180185
}
181186

187+
if ($errorOutput->isDebug()) {
188+
$errorOutput->writeLineFormatted(sprintf('Process %s analysis successful - queueing a new job.', $processIdentifier));
189+
}
190+
182191
$job = array_pop($jobs);
183192
$process->request(['action' => 'analyse', 'files' => $job]);
184-
}, $handleError, function ($exitCode, string $output) use (&$internalErrors, &$internalErrorsCount, $processIdentifier): void {
193+
}, $handleError, function ($exitCode, $termSignal, string $output) use (&$internalErrors, &$internalErrorsCount, $processIdentifier, $errorOutput): void {
185194
$this->processPool->tryQuitProcess($processIdentifier);
195+
if ($errorOutput->isDebug()) {
196+
$errorOutput->writeLineFormatted(sprintf('Process %s exited - exit code %s, term signal %s, output: %s', $processIdentifier, $exitCode ?? 'null', $termSignal ?? 'null', $output));
197+
}
186198
if ($exitCode === 0) {
187199
return;
188200
}

src/Parallel/Process.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(
4848
/**
4949
* @param callable(mixed[] $json) : void $onData
5050
* @param callable(\Throwable $exception) : void $onError
51-
* @param callable(?int $exitCode, string $output) : void $onExit
51+
* @param callable(?int $exitCode, ?int $termSignal, string $output) : void $onExit
5252
*/
5353
public function start(callable $onData, callable $onError, callable $onExit): void
5454
{
@@ -69,7 +69,7 @@ public function start(callable $onData, callable $onError, callable $onExit): vo
6969
$this->process->start($this->loop);
7070
$this->onData = $onData;
7171
$this->onError = $onError;
72-
$this->process->on('exit', function ($exitCode) use ($onExit): void {
72+
$this->process->on('exit', function ($exitCode, $termSignal) use ($onExit): void {
7373
$this->cancelTimer();
7474

7575
$output = '';
@@ -84,7 +84,7 @@ public function start(callable $onData, callable $onError, callable $onExit): vo
8484
if (is_string($stdErr)) {
8585
$output .= $stdErr;
8686
}
87-
$onExit($exitCode, $output);
87+
$onExit($exitCode, $termSignal, $output);
8888
fclose($this->stdOut);
8989
fclose($this->stdErr);
9090
});

0 commit comments

Comments
 (0)