Documentation
¶
Overview ¶
Package stat collects per-operation success/error counts so a summary can be printed at the end of a run. It is opt-in: until InitStat is called (root --stat flag), Add and Collect are cheap no-ops, so callers can report unconditionally without worrying about whether stats are enabled.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶ added in v0.0.6
Add records one completed operation. It is a no-op until InitStat has been called. The log package calls it for every operation-attributed Info (success) and Error (failure) message, so enabling --stat requires no per-command wiring.
func Collect ¶
Collect returns a closure intended for `defer` at the top of an Action. When the deferred call runs, if *err is nil the operation's success counter is incremented, and the total counter is always incremented (provided stat collection is enabled). The closure is a no-op when stat collection is disabled, so it is safe to defer unconditionally.
Types ¶
type Stat ¶
type Stat struct {
Operation string `json:"operation"`
Success int64 `json:"success"`
Error int64 `json:"error"`
}
Stat is a single operation's statistics.
type Stats ¶
type Stats []Stat
Stats is a slice of Stat that implements log.Message.
func Statistics ¶
func Statistics() Stats
Statistics returns the stats collected so far, sorted by operation name so the summary table is deterministic. Returns an empty slice if stat collection is disabled. The maps are snapshotted under their mutexes so Statistics is safe to call while workers are still adding.