Documentation
¶
Overview ¶
Package timing records where one request's time went (agni issue 914): its stages, which cache layer answered each read, how long each rule took, and the plan of each query evaluated.
A Recorder travels in the request's context. Every recording call here is a no-op when the context holds none, so a request nobody is timing costs one context lookup per call and nothing else. The package imports only the standard library, so the rule loop in core/check can record into it.
Index ¶
- func Absent(ctx context.Context, query, why string)
- func AskingWhyNot(ctx context.Context) bool
- func Begin(ctx context.Context, name string) func()
- func BeginRule(ctx context.Context) func(name string)
- func Cached(ctx context.Context, layer, source string)
- func Explaining(ctx context.Context) bool
- func Planned(ctx context.Context, query, plan string)
- func Ruled(ctx context.Context, rule string, d time.Duration)
- func With(ctx context.Context, r *Recorder) context.Context
- type Lookup
- type Plan
- type Recorder
- type RuleTime
- type Snapshot
- type Stage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Absent ¶ added in v0.12.0
Absent records why one query evaluation answered no rows, as jaala's Absence renders it.
func AskingWhyNot ¶ added in v0.12.0
AskingWhyNot reports whether the request asked why an empty answer is empty.
func Begin ¶
Begin starts a stage and returns the function that ends it, for `defer timing.Begin(ctx, "x")()`.
func BeginRule ¶
BeginRule starts timing one rule and returns the function that records it under name, with the bytes it allocated when the Recorder asked for Memory (agni issue 994). It is Ruled for a caller that wants allocation too.
func Explaining ¶
Explaining reports whether the request asked for query plans.
Types ¶
type Lookup ¶
Lookup is which tier answered one cached read: "memory" (kept in this process), "store" (the persistent tier, such as the browser's), "built" (read and built now) or "uncached" (no cache).
type Recorder ¶
type Recorder struct {
// Explain asks query evaluations to record their plans (jaala's Explain), which costs time in
// proportion to the rules and literals a query runs.
Explain bool
// WhyNot asks a query evaluation that answers no rows to record why (jaala's WhyNot, agni issue
// 1965). It costs one more evaluation per literal, and only on an empty answer.
WhyNot bool
// Memory asks each stage to record the process's memory as it ends (agni issue 994). Reading it
// stops the world briefly, so only a request that asks for it is slowed. In wasm, memory only
// grows. So when a stage's end first shows a higher Sys, that stage raised the peak.
Memory bool
// contains filtered or unexported fields
}
Recorder collects one request's timings. Its methods are safe for concurrent use, since a request may read its tiers in parallel.
type RuleTime ¶
RuleTime is how long one rule's evaluation took, and, when the Recorder asked for Memory, how many bytes it allocated, collected or not. Allocation is read process-wide, so a rule run while another request allocates is charged for both.
type Snapshot ¶
type Snapshot struct {
Total time.Duration
Stages []Stage // by start
Lookups []Lookup // in the order the reads happened
Rules []RuleTime // slowest first
Plans []Plan // in the order the queries ran
// Absent holds why each empty answer is empty, in the order the queries ran. Text is jaala's
// Absence as text.
Absent []Plan
}
Snapshot is a Recorder's contents at one moment, in the order a reader wants them.
type Stage ¶
type Stage struct {
Name string
// Start is the span's offset from the start of the request.
Start time.Duration
Dur time.Duration
// Sys and HeapAlloc are runtime.MemStats' figures as the stage ended, zero unless the Recorder
// asked for Memory. Sys counts what the runtime has obtained, and in wasm that is the memory's
// size. HeapAlloc includes garbage not yet collected, since no collection is forced.
Sys uint64
HeapAlloc uint64
}
Stage is one named span of a request. Stages nest, so a parent's duration includes its children's.