Help us shape the future of Go! Take the 2026 Go Developer Survey

probes

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 2 Imported by: 1

README

probes

GoDoc Build Status

The probes package helps examine numerical values that change over time by providing methods to collect values safely across goroutines through the Probe structure.

Usage

Activation/Deactivation

Activate a probe by calling its Activate method, and deactivate it by calling Deactivate. While doing work, send values to the probe's input channel.

p := NewProbe()
p.Activate()

// Some work...
for var i := 0; i < 10; i++ {
  p.C <- float64(i)
}

p.Flush()
p.Deactivate()
Examining the Input Signal

Examine the probe's input signal at any time by using the Signal and RecentValue methods.

// "9"
fmt.Println(p.RecentValue())

// "[0 1 2 3 4 5 6 7 8 9]"
fmt.Println(p.Signal())
Reuse

Calling Activate after a call to Deactivate will continue appending values to the probes previous input signal. To prevent this behavior, call the probe's ClearSignal method before a call to Activate.

// ... some work
p.Deactivate()

// Log our input signal
fmt.Println(p.Signal())

// Clear the input and re-activate
p.ClearSignal()
p.Activate()
Buffers and State

Set the probe's input channel buffer length by setting the InputBufferLength property. This value is set to 1 by default and will only take effect after the next call to Activate.

Set the probe's maximum signal length by setting the MaximumSignalLength property. This value is set to math.MaxInt32 by default and should only be set while the probe is in an inactive state.

Check the state of the probe at any time with its IsActive method.

p.InputBufferLength = 10

if !p.IsActive() {
  p.MaximumSignalLength = 100
}
Blocking and Non-Blocking

Probe provides two ways to pass input to the probe:

  • The input channel, C. (non-blocking)
  • The Push method. (blocking)

Use whichever is more appropriate, but be aware that calling Deactivate on a probe does not automatically flush the probes input channel buffer. You must call Flush before calling Deactivate to ensure that all values will be represented in the probe's signal.

Mixing input methods by using both the channel and push method is supported by the push method's flush parameter. Set this to true to preserve input order in the probe's signal.

p := NewProbe()
p.Activate()

// Some work...
for var i := 0; i < 10; i++ {
  p.C <- float64(i)
}

p.Push(10, true)
p.Deactivate()

Documentation

Overview

Package probes provides types to inspect varying numerical values safely across many goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Probe

type Probe struct {
	// The maximum length of the probe's internal signal history.
	MaximumSignalLength int

	// The length of the input channel's buffer.
	InputBufferLength int

	// The probe's input channel.
	C chan float64
	// contains filtered or unexported fields
}

Probe types collect floating point values and expose those values safely.

func NewProbe

func NewProbe() *Probe

NewProbe creates and returns a new probe.

func (*Probe) Activate

func (p *Probe) Activate()

Activate activates the probe and begins waiting for signal values over its input channel.

func (*Probe) ClearSignal

func (p *Probe) ClearSignal()

ClearSignal removes all elements from the probe's signal.

func (*Probe) Deactivate

func (p *Probe) Deactivate()

Deactivate deactivates the probe and returns the signal it collected.

func (*Probe) Flush

func (p *Probe) Flush()

Flush flushes the probe's input channel buffer.

func (*Probe) IsActive

func (p *Probe) IsActive() bool

IsActive returns the state of the probe.

func (*Probe) Push

func (p *Probe) Push(value float64, flush bool)

Push appends a value to the probe's signal after, optionally, flushing any values in the probe's input channel buffer.

func (*Probe) RecentValue

func (p *Probe) RecentValue() float64

RecentValue retrieves the most recent value collected by the probe, or 0.0 if a value has not been collected.

func (*Probe) Signal

func (p *Probe) Signal() []float64

Signal returns the probe's accumulated signal.

Jump to

Keyboard shortcuts

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