SlidingPercentileBandwidthStatistic


@UnstableApi
class SlidingPercentileBandwidthStatistic : BandwidthStatistic


A BandwidthStatistic that calculates estimates based on a sliding window weighted percentile.

Summary

Constants

const Int

The default maximum number of samples.

const Double

The default percentile to return.

Public constructors

Creates an instance with a maximum of DEFAULT_MAX_SAMPLES_COUNT samples, returning the DEFAULT_PERCENTILE.

SlidingPercentileBandwidthStatistic(
    maxSampleCount: Int,
    percentile: Double
)

Creates an instance.

Public functions

Unit
addSample(bytes: Long, durationUs: Long)

Adds a transfer sample to the statistic.

Long

Returns the bandwidth estimate in bits per second, or ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

Unit

Resets the statistic.

Constants

DEFAULT_MAX_SAMPLES_COUNT

const val DEFAULT_MAX_SAMPLES_COUNT = 10: Int

The default maximum number of samples.

DEFAULT_PERCENTILE

const val DEFAULT_PERCENTILE = 0.5: Double

The default percentile to return.

Public constructors

SlidingPercentileBandwidthStatistic

SlidingPercentileBandwidthStatistic()

Creates an instance with a maximum of DEFAULT_MAX_SAMPLES_COUNT samples, returning the DEFAULT_PERCENTILE.

SlidingPercentileBandwidthStatistic

SlidingPercentileBandwidthStatistic(
    maxSampleCount: Int,
    percentile: Double
)

Creates an instance.

Parameters
maxSampleCount: Int

The maximum number of samples.

percentile: Double

The percentile to return. Must be in the range of [0-1].

Public functions

addSample

fun addSample(bytes: Long, durationUs: Long): Unit

Adds a transfer sample to the statistic.

Parameters
bytes: Long

The number of bytes transferred.

durationUs: Long

The duration of the transfer, in microseconds.

getBandwidthEstimate

fun getBandwidthEstimate(): Long

Returns the bandwidth estimate in bits per second, or ESTIMATE_NOT_AVAILABLE if there is no estimate available yet.

reset

fun reset(): Unit

Resets the statistic. The statistic should drop all samples and reset to its initial state, similar to right after construction.