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 ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements the http.Handler.
func NewHandler ¶
NewHandler returns an instance of a web handler for the stopwatch.
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 ¶
FromContext retrieves a Registry from a context.
func (*Registry) ForNamespace ¶
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) 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.