Documentation
¶
Overview ¶
package covutil provides utilities for working with Go coverage data. It allows parsing coverage meta-data and counter files, merging coverage data from multiple runs, and generating various human-readable reports. Additionally, it offers functions for instrumented binaries to programmatically emit their coverage data and control counters.
Index ¶
- Constants
- func ClearCoverageCounters() error
- func PkgFuncKeyString(p PkgFuncKey) string
- func WriteCounterFileContent(w io.Writer) error
- func WriteCoverageSetToDirectory(baseDirPath string, set *CoverageSet) error
- func WriteMetaFileContent(w io.Writer) error
- func WritePodToDirectory(baseDirPath string, pod *Pod) error
- func WriteProfileToDirectory(dirPath string, p *Profile) error
- type CounterDataSegment
- type CounterFile
- type CounterGranularity
- type CounterMode
- type CoverableUnit
- type CoverageSet
- type Formatter
- func (f *Formatter) AddPodProfile(p *Pod) error
- func (f *Formatter) WriteFuncSummaryReport(w io.Writer, opts FuncSummaryReportOptions) error
- func (f *Formatter) WritePercentReport(w io.Writer, opts PercentReportOptions) error
- func (f *Formatter) WriteTextualReport(w io.Writer, opts TextualReportOptions) error
- type FuncDesc
- type FuncSummaryReportOptions
- type FunctionCounters
- type Link
- type LoadOption
- type MetaFile
- type PackageMeta
- type PercentReportOptions
- type PkgFuncKey
- type Pod
- type Profile
- type SourceInfo
- type TextualReportOptions
Constants ¶
const ( ModeSet = coverage.ModeSet ModeCount = coverage.ModeCount ModeAtomic = coverage.ModeAtomic ModeInvalid = coverage.ModeInvalid ModeDefault = coverage.ModeDefault )
const ( GranularityBlock = coverage.GranularityBlock GranularityFunc = coverage.GranularityFunc GranularityInvalid = coverage.GranularityInvalid GranularityDefault = coverage.GranularityDefault )
Variables ¶
This section is empty.
Functions ¶
func ClearCoverageCounters ¶
func ClearCoverageCounters() error
func PkgFuncKeyString ¶
func PkgFuncKeyString(p PkgFuncKey) string
PkgFuncKeyString returns a string representation of the PkgFuncKey.
func WriteCounterFileContent ¶
func WriteCoverageSetToDirectory ¶
func WriteCoverageSetToDirectory(baseDirPath string, set *CoverageSet) error
WriteCoverageSetToDirectory writes all pods in a coverage set to subdirectories
func WriteMetaFileContent ¶
--- Runtime Data Emission ---
func WritePodToDirectory ¶
WritePodToDirectory writes a pod's data to files in the specified directory
func WriteProfileToDirectory ¶
WriteProfileToDirectory writes a profile's metadata and counter data to separate files in the specified directory
Types ¶
type CounterDataSegment ¶
type CounterDataSegment = coverage.CounterDataSegment
type CounterFile ¶
type CounterFile = coverage.CounterFile
func LoadCounterFile ¶
func LoadCounterFile(r io.Reader, filePath string) (*CounterFile, error)
LoadCounterFile parses a single counter data file.
type CounterGranularity ¶
type CounterGranularity = coverage.CounterGranularity
type CounterMode ¶
type CounterMode = coverage.CounterMode
type CoverableUnit ¶
type CoverableUnit = coverage.CoverableUnit
type CoverageSet ¶
type CoverageSet struct { Pods []*Pod // contains filtered or unexported fields }
CoverageSet manages a collection of Pods and implements fs.FS. It presents coverage data as a Plan 9-style virtual filesystem where:
/pods/ - All pods by ID /pods/<id>/metadata.json - Pod metadata /pods/<id>/profile.json - Coverage profile /by-label/<key>/<value>/ - Pods filtered by label /by-package/<path>/ - Data for specific package /functions/<pkg>/<func>/ - Individual function data /summary/ - Aggregate summaries
func LoadCoverageSet ¶
func LoadCoverageSet(fsys fs.FS, opts ...LoadOption) (*CoverageSet, error)
LoadCoverageSet scans an fs.FS for coverage files and loads them. It identifies groups of meta and counter files (internal pods) and transforms them into public Pod structures containing Profiles.
Use fs.Sub if you need to target a specific subdirectory:
subFS, _ := fs.Sub(os.DirFS("/path"), "covdata") set, _ := LoadCoverageSet(subFS, WithLogger(logger))
For updates/refreshes, simply call this function again with the same or updated filesystem - it will re-scan and return fresh data.
func (*CoverageSet) FilterByLabel ¶
func (cs *CoverageSet) FilterByLabel(matchLabels map[string]string) (*CoverageSet, error)
FilterByLabel returns a new CoverageSet containing pods that match all provided labels.
func (*CoverageSet) FilterByPath ¶
func (cs *CoverageSet) FilterByPath(prefixes ...string) (*CoverageSet, error)
FilterByPath returns a new CoverageSet with pods and profiles filtered by package path prefixes.
func (*CoverageSet) Merge ¶
func (cs *CoverageSet) Merge() (*Pod, error)
Merge aggregates all pods in the CoverageSet into a single summary Pod.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
--- Formatting ---
func NewFormatter ¶
func NewFormatter(mode CounterMode) *Formatter
func (*Formatter) AddPodProfile ¶
func (*Formatter) WriteFuncSummaryReport ¶
func (f *Formatter) WriteFuncSummaryReport(w io.Writer, opts FuncSummaryReportOptions) error
func (*Formatter) WritePercentReport ¶
func (f *Formatter) WritePercentReport(w io.Writer, opts PercentReportOptions) error
func (*Formatter) WriteTextualReport ¶
func (f *Formatter) WriteTextualReport(w io.Writer, opts TextualReportOptions) error
type FuncSummaryReportOptions ¶
type FuncSummaryReportOptions struct { }
type FunctionCounters ¶
type FunctionCounters = coverage.FunctionCounters
type Link ¶
type Link struct { Type string // e.g., "git_commit", "git_repo", "pprof_profile", "go_trace", "source_ref", "issue_tracker" URI string // Uniform Resource Identifier (e.g., commit SHA, repo URL, file path with line, ticket URL) Desc string // Optional description (e.g., "Source at time of test", "Performance profile for this run") }
Link defines a typed link to an external artifact or concept.
type LoadOption ¶
type LoadOption func(*loadConfig)
LoadOption configures coverage loading behavior
func WithLogger ¶
func WithLogger(logger *slog.Logger) LoadOption
WithLogger sets the logger for warnings and diagnostics
func WithMaxDepth ¶
func WithMaxDepth(depth int) LoadOption
WithMaxDepth sets the maximum directory depth to search (default: unlimited)
type PackageMeta ¶
type PackageMeta = coverage.PackageMeta
type PercentReportOptions ¶
type PkgFuncKey ¶
type PkgFuncKey = coverage.PkgFuncKey
PkgFuncKey identifies a function within a package for counter lookup.
type Pod ¶
type Pod struct { ID string // Unique identifier for this pod Profile *Profile // The actual coverage data Labels map[string]string // User-defined labels (test_name, os, arch, build_id) Links []Link // Links to related artifacts Source *SourceInfo // Source control information relevant to this pod's data Timestamp time.Time // When this coverage data was generated or collected SubPods []*Pod // For hierarchical data (e.g., subtests) // contains filtered or unexported fields }
Pod represents a coherent set of coverage data, typically one meta-data file and its associated counter files, enriched with labels, links, and timing.
type Profile ¶
type Profile struct { Meta MetaFile Counters map[PkgFuncKey][]uint32 Args map[string]string }
Profile holds a consistent set of coverage meta-data and aggregated counters.
func IntersectProfiles ¶
func MergeProfiles ¶
func SubtractProfile ¶
type SourceInfo ¶
type SourceInfo struct { RepoURI string // e.g., "https://github.com/user/repo.git" CommitSHA string // Full commit SHA CommitTime time.Time // Time of the commit Branch string // Optional branch name Tag string // Optional tag name Dirty bool // True if the working directory was dirty when data was generated }
SourceInfo can hold source control details.
type TextualReportOptions ¶
type TextualReportOptions struct{ TargetPackages []string }
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
covforest
command
Covforest is a program for managing and analyzing multiple coverage trees from different machines, repositories, and timelines.
|
Covforest is a program for managing and analyzing multiple coverage trees from different machines, repositories, and timelines. |
covtree-web
command
Covtree-web is a standalone web server for interactive coverage data exploration.
|
Covtree-web is a standalone web server for interactive coverage data exploration. |
covutil
command
Command covutil provides utilities for working with Go coverage data.
|
Command covutil provides utilities for working with Go coverage data. |
package coverage defines the public types for covutil, acting as an adapter/wrapper around internal representations if needed.
|
package coverage defines the public types for covutil, acting as an adapter/wrapper around internal representations if needed. |
exp
|
|
cmd/covanalyze/cmd
command
|
|
cmd/covcompare/cmd
command
|
|
cmd/covdiff/cmd
command
|
|
cmd/covdup/cmd
command
|
|
cmd/covshow
This tool takes a function name and outputs the source code with annotations for lines not covered by scripttest tests.
|
This tool takes a function name and outputs the source code with annotations for lines not covered by scripttest tests. |
cmd/covshow/cmd
command
|
|
cmd/covzero/cmd
command
|
|
internal
|
|
coverage/cfile
Package cfile implements management of coverage files.
|
Package cfile implements management of coverage files. |
covforest
Package covforest provides functionality for managing multiple coverage trees from different sources (machines, repositories, timelines).
|
Package covforest provides functionality for managing multiple coverage trees from different sources (machines, repositories, timelines). |
covtree
Package covtree provides functionality for analyzing and visualizing Go coverage data in a hierarchical tree structure.
|
Package covtree provides functionality for analyzing and visualizing Go coverage data in a hierarchical tree structure. |
runtime/exithook
Package exithook provides a mechanism to execute functions at program exit.
|
Package exithook provides a mechanism to execute functions at program exit. |
testenv
Package testenv provides a mock of Go's internal/testenv for testing purposes
|
Package testenv provides a mock of Go's internal/testenv for testing purposes |
utils/mkcoveragealiases
command
Command mkcoveragealiases creates a mirror of a subset of packages + exported symbols from internal/coverage into ./coverage/.
|
Command mkcoveragealiases creates a mirror of a subset of packages + exported symbols from internal/coverage into ./coverage/. |
utils/rewriteimports
command
Command rewriteimports rewrites import paths in Go files.
|
Command rewriteimports rewrites import paths in Go files. |
Package synthetic provides comprehensive functionality for generating synthetic coverage data for non-Go artifacts such as scripts, configuration files, templates, and other resources.
|
Package synthetic provides comprehensive functionality for generating synthetic coverage data for non-Go artifacts such as scripts, configuration files, templates, and other resources. |
parsers
Package parsers provides a modular, extensible architecture for script parsing in the synthetic coverage system.
|
Package parsers provides a modular, extensible architecture for script parsing in the synthetic coverage system. |
parsers/bash
Package bash provides a parser for Bash scripts with advanced syntax support.
|
Package bash provides a parser for Bash scripts with advanced syntax support. |
parsers/defaults
Package defaults registers all built-in parsers with the default registry.
|
Package defaults registers all built-in parsers with the default registry. |
parsers/gotemplate
Package gotemplate provides a parser for Go template files.
|
Package gotemplate provides a parser for Go template files. |
parsers/python
Package python provides a parser for Python scripts.
|
Package python provides a parser for Python scripts. |
parsers/scripttest
Package scripttest provides a comprehensive parser for Go's scripttest format.
|
Package scripttest provides a comprehensive parser for Go's scripttest format. |
parsers/shell
Package shell provides a parser for POSIX shell scripts.
|
Package shell provides a parser for POSIX shell scripts. |