config

package
v0.0.0-...-61c93d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID       string
	Title    string
	Includes Includes
}

Category groups functions, contexts, versions and metrics into a single chart.

type Config

type Config struct {
	Name        string
	IsJSON      bool `mapstructure:"-"`
	IsStrict    bool `mapstructure:"-"`
	Environment string
	Render      Rendering
	Outputs     Output `mapstructure:"-"`
	Metrics     []Metric
	Functions   []Function
	Contexts    []Context
	Versions    []Version
	Categories  []Category
	Files       []File // Files allows for enrichments based on the input file name
	// contains filtered or unexported fields
}

Config holds the configuration for benchviz.

func Generate

func Generate(input GenerateInput) *Config

Generate builds a Config from parsed benchmark data.

It creates one function entry per unique benchmark name, includes all detected metrics, and bundles everything into a single "all" category.

func Load

func Load(file string) (*Config, error)

Load a configuration file from the local file system.

func LoadDefaults

func LoadDefaults() (*Config, error)

LoadDefaults loads the default configuration from the embedded default_config.yaml.

func (*Config) EncodeYAML

func (c *Config) EncodeYAML(w io.Writer) error

EncodeYAML serializes a Config to YAML into the provided writer.

Runtime-only fields (IsJSON, IsStrict, Outputs) are excluded from the output.

func (Config) FindContext

func (c Config) FindContext(name string) (id string, ok bool)

FindContext returns the ID of the first context whose regexp matches the given benchmark name.

func (Config) FindContextFromFile

func (c Config) FindContextFromFile(file string) (id string, ok bool)

FindContextFromFile returns the ID of the first context matched by a file-based rule.

func (Config) FindFunction

func (c Config) FindFunction(name string) (id string, ok bool)

FindFunction returns the ID of the first function whose regexp matches the given benchmark name.

func (Config) FindVersion

func (c Config) FindVersion(name string) (id string, ok bool)

FindVersion returns the ID of the first version whose regexp matches the given benchmark name.

func (Config) FindVersionFromFile

func (c Config) FindVersionFromFile(file string) (id string, ok bool)

FindVersionFromFile returns the ID of the first version matched by a file-based rule.

func (Config) GetContext

func (c Config) GetContext(id string) (Context, bool)

GetContext retrieves a context definition by its ID.

func (Config) GetFunction

func (c Config) GetFunction(id string) (Function, bool)

GetFunction retrieves a function definition by its ID.

func (Config) GetMetric

func (c Config) GetMetric(id MetricName) (Metric, bool)

GetMetric retrieves a metric definition by its MetricName.

func (Config) GetVersion

func (c Config) GetVersion(id string) (Version, bool)

GetVersion retrieves a version definition by its ID.

type Context

type Context struct {
	Object `mapstructure:",deep,squash"`
}

Context identifies a benchmark context (e.g. input size, data type) by regexp matching.

type File

type File struct {
	ID        string
	MatchFile string
	Contexts  []Context
	Versions  []Version
	// contains filtered or unexported fields
}

File defines a file-matching rule that enriches benchmarks with version or context based on filename.

func (File) MatchString

func (f File) MatchString(file string) (id string, ok bool)

MatchString reports whether the file name matches the file rule, returning the file rule ID.

type Function

type Function struct {
	Object `mapstructure:",deep,squash"`
}

Function identifies a benchmark function by regexp matching on its name.

type GenerateInput

type GenerateInput struct {
	Functions []string
	Metrics   []MetricName
}

GenerateInput holds the data needed by Generate to build a configuration from parsed benchmark results.

This avoids importing the parser package (which imports config).

type Includes

type Includes struct {
	Functions []string
	Versions  []string
	Contexts  []string
	Metrics   []MetricName
}

Includes lists the IDs of functions, versions, contexts and metrics included in a Category.

type Layout

type Layout struct {
	Horizontal int
	Vertical   int
}

Layout controls how charts are arranged on the page.

type LegendPosition

type LegendPosition string

LegendPosition controls where the chart legend is displayed.

const (
	LegendPositionNone   LegendPosition = "none"
	LegendPositionBottom LegendPosition = "bottom"
	LegendPositionTop    LegendPosition = "top"
	LegendPositionLeft   LegendPosition = "left"
	LegendPositionRight  LegendPosition = "right"
)

Supported legend positions.

type Metric

type Metric struct {
	ID    MetricName
	Title string
	Axis  string
}

Metric defines a benchmark metric with its display title and axis label.

type MetricName

type MetricName string

MetricName identifies a benchmark metric (e.g. "nsPerOp", "allocsPerOp").

const (
	MetricNsPerOp     MetricName = "nsPerOp"
	MetricAllocsPerOp MetricName = "allocsPerOp"
	MetricBytesPerOp  MetricName = "bytesPerOp"
	MetricMBPerS      MetricName = "MBytesPerS"
)

Standard benchmark metric names.

func AllMetricNames

func AllMetricNames() []MetricName

AllMetricNames returns all known benchmark metric names.

func (MetricName) IsValid

func (m MetricName) IsValid() bool

IsValid reports whether the metric name is one of the known benchmark metrics.

func (MetricName) String

func (m MetricName) String() string

String returns the metric name as a plain string.

type Object

type Object struct {
	ID       string
	Title    string
	Match    string
	NotMatch string
	// contains filtered or unexported fields
}

Object is the base type for regexp-matched configuration entries (functions, contexts, versions).

func (Object) MatchString

func (o Object) MatchString(name string) (id string, ok bool)

MatchString reports whether name matches the object's positive regexp and not its negative regexp.

func (Object) Matchers

func (o Object) Matchers() (match, notMatch *regexp.Regexp)

Matchers returns the compiled positive and negative match regexps.

type Orientation

type Orientation string

Orientation controls the chart bar direction.

const (
	OrientationVertical   Orientation = "vertical"
	OrientationHorizontal Orientation = "horizontal"
)

Supported chart orientations.

type Output

type Output struct {
	HTMLFile string
	PngFile  string
	IsTemp   bool
}

Output holds the resolved output file paths for HTML and PNG rendering.

type Rendering

type Rendering struct {
	Title       string
	Theme       string
	Layout      Layout
	Chart       string
	Legend      LegendPosition
	Scale       Scale
	DualScale   bool
	Orientation Orientation
	Screenshot  Screenshot
}

Rendering holds chart rendering settings (theme, layout, legend, scale).

type Scale

type Scale string

Scale controls the Y-axis scaling strategy.

const (
	ScaleAuto Scale = "auto"
	ScaleLog  Scale = "log"
)

Supported Y-axis scale modes.

type Screenshot

type Screenshot struct {
	Height int64
	Width  int64
	Sleep  string
}

Screenshot configures the headless Chrome screenshot used for PNG rendering.

func (Screenshot) SleepDuration

func (s Screenshot) SleepDuration() time.Duration

SleepDuration parses the Sleep field as a time.Duration.

type Version

type Version struct {
	Object `mapstructure:",deep,squash"`
}

Version identifies a benchmark implementation variant (e.g. "reflect", "generics") by regexp matching.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL