Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DurationThreshold = 5 * time.Millisecond
Duration threshold - timings below the threshold will not be saved in the state. It can be changed only while holding state lock.
var MaxTimings = 100
Maximum number of timings to keep in state. It can be changed only while holding state lock.
Functions ¶
Types ¶
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span represents a single performance measurement with optional nested measurements.
type TimingJSON ¶
type TimingJSON struct { Level int `json:"level,omitempty"` Label string `json:"label,omitempty"` Summary string `json:"summary,omitempty"` Duration time.Duration `json:"duration"` }
TimingJSON and rootTimingsJSON aid in marshalling of flattened timings into state.
type Timings ¶
type Timings struct {
// contains filtered or unexported fields
}
Timings represents a tree of Span time measurements for a single execution of measured activity. A Timings tree object should be created at the beginning of the activity, followed by starting at least one Span, and then saved at the end of the activity.
Calling StartSpan on the Timings objects creates a Span and starts new performance measurement. Measurement needs to be finished by calling Stop function on the Span object. Nested measurements may be collected by calling StartSpan on Span objects. Similar to the above, nested measurements need to be finished by calling Stop on them.
Typical usage:
troot := timings.New(map[string]string{"task-id": task.ID(), "change-id": task.Change().ID()}) t1 := troot.StartSpan("computation", "...") .... nestedTiming := t1.StartSpan("sub-computation", "...") .... nestedTiming.Stop() t1.Stop() troot.Save()
In addition, a few helpers exist to simplify typical use cases, for example the above example can be reduced to:
troot := timings.NewForTask(task) // tags set automatically from task t1 := troot.StartSpan("computation", "...") timings.Run(t1, "sub-computation", "...", func(nested *Span) { ... expensive computation }) t1.Stop() troot.Save(task.State())
func New ¶
New creates a Timings object. Tags provide extra information (such as "task-id" and "change-id") that can be used by the client when retrieving timings.
func NewForTask ¶
NewForTask creates a new Timings tree for the given task. Returned Timings tree has "task-id", "change-id" and "task-kind" tags set automatically from the respective task.
func (*Timings) LinkChange ¶
LinkChange sets the "change-id" tag on the Timings object.
func (*Timings) Save ¶
Save appends Timings data to the "timings" list in the state and purges old timings, ensuring that up to MaxTimings are kept. Timings are only stored in state if their duration is greater than or equal to DurationThreshold. It's responsibility of the caller to lock the state before calling this function.
type TimingsInfo ¶
type TimingsInfo struct { Tags map[string]string NestedTimings []*TimingJSON }
TimingsInfo holds a set of related nested timings and the tags set when they were captured.
func Get ¶
func Get(st *state.State, maxLevel int, filter func(tags map[string]string) bool) ([]*TimingsInfo, error)
Get returns timings for which filter predicate is true and filters out nested timings whose level is greater than maxLevel. Negative maxLevel value disables filtering by level. It's responsibility of the caller to lock the state before calling this function.