timing

package
v0.56.0-devel Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Overview

Package timing is used to aggregate timing calls within hotpaths to avoid using repeated statsd calls. The package has a default set that reports at 10 second intervals and can be used directly. If a different behaviour or reporting pattern is desired, a custom Set may be created.

Example

The most basic usage for the package is timing the execution time of a function.

reporter := New(&statsd.Client{})
reporter.Start()
computeThings := func() {
	// the easiest way is using a defer statement, which will trigger
	// when a function returns
	defer reporter.Since("compute.things", time.Now())
	// do stuff...
}
computeThings()
reporter.Stop()
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NoopReporter

type NoopReporter struct{}

NoopReporter is a no-op implementation of the Reporter interface.

func (NoopReporter) Since

func (NoopReporter) Since(_ string, _ time.Time)

Since is a no-op.

func (NoopReporter) Start

func (NoopReporter) Start()

Start is a no-op.

func (NoopReporter) Stop

func (NoopReporter) Stop()

Stop is a no-op.

type Reporter

type Reporter interface {
	// Since records the duration for the given metric name as time passed since start.
	// It uses the default set which is reported at 10 second intervals.
	Since(name string, start time.Time)

	// Start starts a background goroutine that reports the timing metrics.
	Start()

	// Stop permanently stops the default set from auto-reporting and flushes any remaining
	// metrics. It can be useful to call when the program exits to ensure everything is submitted.
	Stop()
}

Reporter represents an interface for measuring and reporting timing information.

func New

func New(statsd statsd.ClientInterface) Reporter

New returns a new Timing instance. You have to call Start to start reporting metrics.

Jump to

Keyboard shortcuts

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