perf

package
v0.0.0-...-2ce8548 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2015 License: BSD-2-Clause Imports: 6 Imported by: 7

Documentation

Overview

Package perf exposes a centralized API for storing, tracking, and querying performance data for a Go application.

Index

Constants

View Source
const STAT_SAMPLES = 100

The number of samples stored and used to calculate statistics in a given Stat object.

Variables

This section is empty.

Functions

func DumpString

func DumpString() string

DumpString dumps every value, of every Counter, of every CounterSet registered with the perf service, in string format.

Types

type Counter

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

Counter represents a simple performance counter object. Counters tracking an ongoing value while also tracking the min, max and per-second delta between samples. Addtionally, statistics can be enabled on a counter object to enable tracking of variance, mean, median and standard deviation.

func NewCounter

func NewCounter() *Counter

NewCounter initializes a new Counter object and returns a pointer to it for use.

func (*Counter) Add

func (this *Counter) Add(amount int64)

Add adds calculates a new counter value by adding the supplied amount to the counter's current value.

func (*Counter) DisableStats

func (this *Counter) DisableStats()

DisableStats removes statistical tracking on this counter object.

func (*Counter) EnableStats

func (this *Counter) EnableStats()

EnableStats enables statistical tracking on this counter object. Note that stats tracking is expensive and should be enabled judiciously on applications that have many counters.

func (*Counter) Increment

func (this *Counter) Increment()

Increment calculates and inserts a new NextVal() which is 1 greater than the last value.

func (*Counter) MaxPerSec

func (this *Counter) MaxPerSec() int64

MaxPerSec calculates and returns the per-second derivative from the most recent two samples.

func (*Counter) PerSec

func (this *Counter) PerSec() int64

PerSec calculates and returns the per-second derivative from the most recent two samples.

func (*Counter) Reset

func (this *Counter) Reset()

Reset re-initializes the counter object and underlying stats. It does not disable stats if they have been enabled on the counter object, only resets them.

func (*Counter) Set

func (this *Counter) Set(val int64)

Set sets the counter to the supplied value.

func (*Counter) Stats

func (this *Counter) Stats() *Stat

Stats returns this counter object's statistics object. If stats are not enabled, returns nil.

func (*Counter) String

func (this *Counter) String() string

String pretty-prints the contents of the counter object

func (*Counter) Value

func (this *Counter) Value() int64

Value returns the current value of the counter.

type CounterSet

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

CounterSet represent a collection of named performance CounterSet and their values.

func GetAllCounterSets

func GetAllCounterSets() []*CounterSet

GetAllCounterSets returns a slice with pointers to all registered CounterSet objects.

func GetCounterSet

func GetCounterSet(name string) *CounterSet

GetCounterSet returns the named CounterSet object, if one is registered by that name. Otherwise, nil is returned.

func NewCounterSet

func NewCounterSet(name string, size int, names []string) *CounterSet

NewCounterSet is a construction helper which creates a new CounterSet container, registers and initializes it, and returns a pointer to it for use.

func (*CounterSet) Add

func (this *CounterSet) Add(offset int, val int64)

Add adds the supplied val to the value of the specified counter. If the specified offset doesn't exist, it's a no-op.

func (*CounterSet) CounterName

func (this *CounterSet) CounterName(offset int) string

CounterName returns the friendly name of the counter at the given offset. If the specified offset doesn't exist, a blank string is returned.

func (*CounterSet) EnableStats

func (this *CounterSet) EnableStats(offset int)

EnableStats enables statistics gathering on the given counter object.

func (*CounterSet) Get

func (this *CounterSet) Get(offset int) *Counter

Get returns the Counter object representing the given offset.

func (*CounterSet) Increment

func (this *CounterSet) Increment(offset int)

Increment adds 1 to the value of the specified counter. If the specified offset doesn't exist, it's a no-op.

func (*CounterSet) Len

func (this *CounterSet) Len() int

Len returns the number of counters in available in this CounterSet.

func (*CounterSet) Name

func (this *CounterSet) Name() string

Name returns the friendly name of this CounterSet container.

func (*CounterSet) Reset

func (this *CounterSet) Reset()

Reset ranges through all individual CounterSet in this CounterSet object and sets them all back to zero.

func (*CounterSet) Set

func (this *CounterSet) Set(offset int, value int64)

Set sets the value of the counter at the given offset to the specified value. If the specified offset doesn't exist, it's a no-op

func (*CounterSet) String

func (this *CounterSet) String() string

String returns a friendly representation of all the values stored in this CounterSet object.

func (*CounterSet) Value

func (this *CounterSet) Value(offset int) int64

Value returns the current value of the counter at the given offset. If the offset doesn't exist, zero is returned.

type CounterVals

type CounterVals struct {
	Max       int64
	MaxPerSec int64
	Mean      float64
	Min       int64
	Name      string
	PerSec    int64
	StdDev    float64
	Value     int64
	Variance  float64
}

CounterVals represents all of the values associated with a given counter.

func (*CounterVals) String

func (this *CounterVals) String() string

String pretty-prints the values inside the CounterVals object.

func (*CounterVals) StringBrief

func (this *CounterVals) StringBrief() string

StringBrief prints a less verbose output of performance counters, only writing data for non-default values.

type Snapshot

type Snapshot struct {
	Counters  []*CounterVals
	Timestamp time.Time
}

Snapshot represents a snapshot of perf counter data taken at a given point in time.

func TakeSnapshot

func TakeSnapshot() *Snapshot

TakeSnapshot creates a new Snapshot object containing the values of all the current metrics in the perf system, and returns a pointer to it for use.

func (*Snapshot) String

func (this *Snapshot) String() string

String pretty-prints the Snapshot object and all of the counter objects it contains.

func (*Snapshot) StringBrief

func (this *Snapshot) StringBrief() string

StringBrief pretty-prints a less verbose version of the Snapshot object, opting to only print non-default values.

type Stat

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

Stat represents a series of values and some common statistical values associated with that set.

func NewStat

func NewStat() *Stat

NewStat initializes a new Stat object and returns a pointer to it for use.

func (*Stat) Len

func (this *Stat) Len() int

MaxCount returns the total number of items in the set.

func (*Stat) Max

func (this *Stat) Max() int64

Max returns the maximum value that has been observed since recording stats for this object.

func (*Stat) Mean

func (this *Stat) Mean() float64

Mean returns the mean (simple average) across all values in the set.

func (*Stat) Min

func (this *Stat) Min() int64

Min returns the minimum value that has been observed since reocrding stats for this object.

func (*Stat) Next

func (this *Stat) Next(val int64)

Next submits the given value as the next value in the set.

func (*Stat) Reset

func (this *Stat) Reset()

Reset re-initializes all stat values back to zero.

func (*Stat) StdDev

func (this *Stat) StdDev() float64

StdDev returns the standard deviation across all values in the set.

func (*Stat) String

func (this *Stat) String() string

String implements Stringer to pretty-print the Stat object.

func (*Stat) Variance

func (this *Stat) Variance() float64

Variance returns the variance across all values in the set.

Jump to

Keyboard shortcuts

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