Lines
100.00%
8 / 8
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| LatencyHistogram | 100.00% | 8 / 8 | 100.00% | 2 / 2 | 5 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| quantileBoundMs | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Control\Protocol\Status; | |
| 6 | ||
| 7 | use Stewart\Contracts\Time\Duration; | |
| 8 | use Stewart\Contracts\Wire\ListOf; | |
| 9 | ||
| 10 | final readonly class LatencyHistogram | |
| 11 | { | |
| 12 | /** | |
| 13 | * @param list<int> $boundsMs | |
| 14 | * @param list<int> $cumulativeCounts | |
| 15 | */ | |
| 16 | public function __construct( | |
| 17 | #[ListOf('int')] | |
| 18 | public array $boundsMs, | |
| 19 | #[ListOf('int')] | |
| 20 | public array $cumulativeCounts, | |
| 21 | public int $count, | |
| 22 | public Duration $sum, | |
| 23 | ) {} | |
| 24 | ||
| 25 | public function quantileBoundMs(float $quantile): ?int | |
| 26 | { | |
| 27 | if ($this->count === 0) { | |
| 28 | return null; | |
| 29 | } | |
| 30 | ||
| 31 | $rank = $quantile * $this->count; | |
| 32 | ||
| 33 | foreach ($this->boundsMs as $index => $bound) { | |
| 34 | if ($this->cumulativeCounts[$index] >= $rank) { | |
| 35 | return $bound; | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | return null; | |
| 40 | } | |
| 41 | } |