Documentation
¶
Overview ¶
Package perfgate compares benchmark results with performance thresholds.
It reads two kinds of results: `go test -bench` output (benchmark name, iteration count, then value/unit pairs) and the JSON lines written by bench/k8s.sh (RESULTS). Thresholds live in a JSON file of named profiles (bench/thresholds.json), so CI runners and a developer machine can be held to different, documented limits.
Index ¶
Constants ¶
const ( ExitOK = 0 ExitFail = 1 // a threshold was exceeded or a result is missing ExitUsage = 2 // bad flags, unreadable input or invalid thresholds )
Exit codes of Run.
Variables ¶
This section is empty.
Functions ¶
func ReadK8s ¶
ReadK8s returns the numeric fields of the last JSON line of a bench/k8s.sh RESULTS file (the script appends one line per run).
func Run ¶
Run is the perfgate command line (cmd/perfgate and bench/check.sh):
perfgate [-thresholds bench/thresholds.json] [-profile plan]
[-k8s results.jsonl] [-bench out.txt ...] [-partial]
[-summary file] [-json file] [bench-output.txt ...]
It prints one line per check and exits ExitFail when any check fails.
Types ¶
type BenchResults ¶
BenchResults maps benchmark name to unit to every reported value.
func ParseBench ¶
func ParseBench(r io.Reader) (BenchResults, error)
ParseBench reads `go test -bench` output; non-benchmark lines are skipped. Repeated runs (-count) of a benchmark accumulate.
func (BenchResults) Merge ¶
func (r BenchResults) Merge(other BenchResults)
Merge adds the values of other to r.
type Check ¶
type Check struct {
Source string // "k8s" or "bench"
Name string // benchmark name, or "k8s"
Metric string // unit or RESULTS field
Value float64 // median measured value
Min float64
Max float64
HasMin bool
HasMax bool
Missing bool // no result for a configured limit
OK bool
}
Check is the outcome of one metric against its bound.
type Config ¶
Config is the thresholds file.
func ParseConfig ¶
ParseConfig decodes a thresholds file. Top-level keys other than "profiles" (such as "_doc") are ignored.
type Limit ¶
Limit is one threshold value: a plain number in the metric's unit, or a Go duration string ("150ms") converted to the metric's time unit.
func (*Limit) In ¶
In returns the limit expressed in unit. A duration converts to nanoseconds for "ns/op", milliseconds for units ending in "ms" and seconds for "s" or units ending in "_s"; any other unit takes plain numbers only.
func (*Limit) UnmarshalJSON ¶
UnmarshalJSON accepts a number or a duration string.
type Profile ¶
type Profile struct {
// K8s maps a bench/k8s.sh RESULTS field (full_s, noop_s, ...) to its bound.
K8s map[string]Bound `json:"k8s"`
// Bench maps a benchmark name (without the -GOMAXPROCS suffix) to its
// metrics; a metric key is a unit ("ns/op", "go-edit-ms") or a
// path.Match pattern over units ("*-ms").
Bench map[string]map[string]Bound `json:"bench"`
}
Profile holds the limits of one environment.
type Report ¶
Report is the result of checking one profile.
func (*Report) DropAbsent ¶
func (r *Report) DropAbsent(bench BenchResults)
DropAbsent removes bench checks of benchmarks that have no result at all in bench, for runs of a subset of the gates. Missing metrics of a benchmark that did run still fail.
func (*Report) WriteMarkdown ¶
WriteMarkdown renders the report as a table (for $GITHUB_STEP_SUMMARY).