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()
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.
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.
Click to show internal directories.
Click to hide internal directories.