stats

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats tracks transfer statistics (bytes, duration, bandwidth).

func New

func New() *Stats

New returns a zero-valued Stats whose time source is time.Now.

func (*Stats) AddBytes

func (s *Stats) AddBytes(count uint64)

AddBytes adds count to the running byte total.

func (*Stats) Bytes

func (s *Stats) Bytes() uint64

Bytes returns the running byte total.

func (*Stats) CurrentBandwidth

func (s *Stats) CurrentBandwidth() float64

CurrentBandwidth returns bytes/sec over an adaptive window:

window_age = min(time_since_oldest_in_window_sample, maxWindow)
rate       = (bytes_now − bytes_at_window_start) / window_age

During the first maxWindow, Stats.timeStart acts as an implicit zeroth sample at bytes=0, so the rate is meaningful from the first AddBytes call without a startup spike.

Returns 0 if not started, or past the startup window with no recent samples.

func (*Stats) Duration

func (s *Stats) Duration() time.Duration

Duration returns the active elapsed time, excluding any intervals spent paused. Returns 0 before Start. While running, measures up to "now"; after Stop, up to the stop timestamp.

func (*Stats) Pause

func (s *Stats) Pause()

Pause records an interruption timestamp. No-op if not started or already stopped.

func (*Stats) Sample

func (s *Stats) Sample()

Sample records the current byte total at "now" into the live-bandwidth ring buffer. Cheap; intended to be called on a regular tick (e.g. every 100ms by progress emitters).

func (*Stats) Start

func (s *Stats) Start()

Start records the start timestamp on the first call, or resumes a paused run. Subsequent calls while running are no-ops.

func (*Stats) Stop

func (s *Stats) Stop()

Stop records the stop timestamp. No-op if not started or already stopped.

func (*Stats) String

func (s *Stats) String() string

Jump to

Keyboard shortcuts

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