watch

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

Watch

Documentation

Overview

Package watch provides performance monitoring routines

Package watch provides performance monitoring routines

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Finish

func Finish(ctx context.Context) (err error)

Finish captures elapsed monitors, logs Capture info, and ends it.

func GetTrace

func GetTrace(ctx context.Context) uuid.UUID

GetTrace extracts trace id form the context.

func LogMetrics

func LogMetrics(kvp [][]string)

LogMetrics logs performance stats key/value pairs.

func TraceContext

func TraceContext(ctx context.Context) context.Context

TraceContext creates new context with trace id.

func WatcherContext

func WatcherContext(ctx context.Context, name string, options ...Optioner) (context.Context, error)

WatcherContext adds watcher to the context.

Types

type Aggregator

type Aggregator struct {
	Area     string
	Elapsed  time.Duration
	Monitors []*Monitor
}

Aggregator stores multiple monitors for the same operation.

func NewAggregator

func NewAggregator(area string) *Aggregator

NewAggregator creates new area aggregator.

func (*Aggregator) Add

func (a *Aggregator) Add(mon *Monitor)

Add appends a monitor to the aggregator.

func (*Aggregator) Aggregate

func (a *Aggregator) Aggregate() (err error)

Aggregate aggregates elapsed durations of each monitor.

type ConfigOption

type ConfigOption struct {
	ID  Option
	Val interface{}
}

ConfigOption of th capture.

func (ConfigOption) Option

func (o ConfigOption) Option() Option

Option return config option identifier.

func (ConfigOption) Value

func (o ConfigOption) Value() interface{}

Value return config option value.

type DecimalPlaces added in v0.1.4

type DecimalPlaces int

DecimalPlaces for percentage and unit values.

const (
	// DecimalPlacesAll disabled.
	DecimalPlacesAll DecimalPlaces = iota
	// DecimalPlacesOnes 1 - ones place.
	DecimalPlacesOnes
	// DecimalPlacesTenths 2 - tenths place.
	DecimalPlacesTenths
	// DecimalPlacesHundredths 3 - hundredths place.
	DecimalPlacesHundredths
	// DecimalPlacesThousandths 4 - thousandths place.
	DecimalPlacesThousandths
	// DecimalPlacesTenThousandths 5 - ten thousandths place.
	DecimalPlacesTenThousandths
	// DecimalPlacesHundredThousandths  6 - hundred thousandths place.
	DecimalPlacesHundredThousandths
	// DecimalPlacesMillions 7 - millions place.
	DecimalPlacesMillions
)

type DurationUnits

type DurationUnits int

DurationUnits of duration.

const (
	// Nanoseconds ...
	Nanoseconds DurationUnits = iota
	// Microseconds ...
	Microseconds
	// Milliseconds ...
	Milliseconds
	// Seconds ...
	Seconds
	// Minutes ...
	Minutes
	// Hours ...
	Hours
)

type LogMetricsFunc

type LogMetricsFunc func(kvp [][]string)

LogMetricsFunc defines a function to log the watch metrics.

type Monitor

type Monitor struct {
	ID   uuid.UUID
	Area string
	// contains filtered or unexported fields
}

Monitor measures elapsed time in the area.

func NewMonitor

func NewMonitor(area string, start bool) (*Monitor, error)

NewMonitor creates new operation monitor.

func Start

func Start(ctx context.Context, name string) (mon *Monitor, err error)

Start starts a new monitor.

func (*Monitor) Hours

func (m *Monitor) Hours() float64

Hours returns elapsed time as floating point number like 0.23h.

func (*Monitor) Microseconds

func (m *Monitor) Microseconds() int64

Microseconds returns elapsed time in 0.000001 of a second (μs/us).

func (*Monitor) Milliseconds

func (m *Monitor) Milliseconds() int64

Milliseconds returns elapsed time in 0.001 of a second (ms).

func (*Monitor) Nanoseconds

func (m *Monitor) Nanoseconds() int64

Nanoseconds returns elapsed time in nanoseconds (ns).

func (*Monitor) Seconds

func (m *Monitor) Seconds() float64

Seconds returns elapsed time as floating point number like 1.5s.

func (*Monitor) Start

func (m *Monitor) Start() (err error)

Start starts a new monitor.

func (*Monitor) Stop

func (m *Monitor) Stop() (time.Duration, error)

Stop adds to monitor elapsed time and stops time capture.

type Option

type Option int

Option of the capture.

const (
	// Units to output monitor time i.e. nanoseconds(ns). etc.
	Units Option = iota
	// LogFunc function to log watch output.
	LogFunc
	// Percentage option for performance stats.
	Percentage
	// Precision option for float values.
	Precision
)

type Optioner

type Optioner interface {
	Option() Option
	Value() interface{}
}

Optioner interface.

type TraceID

type TraceID uuid.UUID

TraceID is context trace id.

type TraceIDKey

type TraceIDKey int

TraceIDKey is the type of value to use for the key. The key is type specific and only values of the same type will match.

type Watch

type Watch struct {
	Name string

	Unknown time.Duration

	LogMetrics LogMetricsFunc
	// contains filtered or unexported fields
}

Watch performance profiler instance.

func NewWatcher

func NewWatcher(name string, options ...interface{}) (watch *Watch, err error)

NewWatcher creates a new watcher.

func (*Watch) Finish

func (w *Watch) Finish(ctx context.Context) (err error)

Finish captures elapsed monitors, logs Capture info, and ends it.

func (*Watch) Running

func (w *Watch) Running() bool

Running returns true if watch is running.

func (*Watch) Start

func (w *Watch) Start(ctx context.Context, name string) (mon *Monitor)

Start starts RTM area capture.

func (*Watch) Units

func (w *Watch) Units() DurationUnits

Units return DurationUnits for the watch.

type Watcher

type Watcher interface {
	Start(ctx context.Context, name string) *Monitor
	Finish(ctx context.Context) error
	Running() bool
	Units() DurationUnits
}

Watcher interface.

func GetWatch

func GetWatch(ctx context.Context) Watcher

GetWatch extracts watch form the context.

type WatcherIDKey

type WatcherIDKey int

WatcherIDKey is the type of value to use fЕor the key. The key is type specific and only values of the same type will match.

type WatcherType

type WatcherType Watcher

WatcherType is context watcher.

Jump to

Keyboard shortcuts

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