Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .psalm/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@
</file>
<file src="src/Event/Value/Telemetry/Php83GarbageCollectorStatusProvider.php">
<InvalidArrayOffset>
<code><![CDATA[$status['application_time']]]></code>
<code><![CDATA[$status['buffer_size']]]></code>
<code><![CDATA[$status['collector_time']]]></code>
<code><![CDATA[$status['destructor_time']]]></code>
<code><![CDATA[$status['free_time']]]></code>
<code><![CDATA[$status['full']]]></code>
<code><![CDATA[$status['protected']]]></code>
<code><![CDATA[$status['running']]]></code>
Expand Down
78 changes: 69 additions & 9 deletions src/Event/Value/Telemetry/GarbageCollectorStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ final class GarbageCollectorStatus
private readonly int $collected;
private readonly int $threshold;
private readonly int $roots;
private readonly ?float $applicationTime;
private readonly ?float $collectorTime;
private readonly ?float $destructorTime;
private readonly ?float $freeTime;
private readonly ?bool $running;
private readonly ?bool $protected;
private readonly ?bool $full;
private readonly ?int $bufferSize;

public function __construct(int $runs, int $collected, int $threshold, int $roots, ?bool $running, ?bool $protected, ?bool $full, ?int $bufferSize)
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)
{
$this->runs = $runs;
$this->collected = $collected;
$this->threshold = $threshold;
$this->roots = $roots;
$this->running = $running;
$this->protected = $protected;
$this->full = $full;
$this->bufferSize = $bufferSize;
$this->runs = $runs;
$this->collected = $collected;
$this->threshold = $threshold;
$this->roots = $roots;
$this->applicationTime = $applicationTime;
$this->collectorTime = $collectorTime;
$this->destructorTime = $destructorTime;
$this->freeTime = $freeTime;
$this->running = $running;
$this->protected = $protected;
$this->full = $full;
$this->bufferSize = $bufferSize;
}

public function runs(): int
Expand All @@ -60,6 +68,10 @@ public function roots(): int
}

/**
* @psalm-assert-if-true !null $this->applicationTime
* @psalm-assert-if-true !null $this->collectorTime
* @psalm-assert-if-true !null $this->destructorTime
* @psalm-assert-if-true !null $this->freeTime
* @psalm-assert-if-true !null $this->running
* @psalm-assert-if-true !null $this->protected
* @psalm-assert-if-true !null $this->full
Expand All @@ -70,6 +82,54 @@ public function hasExtendedInformation(): bool
return $this->running !== null;
}

/**
* @throws RuntimeException on PHP < 8.3
*/
public function applicationTime(): float
{
if ($this->applicationTime === null) {
throw new RuntimeException('Information not available');
}

return $this->applicationTime;
}

/**
* @throws RuntimeException on PHP < 8.3
*/
public function collectorTime(): float
{
if ($this->collectorTime === null) {
throw new RuntimeException('Information not available');
}

return $this->collectorTime;
}

/**
* @throws RuntimeException on PHP < 8.3
*/
public function destructorTime(): float
{
if ($this->destructorTime === null) {
throw new RuntimeException('Information not available');
}

return $this->destructorTime;
}

/**
* @throws RuntimeException on PHP < 8.3
*/
public function freeTime(): float
{
if ($this->freeTime === null) {
throw new RuntimeException('Information not available');
}

return $this->freeTime;
}

/**
* @throws RuntimeException on PHP < 8.3
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function status(): GarbageCollectorStatus
null,
null,
null,
null,
null,
null,
null,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function status(): GarbageCollectorStatus
$status['collected'],
$status['threshold'],
$status['roots'],
$status['application_time'],
$status['collector_time'],
$status['destructor_time'],
$status['free_time'],
$status['running'],
$status['protected'],
$status['full'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Event/AbstractEventTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final protected function telemetryInfo(): Telemetry\Info
HRTime::fromSecondsAndNanoseconds(...hrtime(false)),
Telemetry\MemoryUsage::fromBytes(1000),
Telemetry\MemoryUsage::fromBytes(2000),
new Telemetry\GarbageCollectorStatus(0, 0, 0, 0, false, false, false, 0),
new Telemetry\GarbageCollectorStatus(0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, false, false, false, 0),
),
Duration::fromSecondsAndNanoseconds(123, 456),
Telemetry\MemoryUsage::fromBytes(2000),
Expand Down
32 changes: 30 additions & 2 deletions tests/unit/Event/Value/Telemetry/GarbageCollectorStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ public function testMayHaveRunning(): void
$this->assertTrue($this->withDetails()->isRunning());
}

public function testMayHaveApplicationTime(): void
{
$this->assertSame(5.0, $this->withDetails()->applicationTime());
}

public function testMayHaveCollectorTime(): void
{
$this->assertSame(6.0, $this->withDetails()->collectorTime());
}

public function testMayHaveDestructorTime(): void
{
$this->assertSame(7.0, $this->withDetails()->destructorTime());
}

public function testMayHaveFreeTime(): void
{
$this->assertSame(8.0, $this->withDetails()->freeTime());
}

public function testMayHaveProtected(): void
{
$this->assertTrue($this->withDetails()->isProtected());
Expand All @@ -60,7 +80,7 @@ public function testMayHaveFull(): void

public function testMayHaveBufferSize(): void
{
$this->assertSame(5, $this->withDetails()->bufferSize());
$this->assertSame(9, $this->withDetails()->bufferSize());
}

public function testMayNotHaveExtendedInformation(): void
Expand Down Expand Up @@ -107,6 +127,10 @@ private function withoutDetails(): GarbageCollectorStatus
null,
null,
null,
null,
null,
null,
null,
);
}

Expand All @@ -117,10 +141,14 @@ private function withDetails(): GarbageCollectorStatus
2,
3,
4,
5.0,
6.0,
7.0,
8.0,
true,
true,
true,
5,
9,
);
}
}
2 changes: 1 addition & 1 deletion tests/unit/Event/Value/Telemetry/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testConstructorSetsValues(): void
$time = HRTime::fromSecondsAndNanoseconds(...hrtime(false));
$memoryUsage = MemoryUsage::fromBytes(2000);
$peakMemoryUsage = MemoryUsage::fromBytes(3000);
$garbageCollectorStatus = new GarbageCollectorStatus(0, 0, 0, 0, false, false, false, 0);
$garbageCollectorStatus = new GarbageCollectorStatus(0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, false, false, false, 0);

$snapshot = new Snapshot(
$time,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Event/Value/Telemetry/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function peakMemoryUsage(): MemoryUsage
}
};

$garbageCollectorStatus = new GarbageCollectorStatus(0, 0, 0, 0, false, false, false, 0);
$garbageCollectorStatus = new GarbageCollectorStatus(0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, false, false, false, 0);

$garbageCollectorProvider = new class($garbageCollectorStatus) implements GarbageCollectorStatusProvider
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/TextUI/Output/Default/ResultPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ private static function telemetryInfo(): Info
HRTime::fromSecondsAndNanoseconds(...hrtime(false)),
MemoryUsage::fromBytes(1000),
MemoryUsage::fromBytes(2000),
new GarbageCollectorStatus(0, 0, 0, 0, false, false, false, 0),
new GarbageCollectorStatus(0, 0, 0, 0, 0.0, 0.0, 0.0, 0.0, false, false, false, 0),
),
Duration::fromSecondsAndNanoseconds(123, 456),
MemoryUsage::fromBytes(2000),
Expand Down