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 | ||
| fromLatencyHistogram | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 3 | ||
| 11 | final readonly class Histogram | |
| 12 | { | |
| 13 | /** @param list<HistogramBucket> $buckets */ | |
| 14 | public function __construct( | |
| 15 | public array $buckets, | |
| 16 | public int $count, | |
| 17 | public Duration $sum, | |
| 18 | ) {} | |
| 19 | ||
| 20 | public static function fromLatencyHistogram(LatencyHistogram $latency): self | |
| 21 | { | |
| 22 | if (\count($latency->boundsMs) !== \count($latency->cumulativeCounts)) { | |
| 23 | throw new LogicException(\sprintf('A latency histogram has %d bounds but %d counts.', \count($latency->boundsMs), \count($latency->cumulativeCounts))); | |
| 24 | } | |
| 25 | ||
| 26 | $buckets = []; | |
| 27 | ||
| 28 | foreach ($latency->boundsMs as $index => $bound) { | |
| 29 | $buckets[] = new HistogramBucket(Duration::milliseconds($bound)->toSeconds(), $latency->cumulativeCounts[$index]); | |
| 30 | } | |
| 31 | ||
| 32 | $buckets[] = new HistogramBucket(INF, $latency->count); | |
| 33 | ||
| 34 | return new self($buckets, $latency->count, $latency->sum); | |
| 35 | } | |
| 36 | } |