stackdump

package
v0.107.30 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package stackdump writes every goroutine's stack to a file in the K-brain log directory, without stopping the process, so a frozen kn or kn backend can be diagnosed: on SIGUSR1 (Unix), on GET /v1/debug/stacks (backend), and automatically when a watchdog sees the UI loop or the backend stall.

Index

Constants

View Source
const Prefix = "stacks-"

Prefix starts every dump file name: stacks-<timestamp>-<pid>.txt.

View Source
const SignalSupported = true

SignalSupported reports whether OnSignal can dump on a signal here.

Variables

This section is empty.

Functions

func Capture

func Capture() []byte

Capture returns every goroutine's stack.

func Dir

func Dir() (string, error)

Dir is the directory dumps are written to, the one k-brain.log is in.

func List

func List(dir string) []string

List returns the dumps in dir, oldest first.

func OnSignal

func OnSignal(report func(path string, err error)) (stop func())

OnSignal writes a dump each time the process receives SIGUSR1 and calls report with the outcome (report may be nil). The process keeps running. The returned function stops listening.

func Signal

func Signal(pid int) error

Signal asks process pid to write a dump.

func Write

func Write(reason string) (string, error)

Write dumps every goroutine's stack into Dir and returns the file's path. reason is recorded in the header and in k-brain.log.

func WriteIn

func WriteIn(dir, reason string) (string, error)

WriteIn is Write into dir.

Types

type Watchdog

type Watchdog struct {
	Name     string
	Interval time.Duration
	Timeout  time.Duration
	// Probe returns once the watched loop or lock has made progress. It must
	// return when ctx is cancelled.
	Probe func(ctx context.Context)
	// Paused, when set, reports a state in which the watched loop is blocked
	// on purpose (an external editor in the foreground); time spent paused
	// does not count.
	Paused func() bool
	// MaxDumps bounds the dumps per process; 0 means 3.
	MaxDumps int
	// OnStall is called after a stall's dump with its outcome (tests, logs).
	OnStall func(path string, err error)
	// Write writes the dump; nil uses stackdump.Write.
	Write func(reason string) (string, error)
}

Watchdog runs Probe every Interval. When a probe has not returned after Timeout, it writes one dump for that stall and logs a warning; the next stall, after a probe has returned again, may dump again, up to MaxDumps.

func (*Watchdog) Start

func (w *Watchdog) Start(ctx context.Context)

Start runs the watchdog until ctx is cancelled.

Jump to

Keyboard shortcuts

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