|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the sj-i/php-profiler package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) sji <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace PhpProfiler\Inspector\Daemon\Dispatcher; |
|
15
|
|
|
|
|
16
|
|
|
use Amp\Promise; |
|
|
|
|
|
|
17
|
|
|
use PhpProfiler\Inspector\Daemon\Reader\Context\PhpReaderContextCreatorInterface; |
|
18
|
|
|
use PhpProfiler\Inspector\Daemon\Reader\Controller\PhpReaderControllerInterface; |
|
19
|
|
|
use PhpProfiler\Inspector\Settings\GetTraceSettings\GetTraceSettings; |
|
20
|
|
|
use PhpProfiler\Inspector\Settings\TargetPhpSettings\TargetPhpSettings; |
|
21
|
|
|
use PhpProfiler\Inspector\Settings\TraceLoopSettings\TraceLoopSettings; |
|
22
|
|
|
|
|
23
|
|
|
final class WorkerPool implements WorkerPoolInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var array<int, PhpReaderControllerInterface> */ |
|
26
|
|
|
private array $contexts; |
|
27
|
|
|
|
|
28
|
|
|
/** @var array<int, bool> */ |
|
29
|
|
|
private array $is_free_list; |
|
30
|
|
|
|
|
31
|
|
|
/** @var array<int, bool> */ |
|
32
|
|
|
private array $on_read_list; |
|
33
|
|
|
|
|
34
|
|
|
/** @no-named-arguments */ |
|
35
|
|
|
public function __construct(PhpReaderControllerInterface ...$contexts) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->contexts = $contexts; |
|
38
|
|
|
$this->is_free_list = array_fill(0, count($contexts), true); |
|
39
|
|
|
$this->on_read_list = array_fill(0, count($contexts), false); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function create( |
|
43
|
|
|
PhpReaderContextCreatorInterface $creator, |
|
44
|
|
|
int $number, |
|
45
|
|
|
TargetPhpSettings $target_php_settings, |
|
46
|
|
|
TraceLoopSettings $loop_settings, |
|
47
|
|
|
GetTraceSettings $get_trace_settings |
|
48
|
|
|
): self { |
|
49
|
|
|
$contexts = []; |
|
50
|
|
|
$started = []; |
|
51
|
|
|
for ($i = 0; $i < $number; $i++) { |
|
52
|
|
|
$context = $creator->create(); |
|
53
|
|
|
$started[] = $context->start(); |
|
54
|
|
|
$contexts[] = $context; |
|
55
|
|
|
} |
|
56
|
|
|
Promise\wait(Promise\all($started)); |
|
|
|
|
|
|
57
|
|
|
$send_settings = []; |
|
58
|
|
|
for ($i = 0; $i < $number; $i++) { |
|
59
|
|
|
$send_settings[] = $contexts[$i]->sendSettings( |
|
60
|
|
|
$target_php_settings, |
|
61
|
|
|
$loop_settings, |
|
62
|
|
|
$get_trace_settings |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
Promise\wait(Promise\all($send_settings)); |
|
66
|
|
|
|
|
67
|
|
|
return new self(...$contexts); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getFreeWorker(): ?PhpReaderControllerInterface |
|
71
|
|
|
{ |
|
72
|
|
|
foreach ($this->contexts as $key => $context) { |
|
73
|
|
|
if ($this->is_free_list[$key]) { |
|
74
|
|
|
$this->is_free_list[$key] = false; |
|
75
|
|
|
return $context; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
return null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return iterable<int, PhpReaderControllerInterface> |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getWorkers(): iterable |
|
85
|
|
|
{ |
|
86
|
|
|
foreach ($this->contexts as $key => $context) { |
|
87
|
|
|
yield $key => $context; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function returnWorkerToPool(PhpReaderControllerInterface $context_to_return): void |
|
92
|
|
|
{ |
|
93
|
|
|
foreach ($this->contexts as $key => $context) { |
|
94
|
|
|
if ($context === $context_to_return) { |
|
95
|
|
|
$this->is_free_list[$key] = true; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function debugDump(): array |
|
101
|
|
|
{ |
|
102
|
|
|
return [ |
|
103
|
|
|
'all' => array_keys($this->contexts), |
|
104
|
|
|
'is_free_list' => $this->is_free_list, |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths