stats

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stats provides pure analysis functions used by the aggregator and report generator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillBucketRTTStats

func FillBucketRTTStats(out *BucketSummary, rttsInTimeOrder []float64)

FillBucketRTTStats populates percentile/max/mean/jitter pointer fields from RTTs in time order. No-op when empty.

func JitterMs

func JitterMs(rttsInTimeOrder []float64) (float64, bool)

JitterMs is RFC 3550-style jitter: the mean absolute delta between consecutive RTTs in time order. This is what voice/video codecs feel; std-dev-of-all misses bursty jitter that matters for call quality. Caller orders by timestamp ascending; mixing targets gives nonsense. Returns (0, false) for fewer than 2 samples.

func Mean

func Mean(xs []float64) (float64, bool)

Mean of an unsorted slice. Returns (0, false) when empty.

func Percentile

func Percentile(sortedXs []float64, q float64) (float64, bool)

Percentile returns the value at quantile q (0..1) from a sorted slice using floor(len*q), clamped. Empty input returns (0, false).

func Round2

func Round2(v float64) float64

Round2 rounds v to two decimal places. Single definition prevents drift between probe recording and report generation.

Types

type BucketSummary

type BucketSummary struct {
	Count        int
	SuccessCount int
	FailCount    int
	P50Ms        *float64
	P95Ms        *float64
	P99Ms        *float64
	MaxMs        *float64
	MeanMs       *float64
	JitterMs     *float64
	Errors       map[string]int
}

BucketSummary is what the aggregator writes to sample_5min/sample_1h.

func Aggregate

func Aggregate(samples []SampleInput) BucketSummary

Aggregate folds a slice of samples (any order) into a BucketSummary. Stats pointer fields stay nil when there are no successful samples — that distinguishes "no signal" from "0ms latency" in the UI.

func AggregateFromBuckets

func AggregateFromBuckets(children []BucketSummary) BucketSummary

AggregateFromBuckets folds child summaries into a coarser one for the 5min→1h rollup. Counts/errors sum exactly. Percentiles and jitter use success-count-weighted means of the child values — a fidelity trade-off once raw RTTs have been pruned.

type SampleInput

type SampleInput struct {
	TSUnixMs int64
	Success  bool
	RTTMs    *float64
	Error    *string
}

SampleInput is the minimal projection of a probe Sample for aggregation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL