Help us shape the future of Go! Take the 2026 Go Developer Survey

profiling

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package profiling writes the runtime profiles one grafo run was asked for.

Every profile is opt-in and absent by default, because each one costs something: the CPU and trace profiles install a sampler for the whole run, and the block and mutex profiles make the runtime record contention events it otherwise ignores. A run that asks for none pays nothing and takes no different path than before.

The profiles are the standard ones `go tool pprof` and `go tool trace` read, at the rates the Go toolchain's own flags use, so a reader who knows `go test -cpuprofile` already knows what these contain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	CPUPath    string
	MemoryPath string
	BlockPath  string
	MutexPath  string
	TracePath  string
}

Options names the file each profile is written to. An empty path leaves that profile off, which is what every run that did not ask for one passes.

func (Options) Requested

func (o Options) Requested() bool

Requested reports whether any profile was asked for, so a caller can skip the session entirely rather than start one that does nothing.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session owns the files a started profiling run writes and the runtime state it changed. Stop returns both to where they were.

func Start

func Start(options Options) (*Session, error)

Start opens every requested profile's file and installs the samplers that have to run for the whole command.

Opening the files first is deliberate: a profile is asked for precisely when the run is expensive, and discovering an unwritable path after a cold index has finished wastes the only run the caller cared about. A failure here leaves nothing installed and no file open.

func (*Session) Stop

func (s *Session) Stop() error

Stop writes the snapshot profiles, uninstalls the samplers, and closes every file. It attempts all of them and joins their errors, so one unwritable profile does not cost the others: a caller that asked for several has already paid for the run that produced them.

A nil session stops nothing, which is what a run that requested no profile holds.

Jump to

Keyboard shortcuts

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