Skip to content

Commit f37f425

Browse files
Use garbage collector information introduced in php/php-src#11523
1 parent de7fb9b commit f37f425

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

src/Event/Value/Telemetry/GarbageCollectorStatus.php

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,29 @@ final class GarbageCollectorStatus
2222
private readonly int $collected;
2323
private readonly int $threshold;
2424
private readonly int $roots;
25+
private readonly ?float $applicationTime;
26+
private readonly ?float $collectorTime;
27+
private readonly ?float $destructorTime;
28+
private readonly ?float $freeTime;
2529
private readonly ?bool $running;
2630
private readonly ?bool $protected;
2731
private readonly ?bool $full;
2832
private readonly ?int $bufferSize;
2933

30-
public function __construct(int $runs, int $collected, int $threshold, int $roots, ?bool $running, ?bool $protected, ?bool $full, ?int $bufferSize)
34+
public function __construct(int $runs, int $collected, int $threshold, int $roots, ?float $applicationTime, ?float $collectorTime, ?float $destructorTime, ?float $freeTime, ?bool $running, ?bool $protected, ?bool $full, ?int $bufferSize)
3135
{
32-
$this->runs = $runs;
33-
$this->collected = $collected;
34-
$this->threshold = $threshold;
35-
$this->roots = $roots;
36-
$this->running = $running;
37-
$this->protected = $protected;
38-
$this->full = $full;
39-
$this->bufferSize = $bufferSize;
36+
$this->runs = $runs;
37+
$this->collected = $collected;
38+
$this->threshold = $threshold;
39+
$this->roots = $roots;
40+
$this->applicationTime = $applicationTime;
41+
$this->collectorTime = $collectorTime;
42+
$this->destructorTime = $destructorTime;
43+
$this->freeTime = $freeTime;
44+
$this->running = $running;
45+
$this->protected = $protected;
46+
$this->full = $full;
47+
$this->bufferSize = $bufferSize;
4048
}
4149

4250
public function runs(): int
@@ -60,6 +68,10 @@ public function roots(): int
6068
}
6169

6270
/**
71+
* @psalm-assert-if-true !null $this->applicationTime
72+
* @psalm-assert-if-true !null $this->collectorTime
73+
* @psalm-assert-if-true !null $this->destructorTime
74+
* @psalm-assert-if-true !null $this->freeTime
6375
* @psalm-assert-if-true !null $this->running
6476
* @psalm-assert-if-true !null $this->protected
6577
* @psalm-assert-if-true !null $this->full
@@ -70,6 +82,54 @@ public function hasExtendedInformation(): bool
7082
return $this->running !== null;
7183
}
7284

85+
/**
86+
* @throws RuntimeException on PHP < 8.3
87+
*/
88+
public function applicationTime(): float
89+
{
90+
if ($this->applicationTime === null) {
91+
throw new RuntimeException('Information not available');
92+
}
93+
94+
return $this->applicationTime;
95+
}
96+
97+
/**
98+
* @throws RuntimeException on PHP < 8.3
99+
*/
100+
public function collectorTime(): float
101+
{
102+
if ($this->collectorTime === null) {
103+
throw new RuntimeException('Information not available');
104+
}
105+
106+
return $this->collectorTime;
107+
}
108+
109+
/**
110+
* @throws RuntimeException on PHP < 8.3
111+
*/
112+
public function destructorTime(): float
113+
{
114+
if ($this->destructorTime === null) {
115+
throw new RuntimeException('Information not available');
116+
}
117+
118+
return $this->destructorTime;
119+
}
120+
121+
/**
122+
* @throws RuntimeException on PHP < 8.3
123+
*/
124+
public function freeTime(): float
125+
{
126+
if ($this->freeTime === null) {
127+
throw new RuntimeException('Information not available');
128+
}
129+
130+
return $this->freeTime;
131+
}
132+
73133
/**
74134
* @throws RuntimeException on PHP < 8.3
75135
*/

src/Event/Value/Telemetry/Php83GarbageCollectorStatusProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public function status(): GarbageCollectorStatus
2525
$status['collected'],
2626
$status['threshold'],
2727
$status['roots'],
28+
$status['application_time'],
29+
$status['collector_time'],
30+
$status['destructor_time'],
31+
$status['free_time'],
2832
$status['running'],
2933
$status['protected'],
3034
$status['full'],

0 commit comments

Comments
 (0)