Documentation
¶
Overview ¶
Package counters provides some basic functionality for implementing centralized performance counters for an application.
Index ¶
Constants ¶
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 (*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) GetRaw ¶
func (this *Float) GetRaw() interface{}
GetRaw reutrns the current stored value as a float64.
func (*Float) MarshalJSON ¶
type Int ¶
type Int struct {
// contains filtered or unexported fields
}
Int implements the Counter interface for the integer data type.
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) GetRaw ¶
func (this *Int) GetRaw() interface{}
GetRaw returns the current counter value as an int64.
func (*Int) MarshalJSON ¶
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 ¶
Add sums the previous and supplied values together using Kahan's sum algorithm and returns the resulting new 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 (*List) Add ¶
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 ¶
Do performs function f on each counter instance currently registered with the counter list.
func (*List) Get ¶
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) MarshalJSON ¶
type PerfTimer ¶
type PerfTimer struct {
// contains filtered or unexported fields
}
func NewPerfTimer ¶
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 ¶
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 ¶
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 ¶
type Uint ¶
type Uint struct {
// contains filtered or unexported fields
}
Uint implements the Counter interface for the uint data type.
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) GetRaw ¶
func (this *Uint) GetRaw() interface{}
GetRaw returns the current counter value as a uint64.