stopwatch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package stopwatch helps measuring execution times of Go applications. It measures the times of wanted code sections and calculates minimum, maximum, average and total values.

Individual stopwatches can be created via New and a namespace. They are automatically registered at a backend for the global retrieval. The measuring points got individual identifiers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, r *Registry) context.Context

NewContext creates a context containing a Registry.

Types

type Handler

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

Handler implements the http.Handler.

func NewHandler

func NewHandler(r *Registry) Handler

NewHandler returns an instance of a web handler for the stopwatch.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the handling function.

type Measurement

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

Measurement contains one single measurement.

func (*Measurement) Stop

func (m *Measurement) Stop()

Stop ends the measurement and enques its duration.

type MeteringPoint

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

MeteringPoint collects the measurements of one code section.

func (*MeteringPoint) Measure

func (mp *MeteringPoint) Measure(f func())

Measure is a convenience function to measure one anonymous function.

func (*MeteringPoint) Start

func (mp *MeteringPoint) Start() Measurement

Start begins a new measurement.

func (*MeteringPoint) Value

func (mp *MeteringPoint) Value() MeteringPointValue

Value returns the current value after an accumulation.

type MeteringPointValue

type MeteringPointValue struct {
	Namespace string        `json:"namespace"`
	ID        string        `json:"id"`
	Quantity  int           `json:"quantity"`
	Total     time.Duration `json:"total"`
	Minimum   time.Duration `json:"minimum"`
	Maximum   time.Duration `json:"maximum"`
	Average   time.Duration `json:"average"`
}

MeteringPointValue contains the accumulated value of one metering point.

func (MeteringPointValue) String

func (mpv MeteringPointValue) String() string

String implements the fmt.Stringer interface.

type MeteringPointValues

type MeteringPointValues []MeteringPointValue

MeteringPointValues contains a set of accumulated metering point values.

type Registry

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

Registry is the register type for all Stopwatches.

func FromContext

func FromContext(ctx context.Context) (*Registry, bool)

FromContext retrieves a Registry from a context.

func New

func New() *Registry

New returns a registry for Stopwatches.

func (*Registry) ForNamespace

func (r *Registry) ForNamespace(namespace string) *Stopwatch

ForNamespace creates an instance of a Stopwatch with the given namespace. In case that namespace is already in use that Stopwatch will be returned.

func (*Registry) Reset

func (r *Registry) Reset()

Reset clears all stopwatches.

func (*Registry) Values

func (r *Registry) Values() MeteringPointValues

Values returns the values of all metering points.

type Stopwatch

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

Stopwatch allows to measure the execution time at multiple reading points in one namespace.

func (*Stopwatch) MeteringPoint

func (sw *Stopwatch) MeteringPoint(id string) *MeteringPoint

MeteringPoint returns a new or already existing metering point with the given ID.

func (*Stopwatch) Values

func (sw *Stopwatch) Values() MeteringPointValues

Values returns the accumulated metering point values of this stopwatch.

Jump to

Keyboard shortcuts

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