memwatch

package
v0.0.0-...-f09cf9b Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B   = 1
	KiB = 1 << (10 * iota) // 2^10
	MiB = 1 << (10 * iota) // 2^20
	GiB = 1 << (10 * iota) // 2^30
	TiB = 1 << (10 * iota) // 2^40
)
View Source
const (
	MappingDelayInS = 2
)

Variables

View Source
var (
	ErrNotEnoughMemory   = fmt.Errorf("not enough memory")
	ErrNotEnoughMappings = fmt.Errorf("not enough memory mappings")
)

Functions

func EstimateObjectDeleteMemory

func EstimateObjectDeleteMemory() int64

func EstimateObjectMemory

func EstimateObjectMemory(object *models.Object) int64

func EstimateStorObjectMemory

func EstimateStorObjectMemory(object *storobj.Object) int64

func LiveHeapReader

func LiveHeapReader() int64

Types

type AllocChecker

type AllocChecker interface {
	CheckAlloc(sizeInBytes int64) error
	CheckMappingAndReserve(numberMappings int64, reservationTimeInS int) error
	Refresh(updateMappings bool)
}

type Monitor

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

Monitor allows making statements about the memory ratio used by the application

func NewDummyMonitor

func NewDummyMonitor() *Monitor

func NewMonitor

func NewMonitor(metricsReader metricsReader, limitSetter limitSetter,
	maxRatio float64,
) *Monitor

NewMonitor creates a Monitor with the given metrics reader and target ratio

Typically this would be called with LiveHeapReader and debug.SetMemoryLimit

func (*Monitor) CheckAlloc

func (m *Monitor) CheckAlloc(sizeInBytes int64) error

func (*Monitor) CheckMappingAndReserve

func (m *Monitor) CheckMappingAndReserve(numberMappings int64, reservationTimeInS int) error

func (*Monitor) Ratio

func (m *Monitor) Ratio() float64

func (*Monitor) Refresh

func (m *Monitor) Refresh(updateMappings bool)

Refresh retrieves the current memory stats from the runtime and stores them in the local cache

Jump to

Keyboard shortcuts

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