procstat

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package procstat reads live process statistics from the operating system.

The observations are best effort: a zero value means the platform could not answer, never that the process used no memory. Callers that publish a metric must treat zero as "unknown" and say so.

Index

Constants

This section is empty.

Variables

View Source
var ErrProcessListUnsupported = errors.New("procstat: this platform cannot enumerate processes")

ErrProcessListUnsupported reports that this build cannot enumerate processes. It is a declared limitation rather than an empty answer: a command that stops processes must not report success because it could not see any.

Functions

func ProportionalSupported added in v0.2.1

func ProportionalSupported() bool

ProportionalSupported reports whether this build can divide shared memory between the processes holding it.

A reader has to be told, because the alternative is reading a resident size as a cost and concluding that mapping a file made a server more expensive when it made the machine cheaper.

func ResidentBytes

func ResidentBytes(pid int) int64

ResidentBytes returns the current resident set size of pid in bytes, or 0 when the platform cannot report it.

Types

type Process

type Process struct {
	PID  int
	Args []string
}

Process is one live process, named by the arguments it was started with.

Only processes this user can read are listed. Enumerating another user's arguments needs privileges this tool does not want, and a process it cannot read is one it could not signal either.

func List

func List() ([]Process, error)

List returns every process of this user that the platform can describe.

func (Process) Command

func (process Process) Command() string

Command answers the process's argv joined for a report, or its identifier when the platform gave no arguments.

func (Process) Invocation

func (process Process) Invocation() (program, command string)

Invocation reports the executable's base name and its first argument, which is what distinguishes `kivgraph serve` from `kivgraph index`.

type Sample added in v0.2.1

type Sample struct {
	// Resident is what the process has in memory right now, shared pages
	// included, which is what `ps` and `top` show and what misleads.
	Resident int64
	// Proportional is the process's share of every page it holds: a page mapped
	// by three processes counts a third here. Zero on a platform that cannot
	// divide it.
	Proportional int64
	// SharedClean is memory the process reads and does not own -- the executable,
	// the shared libraries, a mapped snapshot.
	SharedClean int64
	// PrivateDirty is memory only this process holds, which is what it would
	// stop costing if it exited.
	PrivateDirty int64
	// Peak is the high-water mark of resident memory over the process's life. It
	// is what sizes a machine, because a server that peaks at a gigabyte needs
	// that gigabyte even if it parks at a tenth of it.
	Peak int64
	// CPU is processor time consumed, user and system together.
	CPU time.Duration
	// Uptime is how long the process has been running.
	Uptime time.Duration
}

Sample is one observation of a live process.

Every field is best effort and zero means the platform could not answer, never that the process used none. The distinction matters most for the three shared-memory fields: a process that maps a published snapshot counts every page it touched as resident, so three servers reading one generation each report all of it. Proportional is that page divided by the processes holding it, which is what the machine actually spends.

func Observe added in v0.2.1

func Observe(pid int) Sample

Observe answers one sample of pid.

Jump to

Keyboard shortcuts

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