Documentation
¶
Overview ¶
Package procstats samples what this install is costing the machine: the desktop process, the processes it parents (a terminal's shell, an agent), and the Go runtime's own view of itself.
The process numbers and the Go numbers answer different questions and are kept apart deliberately: RSS is what the OS charges for, while heap-in-use is what this program asked for, and on a cgo-heavy shell the gap between them is the native side — the part the Go runtime cannot see.
What the walk cannot reach: on macOS the WebKit processes that render the UI are XPC services launchd parents, not children of this process, and their only link back to the app is a responsible-pid the public API does not expose. They are excluded rather than guessed at — a WebContent process on the machine may well belong to another app.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GoRuntime ¶
type GoRuntime struct {
Goroutines int `json:"goroutines"`
GOMAXPROCS int `json:"gomaxprocs"`
NumCPU int `json:"numCpu"`
HeapAllocBytes uint64 `json:"heapAllocBytes"`
HeapSysBytes uint64 `json:"heapSysBytes"`
HeapObjects uint64 `json:"heapObjects"`
StackSysBytes uint64 `json:"stackSysBytes"`
TotalSysBytes uint64 `json:"totalSysBytes"`
NextGCBytes uint64 `json:"nextGcBytes"`
GCCount uint32 `json:"gcCount"`
LastGCUnixMs int64 `json:"lastGcUnixMs"`
LastPauseMs float64 `json:"lastPauseMs"`
TotalPauseMs float64 `json:"totalPauseMs"`
}
GoRuntime is the Go runtime's own accounting for this process.
type Process ¶
type Process struct {
PID int32 `json:"pid"`
Name string `json:"name"`
// RSSBytes is resident set size — the memory the OS is actually holding
// for this process, which is the number Activity Monitor shows.
RSSBytes uint64 `json:"rssBytes"`
// CPUPercent is the share of one core used since the previous sample, so
// it can exceed 100 on a process using several cores. The first sample for
// a process reports its average since it started, there being nothing to
// difference against yet.
CPUPercent float64 `json:"cpuPercent"`
Threads int32 `json:"threads"`
}
Process is one sampled OS process.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler holds the previous sample so CPU can be reported as a rate. It is safe for concurrent use; a UI polling it and a report assembling one at the same time must not race on the mark table.
func (*Sampler) RegisterMetrics ¶
func (s *Sampler) RegisterMetrics() metric.Registration
RegisterMetrics samples this process tree during each metric collection. The caller must unregister the returned callback when the sampler is no longer in use.
type Stats ¶
type Stats struct {
SampledAt time.Time `json:"sampledAt"`
UptimeMs int64 `json:"uptimeMs"`
Process Process `json:"process"`
// Children is the process tree below this one, biggest first — the part a
// Go-only view misses entirely.
Children []Process `json:"children"`
// ChildrenTruncated reports that the tree was larger than the walk's cap,
// so the totals below are a floor rather than the whole picture.
ChildrenTruncated bool `json:"childrenTruncated"`
Go GoRuntime `json:"go"`
}
Stats is one sample: the app process, its descendants, and the Go runtime.
func (Stats) TotalCPUPercent ¶
TotalCPUPercent is the whole tree's CPU share, this process included.
func (Stats) TotalRSSBytes ¶
TotalRSSBytes is the whole tree's resident memory, this process included.