profiling

package
v0.0.0-...-6a04f06 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBlockProfileRate = 10_000_000 // ns
	DefalutMutexProfileRate = 100        // 1/100 events
)

Variables

This section is empty.

Functions

func Init

func Init(config *Config) error

Init initializes the profiling service, uses the default config when config is nil.

func Load

func Load(path string) error

Load loads a profiling config from a json/yaml file if it exists and initializes the profiling service.

func Start

func Start() error

Start starts enabled profilers.

func Stop

func Stop() error

Stop stops running profilers, writes all profiles to disk.

Types

type BlockConfig

type BlockConfig struct {
	Enabled bool   `json:"enabled"`
	Path    string `json:"path"`

	// SetBlockProfileRate controls the fraction of goroutine blocking events
	// That are reported in the blocking profile. The profiler aims to sample
	// An average of one blocking event per rate nanoseconds spent blocked.
	//
	// To include every blocking event in the profile, pass rate = 1.
	//
	// 0 means the default rate (10_000_000 ns), see runtime.SetBlockProfileRate.
	Rate int `json:"rate"`
}

type CPUConfig

type CPUConfig struct {
	Enabled bool   `json:"enabled"`
	Path    string `json:"path"`

	// Rate sets the CPU profiling rate to hz samples per second.
	//
	// 0 means the default rate (100 hz), see runtime.SetCPUProfileRate.
	Rate int `json:"rate"`
}

type Config

type Config struct {
	Enabled bool         `json:"enabled"`
	CPU     CPUConfig    `json:"cpu"`
	Memory  MemoryConfig `json:"memory"`
	Block   BlockConfig  `json:"block"`
	Mutex   MutexConfig  `json:"mutex"`
}

Config specifies a profiling configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default profiling config.

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig reads a profiling config from a JSON or YAML file.

type MemoryConfig

type MemoryConfig struct {
	Enabled bool   `json:"enabled"`
	Path    string `json:"path"`

	// Rate controls the fraction of memory allocations that are recorded
	// And reported in the memory profile. The profiler aims to sample
	// An average of one allocation per MemProfileRate bytes allocated.
	//
	// To include every allocated block in the profile, set MemProfileRate to 1.
	//
	// 0 means the default rate (512 kb), see runtime.SetMemProfileRate.
	Rate int `json:"rate"`
}

type MutexConfig

type MutexConfig struct {
	Enabled bool   `json:"enabled"`
	Path    string `json:"path"`

	// Rate controls the fraction of mutex contention events that are reported
	// In the mutex profile. On average 1/rate events are reported.
	//
	// 0 means the default rate (1/100), see runtime.SetMutexProfileFraction.
	Rate int `json:"rate"`
}

Jump to

Keyboard shortcuts

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