timing

package
v0.43.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

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.

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

Index

Examples

Constants

View Source
const AutoreportInterval = 10 * time.Second

AutoreportInterval specifies the interval at which the default set reports.

Variables

This section is empty.

Functions

func Since

func Since(name string, start time.Time)

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.

func Stop

func Stop()

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.

Types

type Set

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

Set represents a set of metrics that can be used for timing. Use NewSet to initialize a new Set. Use Report (or Autoreport) to submit metrics. Set is safe for concurrent use.

func NewSet

func NewSet() *Set

NewSet returns a new, ready to use Set.

func (*Set) Autoreport

func (s *Set) Autoreport(interval time.Duration) (cancelFunc func())

Autoreport enables autoreporting of the Set at the given interval. It returns a cancellation function.

func (*Set) Report

func (s *Set) Report()

Report reports all of the Set's metrics to the statsd client.

func (*Set) Since

func (s *Set) Since(name string, start time.Time)

Since records the duration for the given metric name as *time passed since start*. If name does not exist, as defined by NewSet, it creates it.

Jump to

Keyboard shortcuts

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