memory

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package memory provides memory tracking for worker processes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats a byte count as a human-readable string

func GetOrFindWorkerPID

func GetOrFindWorkerPID(workerBinary string) (int, error)

GetOrFindWorkerPID attempts to find a worker PID by searching processes This is a fallback when the worker PID is not directly known

func GetPID

func GetPID() int

GetPID returns the PID of the current process

func GetParentPID

func GetParentPID() int

GetParentPID returns the PID of the parent process

Types

type Stats

type Stats struct {
	TotalWorkers      int       `json:"total_workers"`
	TotalRSSBytes     int64     `json:"total_rss_bytes"`
	AvgRSSBytes       int64     `json:"avg_rss_bytes"`
	PeakRSSBytes      int64     `json:"peak_rss_bytes"`
	LastUpdated       time.Time `json:"last_updated"`
	SystemTotalMB     int64     `json:"system_total_mb"`
	SystemAvailableMB int64     `json:"system_available_mb"`
	SystemUsedPercent float64   `json:"system_used_percent"`
}

Stats aggregates memory statistics across all tracked workers

type SystemMemory

type SystemMemory struct {
	TotalMB     int64   `json:"total_mb"`
	AvailableMB int64   `json:"available_mb"`
	UsedPercent float64 `json:"used_percent"`
}

SystemMemory represents system-wide memory information

func GetSystemMemory

func GetSystemMemory() (*SystemMemory, error)

GetSystemMemory retrieves system-wide memory information from /proc/meminfo.

type Tracker

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

Tracker tracks memory usage of worker processes

func NewTracker

func NewTracker() *Tracker

NewTracker creates a new memory tracker

func (*Tracker) GetStats

func (t *Tracker) GetStats() *Stats

GetStats returns aggregated memory statistics

func (*Tracker) GetWorkerMemory

func (t *Tracker) GetWorkerMemory(pid int) (*WorkerMemory, bool)

GetWorkerMemory returns memory info for a specific worker

func (*Tracker) Sample

func (t *Tracker) Sample() error

Sample samples memory usage for all tracked workers

func (*Tracker) ShouldThrottle

func (t *Tracker) ShouldThrottle(thresholdMB int64) bool

ShouldThrottle returns true if memory usage indicates we should throttle

func (*Tracker) Start

func (t *Tracker) Start()

Start starts the background sampling goroutine

func (*Tracker) Track

func (t *Tracker) Track(pid int)

Track adds a worker process to be tracked

func (*Tracker) Untrack

func (t *Tracker) Untrack(pid int)

Untrack removes a worker process from tracking

type WorkerMemory

type WorkerMemory struct {
	PID         int       `json:"pid"`
	RSSBytes    int64     `json:"rss_bytes"` // Resident Set Size in bytes
	VMSBytes    int64     `json:"vms_bytes"` // Virtual Memory Size in bytes
	LastUpdated time.Time `json:"last_updated"`
	SampleCount int       `json:"sample_count"`
	PeakRSS     int64     `json:"peak_rss"` // Peak RSS observed
}

WorkerMemory represents memory metrics for a worker process

func GetProcessMemory

func GetProcessMemory(pid int) (*WorkerMemory, error)

GetProcessMemory retrieves memory usage for a process by PID using /proc/[pid]/statm.

func GetSelfMemory

func GetSelfMemory() (*WorkerMemory, error)

GetSelfMemory returns memory usage of the current process

Jump to

Keyboard shortcuts

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