memreport

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package memreport collects per-pane memory snapshots for the daemon and exposes a human-readable formatter used by the TUI, status bar, and MCP tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HumanBytes

func HumanBytes(n uint64) string

HumanBytes renders a byte count using the largest unit whose integer part is non-zero. One decimal place for values ≥ 1 KB, no fractional part for raw bytes. Output is ASCII-safe (no multibyte characters).

Types

type Collector

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

Collector periodically scans a PaneLister and stores an atomic snapshot of per-pane memory usage.

func NewCollector

func NewCollector(lister PaneLister, every time.Duration) *Collector

NewCollector constructs a Collector but does not start it. Call Run in a goroutine.

func (*Collector) Latest

func (c *Collector) Latest() *Snapshot

Latest returns the most recent Snapshot, or nil if Run has not yet completed its first pass.

func (*Collector) Run

func (c *Collector) Run(ctx context.Context)

Run blocks until ctx is cancelled, performing one collection up front so Latest() is never nil afterwards, then on every tick.

type PaneLister

type PaneLister interface {
	PaneSources() []PaneSource
}

PaneLister is implemented by *daemon.SessionManager; the collector calls it each tick to enumerate current panes.

type PaneMem

type PaneMem struct {
	PaneID      string
	TabID       string
	GoHeapBytes uint64
	PTYRSSBytes uint64
	Total       uint64 // GoHeapBytes + PTYRSSBytes
}

PaneMem is a single pane's daemon-side memory accounting. TUI-side bytes (VT grid, notes editor) are computed by the TUI at render time and are not part of this struct.

type PaneSource

type PaneSource interface {
	Snapshot() PaneSourceSnapshot
}

PaneSource is the minimal view the collector needs over a daemon pane. Keeping this as an interface lets the daemon satisfy it externally without creating a package import cycle (memreport ↔ daemon). The single Snapshot call replaces the old seven-method interface — adapters can now grab the per-pane mutex once instead of six times per tick.

type PaneSourceSnapshot added in v1.10.2

type PaneSourceSnapshot struct {
	PaneID    string
	TabID     string
	Alive     bool
	PID       int
	HeapBytes uint64 // OutputBuf + GhostSnap + plugin-state key/value bytes
}

PaneSourceSnapshot is the per-pane view the collector needs each tick. It is intentionally a value type so the adapter can fill it under a single lock acquisition and hand back a torn-free copy.

type Snapshot

type Snapshot struct {
	At    time.Time
	Panes []PaneMem // sorted by Total desc
	Total uint64    // sum of Panes[*].Total
}

Snapshot is the collector's output, refreshed every ~5 s. Readers must treat it as immutable — the collector replaces the pointer atomically rather than mutating in place.

Jump to

Keyboard shortcuts

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