utils

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 5 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

Rendered for windows/amd64

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToFloat

func BoolToFloat(b bool) float64

func CompileAnchored added in v0.32.0

func CompileAnchored(expr string) (*regexp.Regexp, error)

CompileAnchored compiles expr, so that it must match the whole input.

func IsMatchAll added in v0.32.0

func IsMatchAll(re *regexp.Regexp) bool

IsMatchAll reports whether re is an include filter that matches every name: the default of an include flag, types.RegExpAny or nil, which the New function of a collector replaces with the default.

func IsMatchNone added in v0.32.0

func IsMatchNone(re *regexp.Regexp) bool

IsMatchNone reports whether re is an exclude filter that matches no name: the default of an exclude flag, types.RegExpEmpty or nil, which the New function of a collector replaces with the default.

func MBToBytes

func MBToBytes(mb float64) float64

func MilliSecToSec

func MilliSecToSec(t float64) float64

func Must

func Must[T any](v T, err error) T

Must panics if the error is not nil.

func MustCompileAnchored added in v0.32.0

func MustCompileAnchored(expr string) *regexp.Regexp

MustCompileAnchored is like CompileAnchored, but panics if expr can't be parsed.

func PercentageToRatio

func PercentageToRatio(percentage float64) float64

func RegexpFlag added in v0.32.0

func RegexpFlag(app *kingpin.Application, name, help, defaultValue string, target **regexp.Regexp) *kingpin.FlagClause

RegexpFlag registers the flag name, whose value is a regular expression that must match the whole name. The compiled expression is stored in target when the flags are parsed, including the default and a value from the configuration file. An invalid expression fails the parsing with an error that starts with the name of the flag.

func SplitError

func SplitError(err error) []error

SplitError returns a slice of errors from the given error. It reverses the errors.Join function.

Types

type Counter

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

func NewCounter

func NewCounter(lastValue uint32) Counter

NewCounter creates a new Counter that accepts uint32 values and returns float64 values. It resolve the overflow issue of uint32 by using the difference between the last value and the current value.

func (*Counter) AddValue

func (c *Counter) AddValue(value uint32)

func (*Counter) Value

func (c *Counter) Value() float64

type Counter32 added in v0.32.0

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

Counter32 extends a raw 32-bit performance counter, such as a PERF_COUNTER_COUNTER or the numerator of a PERF_AVERAGE_TIMER, beyond 2^32. Unlike Counter, it starts at the raw value and follows a restart of the source, so its value equals the raw value until the first wrap. It can only detect one wrap between two samples.

func NewCounter32 added in v0.32.0

func NewCounter32(value float64, restartBelow uint32) Counter32

NewCounter32 creates a Counter32 from the first raw value. If restartBelow is not zero, a decrease from a raw value below restartBelow is taken as a restart of the source instead of a wrap. Use it for counters that cannot grow by 2^32-restartBelow between two samples, such as request counts.

func (*Counter32) Update added in v0.32.0

func (c *Counter32) Update(value float64, reset bool) float64

Update adds a raw value and returns the extended value. reset reports that the source restarted, for example because a share was reconnected; the raw value is then taken as is. Any other decrease is a wrap, unless it starts below restartBelow.

Directories

Path Synopsis
Package recovery runs functions in a way that a panic is returned as an error instead of terminating the process.
Package recovery runs functions in a way that a panic is returned as an error instead of terminating the process.

Jump to

Keyboard shortcuts

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