loadavg

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: BSD-3-Clause Imports: 9 Imported by: 2 modules, 3 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 loadavg reads the host's 1-minute load average and waits for it to drop, so that a benchmark is not measured on a busy machine.

Linux reads /proc/loadavg (proc(5)). Darwin reads sysctl vm.loadavg, a struct loadavg { fixpt_t ldavg[3]; long fscale; } (xnu sys/resource.h). Every other platform gets a clear error, never a zero.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("load average above the limit")

ErrBusy is wrapped by the error Wait returns when the load stayed above the limit for the whole timeout.

Functions

func Avg1

func Avg1() (float64, error)

Avg1 returns the 1-minute load average.

func Wait

func Wait(ctx context.Context, max float64, timeout, poll time.Duration, onWait func(float64)) (float64, error)

Wait returns the current 1-minute load once it is at most max. With a zero timeout it checks once. Otherwise it polls every poll until timeout has elapsed, then gives up with an error wrapping ErrBusy. onWait, when not nil, is called with each reading that is too high before sleeping.

func WaitFunc

func WaitFunc(ctx context.Context, read func() (float64, error), max float64, timeout, poll time.Duration, onWait func(float64)) (float64, error)

WaitFunc is Wait over a replaceable source of readings.

Types

This section is empty.

Jump to

Keyboard shortcuts

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