Documentation
¶
Overview ¶
Package procs reads what processes on this computer use — memory and CPU time from ps, the whole machine's memory and CPU from the system — and adds them up by process tree. The TUI's resource monitor and the phone gateway's GET /api/resources both count conch this way: a pane is its program and everything that program started.
Index ¶
- Variables
- func BusyPercent(prev, cur Ticks) (float64, bool)
- func Children(procs map[int]Proc) map[int][]int
- func Elapsed(prev, cur *Sample) (time.Duration, bool)
- func Parse(out []byte) map[int]Proc
- func ParseCPUTime(s string) (time.Duration, bool)
- func Spent(prev, cur *Sample, pid int) time.Duration
- func Tree(root int, children map[int][]int, procs map[int]Proc, claimed map[int]bool) []int
- func Used(prev, cur *Sample, pids []int) time.Duration
- type Memory
- type Proc
- type Sample
- type Ticks
Constants ¶
This section is empty.
Variables ¶
var RunPS = func(ctx context.Context) ([]byte, error) { return exec.CommandContext(ctx, "ps", "-A", "-o", "pid=,ppid=,rss=,time=,comm=").Output() }
RunPS lists every process; tests replace it.
Functions ¶
func BusyPercent ¶
BusyPercent is how busy the computer was between two readings, 0–100.
func Elapsed ¶
Elapsed is the time between two samples, when CPU use can be worked out from them: there is an earlier sample, it did not fail, and the clock went forward.
func ParseCPUTime ¶
ParseCPUTime reads ps's time column: [DD-][HH:]MM:SS[.ss]. Linux prints 00:01:02, macOS 1:02.34 (minutes may pass 59 there).
Types ¶
type Memory ¶
type Memory struct {
Total, Used int64
}
Memory is the whole computer's memory, in bytes.
Used is memory nothing else can have without something being pushed out: on Linux MemTotal - MemAvailable, which is what free(1) calls used; on macOS app memory (anonymous pages less purgeable ones) + wired + what the compressor occupies, which is Activity Monitor's "Memory Used". Neither counts the file cache, which the system gives back as it is needed.
func ParseMeminfo ¶
ParseMeminfo reads /proc/meminfo. A kernel older than MemAvailable (3.14) is given free + buffers + cache as available.
func ParseVMStat ¶
ParseVMStat reads vm_stat's pages with total, from hw.memsize: used is app memory + wired + compressed, as Activity Monitor adds it up. An older vm_stat without anonymous pages counts active ones as the apps'.
func ReadMemory ¶
ReadMemory reads the computer's memory: /proc/meminfo on Linux, sysctl and vm_stat on macOS.
type Proc ¶
type Proc struct {
PID, PPID int
RSS int64 // resident memory, KiB
CPU time.Duration // CPU time used so far
Comm string
}
Proc is one process from ps.
type Sample ¶
Sample is every process on this computer at one moment.
type Ticks ¶
type Ticks struct {
Busy, Total uint64
}
Ticks is the whole computer's CPU time since boot, in the kernel's ticks: two of them taken apart say how busy it was in between.
func ParseProcStat ¶
ParseProcStat reads the first line of /proc/stat: user nice system idle iowait irq softirq steal, then guest time, which user already counts. Idle and waiting for disk are not busy.