Documentation
¶
Overview ¶
Package meter counts what a unit of the loop's work costs at its boundaries. A unit is a Scope carried by a context; adapters add a Sample per boundary call, and a Registry on the context keeps totals per scope since start.
Index ¶
- Constants
- Variables
- func Add(ctx context.Context, x Sample)
- func Job(name string) string
- func Loop(name string) string
- func Route(pattern string) string
- func Spend(ctx context.Context, res Resource, op string, points int64)
- func Trace(ctx context.Context) context.Context
- func Tracing(ctx context.Context) bool
- func WithRegistry(ctx context.Context, r *Registry) context.Context
- type Key
- type Registry
- type Resource
- type Sample
- type Scope
- type Stat
- type Tally
- type Total
Constants ¶
const Untagged = "untagged"
Untagged names the registry's totals of samples added outside any scope.
Variables ¶
Resources is every Resource in display order.
Functions ¶
func Add ¶
Add records x in ctx's scope chain and registry; without a scope it goes to the registry under Untagged; without either it is dropped.
func Spend ¶
Spend adds points to Key{res, op} without counting a call: the cost a response reports for a request its transport already counted.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry keeps totals per scope full name since it was made. Safe for concurrent use.
func NewRegistry ¶
NewRegistry makes a registry whose clock is now; a nil now is time.Now.
type Resource ¶
type Resource string
Resource is the boundary a sample crossed, named by port.
const ( SQL Resource = "sql" // one statement; Op "query" or "exec"; Rows for a query Tx Resource = "tx" // one transaction, Dur from begin to commit or rollback; Op "read" (no exec ran) or "write" Workspace Resource = "workspace" // one workspace-manager call; Op its subcommand or method, such as "worktree ps" GitHub Resource = "github" // one GitHub API request; Op "graphql", "rest" or "gh <subcommand>" Git Resource = "git" // one git command; Op its subcommand Agent Resource = "agent" // one headless agent run; Op "ask" or "shell" Work Resource = "work" // one in-process unit its package names, such as "derive rows" )
type Sample ¶
type Sample struct {
Res Resource
// Op is bounded: a subcommand, a method or a statement class; never an
// id, a ref, a path or a URL.
Op string
Spawn bool // the call started a process
Dur time.Duration
// Err is a failure other than the caller's cancellation or deadline:
// adapters set it only when err != nil && ctx.Err() == nil.
Err bool
NotModified bool // a conditional request answered 304
Points int64 // GitHub rate-limit points the call spent, when the response says
Bytes int64 // response bytes read
Rows int64 // rows a query returned
// Detail is the statement text (whitespace collapsed) or the argv, cut
// to 300 bytes. Adapters fill it only when Tracing(ctx).
Detail string
}
Sample is one call across a boundary.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope is one unit of work. Safe for concurrent Add.
func Start ¶
Start opens a scope under ctx's scope, if any. Its full name is name, or "<parent full name>/<name>" when nested. Samples added under the returned context reach this scope and every enclosing one, and reach the registry on ctx, if any, once, under this scope's full name.
func (*Scope) End ¶
End freezes the tally and counts one run of the scope's name in the registry, with its wall time and tally as the name's Last. A second End returns the same tally. Samples after End still reach the registry, not the tally.
type Stat ¶
type Stat struct {
Calls, Spawns, Errors, NotModified int64
Points, Bytes, Rows int64
Dur, Max time.Duration
}
Stat aggregates samples of one Key. Calls counts samples; Spend adds Points without a call.
type Tally ¶
Tally is stats by Key: a value, safe to keep and compare.
type Total ¶
type Total struct {
Name string
Runs int64 // scopes of this name ended
Wall time.Duration // summed over ended scopes
Tally Tally // every sample since Since, ended scopes or not
Last Tally // the last ended scope's tally; nil before one ends
LastAt time.Time
LastWall time.Duration
}
Total is a registry's totals for one scope full name.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package metertest asserts what a unit of work cost, in the manner of assertNumQueries: a failure lists the samples so an N+1 shows.
|
Package metertest asserts what a unit of work cost, in the manner of assertNumQueries: a failure lists the samples so an N+1 shows. |