Lines
100.00%
8 / 8
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| quantileBoundMs | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 4 | ||
| 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 | } |