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 ¶
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 ¶
ResidentBytes returns the current resident set size of pid in bytes, or 0 when the platform cannot report it.
Types ¶
type Process ¶
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 (Process) Command ¶
Command answers the process's argv joined for a report, or its identifier when the platform gave no arguments.
func (Process) Invocation ¶
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
// 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.