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

processusage

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package processusage samples CPU time and resident memory for this process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sample

type Sample struct {
	CPUPercent          *float64
	ResidentMemoryBytes *int64
}

Sample reports unavailable measurements as nil. CPUPercent measures process CPU time against elapsed wall time: one busy core is 100 percent.

type Sampler

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

Sampler serializes reads and shares a sample for at least one second. It owns no workers or handles; CPU needs two successful reads before it is available.

func New

func New() *Sampler

New binds the sampler to this process, without enumerating other processes or reading arguments, environment variables or other process metadata.

func (*Sampler) Snapshot

func (s *Sampler) Snapshot(ctx context.Context) Sample

Snapshot reads at most once per interval. Failed measurements do not hide a successful independent measurement. Cancellation never replaces the cache or CPU baseline; callers can retry with a live context.

Jump to

Keyboard shortcuts

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