procmon

package
v0.1.61 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 5 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 procmon samples live CPU/memory for the daemon's per-turn process groups, on demand.

Every turn runs in its own process group (see internal/proc); the group-leader pid is the whole process tree for that turn (bash → node → claude/codex/opencode). The Supervisor Track()s a turn's group-leader pid for the turn's lifetime and Untrack()s it at teardown, labelling it (agent, chatId, runId). A Monitor samples every tracked group on a ticker and broadcasts Frames to subscribers — but ONLY while at least one subscriber is connected: the sampler goroutine starts on the first Subscribe and stops on the last unsubscribe. So an idle daemon that nobody is watching does ZERO background work (no goroutine, no /proc scans) — this is the on-demand / no-leak guarantee the console's Agent page relies on.

The sampler itself is platform-split (sample_linux.go / sample_darwin.go / sample_other.go), mirroring internal/proc; the lifecycle and delta math here are platform-independent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

type Frame struct {
	At      string   `json:"at"` // RFC3339 timestamp of the tick
	Samples []Sample `json:"samples"`
}

Frame is one sampling tick: every currently-tracked turn that had a live process this tick. An empty Samples slice (with no running turns, or between ticks) is a valid, meaningful frame.

type Monitor

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

Monitor is the refcounted shared sampler. One per Supervisor; Track/Untrack are driven by the turn lifecycle and Subscribe by SSE clients. All state is guarded by mu.

func NewMonitor

func NewMonitor() *Monitor

NewMonitor builds an idle monitor: no sampler goroutine runs until the first Subscribe.

func (*Monitor) Subscribe

func (m *Monitor) Subscribe() (ch <-chan Frame, cancel func(), ok bool)

Subscribe registers a frame channel and starts the sampler if this is the first subscriber. The returned cancel removes the subscriber and stops the sampler when the last one leaves — so sampling happens only while something is watching. ok=false if the subscriber cap is reached; the caller should serve a 503-style response and not block.

func (*Monitor) Track

func (m *Monitor) Track(runID, agent, chatID string, pid int)

Track registers a turn's process group so the next sample includes it. Called from a spawn site's reporter (via proc.Report) after the process starts; safe to call from any goroutine. Re-tracking the same runId (e.g. successive resolve child turns) just updates the pgid.

func (*Monitor) Untrack

func (m *Monitor) Untrack(runID string)

Untrack drops a turn's process group at turn teardown. Idempotent.

type Sample

type Sample struct {
	Agent      string  `json:"agent"`
	ChatID     string  `json:"chatId"`
	RunID      string  `json:"runId"`
	Pid        int     `json:"pid"`
	CPUPercent float64 `json:"cpuPercent"`
	RSSBytes   uint64  `json:"rssBytes"`
}

Sample is one running turn's live resource use at a single tick. Labels + numbers only — never any secret. RSSBytes is resident set size (physical memory) summed over the whole process group.

Jump to

Keyboard shortcuts

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