counters

package module
v0.0.0-...-9c21fcb Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: BSD-2-Clause Imports: 5 Imported by: 1

README

Counters

Build Status

Build Status

Overview

Counters is a Go package which provides an easy API for adding and tracking platform agnostic performance counters within your application.

License

This Go package is release under a BSD-style license, the contents of which are in the repo's LICENSE file.

API Documentation

http://godoc.org/github.com/xaevman/counters

Documentation

Overview

Package counters provides some basic functionality for implementing centralized performance counters for an application.

Index

Constants

View Source
const MAX_TRACKING_SEC = 30

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter interface {
	Add(interface{})
	Get() string
	GetRaw() interface{}
	Name() string
	Set(interface{})
}

Counter provides the interface which underlying counter types must implement to be used by the default counter list system.

type Float

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

Float implements the Counter interface for the floating point data type.

func NewFloat

func NewFloat(name string) *Float

NewFloat returns a reference to an instance of a new Float counter object.

func (*Float) Add

func (this *Float) Add(val interface{})

Add type-asserts teh supplied value as a float64 and adds it to the existing stored value.

func (*Float) Get

func (this *Float) Get() string

Get returns the current stored value as a string.

func (*Float) GetRaw

func (this *Float) GetRaw() interface{}

GetRaw reutrns the current stored value as a float64.

func (*Float) MarshalJSON

func (this *Float) MarshalJSON() ([]byte, error)

func (*Float) Name

func (this *Float) Name() string

Name returns the name of this counter instance.

func (*Float) Set

func (this *Float) Set(val interface{})

Set type-asserts the supplied value as a float64 and sets the current value of the counter to that value.

type Int

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

Int implements the Counter interface for the integer data type.

func NewInt

func NewInt(name string) *Int

NewInt returns a reference to a new Int counter object.

func (*Int) Add

func (this *Int) Add(val interface{})

Add type-asserts the supplied value as an int64 and adds it to the current counter value.

func (*Int) Get

func (this *Int) Get() string

Get returns the current counter value as a string.

func (*Int) GetRaw

func (this *Int) GetRaw() interface{}

GetRaw returns the current counter value as an int64.

func (*Int) MarshalJSON

func (this *Int) MarshalJSON() ([]byte, error)

func (*Int) Name

func (this *Int) Name() string

Name returns the name of this counter instance.

func (*Int) Set

func (this *Int) Set(val interface{})

Set type-asserts the supplied value as an int64 and stores it as the new counter value.

type KahanSum

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

KahanSum represents a running summation of a series of floating point values. The Kahan sum algorithm attempts to reduce the amount of error accumulated when performing many math operations on floating point numbers of varying precisions.

function KahanSum(input)
  var sum = 0.0
  var c = 0.0                  // A running compensation for lost low-order bits.
  for i = 1 to input.length do
      var y = input[i] - c     // So far, so good: c is zero.
      var t = sum + y          // Alas, sum is big, y small, so low-order digits of y are lost.
      c = (t - sum) - y // (t - sum) recovers the high-order part of y; subtracting y recovers -(low part of y)
      sum = t           // Algebraically, c should always be zero. Beware overly-aggressive optimizing compilers!
      // Next time around, the lost low part will be added to y in a fresh attempt.
  return sum

func (*KahanSum) Add

func (this *KahanSum) Add(val float64) float64

Add sums the previous and supplied values together using Kahan's sum algorithm and returns the resulting new sum.

func (*KahanSum) Reset

func (this *KahanSum) Reset()

Reset sets the compensation and sum values back to defaults (0).

func (*KahanSum) Sum

func (this *KahanSum) Sum() float64

Sum returns the current sum.

type List

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

List is a centralized container for counter objects. It supplies methods for adding, removing, and operating on a set of counters registered with it.

func NewList

func NewList() *List

NewList returns a reference to a new List object.

func (*List) Add

func (this *List) Add(c Counter) error

Add registers a new counter with this counter list. If an existing counter with the same name already exists, an error is returned.

func (*List) Do

func (this *List) Do(f func(Counter) error) []error

Do performs function f on each counter instance currently registered with the counter list.

func (*List) Get

func (this *List) Get(counterName string) (Counter, bool)

Get attempts to retreive a counter by the given name from the counter list. If it succeeds, a reference to the counter and an ok value of true are returned. If not, the counter reference will be nil, and an ok value of false is also returned.

func (*List) Len

func (this *List) Len() int

Len returns the current number of counters contained within this counter list.

func (*List) MarshalJSON

func (this *List) MarshalJSON() ([]byte, error)

func (*List) Remove

func (this *List) Remove(counterName string)

Remove attempts to remove a counter by the given name from the counter list.

type PerfTimer

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

func NewPerfTimer

func NewPerfTimer(name string) *PerfTimer

func (*PerfTimer) Counters

func (pt *PerfTimer) Counters() Counter

func (*PerfTimer) EndSample

func (pt *PerfTimer) EndSample()

func (*PerfTimer) StartSample

func (pt *PerfTimer) StartSample()

type RunningAvg

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

func NewRunningAvg

func NewRunningAvg(name string) *RunningAvg

func (*RunningAvg) Add

func (ra *RunningAvg) Add(val interface{})

func (*RunningAvg) Get

func (ra *RunningAvg) Get() string

func (*RunningAvg) GetRaw

func (ra *RunningAvg) GetRaw() interface{}

func (*RunningAvg) MarshalJSON

func (ra *RunningAvg) MarshalJSON() ([]byte, error)

func (*RunningAvg) Name

func (ra *RunningAvg) Name() string

func (*RunningAvg) Set

func (ra *RunningAvg) Set(val interface{})

type Timer

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

Timer implements the Counter interface to supply a continuously updating timer counter.

func NewTimer

func NewTimer(name string) *Timer

NewTimer returns a reference to a new Timer instance. The timer is not started until the user explicitly starts it.

func (*Timer) Add

func (this *Timer) Add(val interface{})

Add is not implemented in the Timer counter.

func (*Timer) Get

func (this *Timer) Get() string

Get returns the current number of seconds elapsed since the timer was started as a string.

func (*Timer) GetRaw

func (this *Timer) GetRaw() interface{}

Get returns the current number of seconds elapsed since the timer was started as a float64.

func (*Timer) MarshalJSON

func (this *Timer) MarshalJSON() ([]byte, error)

func (*Timer) Name

func (this *Timer) Name() string

Name returns the name of this counter instance.

func (*Timer) Set

func (this *Timer) Set(val interface{})

Set starts this timer object.

type Uint

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

Uint implements the Counter interface for the uint data type.

func NewUint

func NewUint(name string) *Uint

NewUint returns a reference to a new Uint counter instance.

func (*Uint) Add

func (this *Uint) Add(val interface{})

Add type-asserts the given value as a uint64 and adds it to the current counter value.

func (*Uint) Get

func (this *Uint) Get() string

Get returns the current counter value as a string.

func (*Uint) GetRaw

func (this *Uint) GetRaw() interface{}

GetRaw returns the current counter value as a uint64.

func (*Uint) MarshalJSON

func (this *Uint) MarshalJSON() ([]byte, error)

func (*Uint) Name

func (this *Uint) Name() string

Name returns the name of this counter instance.

func (*Uint) Set

func (this *Uint) Set(val interface{})

Set type-asserts the given value as uint64 and sets the current counter value to that value.

Jump to

Keyboard shortcuts

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