stack

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const NilG = G(uintptr(0)) // nil

Variables

View Source
var InitGStack = &Stack{}

InitGStack special stack during init

View Source
var NilGStack = &Stack{}

NilGStack is a guard pointer for when g is nil because m is just starting on g0

Functions

func Attach

func Attach(stack *Stack)

Attach attaches a stack for recording

func Detach

func Detach()

func Export

func Export(stack *Stack, offsetNS int64) *stack_model.Stack

func ExportFuncInfo

func ExportFuncInfo(entry *Entry) *stack_model.FuncInfo

func ExportStackEntries

func ExportStackEntries(entries []*Entry, rootBegin time.Time, offsetNS int64) []*stack_model.StackEntry

func ExportStackEntry

func ExportStackEntry(entry *Entry, rootBegin time.Time, offsetNS int64) *stack_model.StackEntry

Types

type Entry

type Entry struct {
	ID       int
	ParentID int

	FuncInfo *core.FuncInfo

	BeginNs  int64
	EndNs    int64
	Finished bool

	Children []*Entry
	Data     EntryData

	Go bool // has go keyword
	// only valid when Go==true
	GetStack func() *Stack

	FuncName string
	File     string
	Line     int

	HitMock   bool
	Panic     bool
	PanicLine int
	Error     string

	Args    interface{}
	Results interface{}
}

func (*Entry) GetData

func (s *Entry) GetData(key interface{}) interface{}

func (*Entry) SetData

func (s *Entry) SetData(key, value interface{})

type EntryData

type EntryData map[interface{}]interface{}

type Field

type Field struct {
	Name  string
	Value interface{}
}

type G

type G uintptr

G points to runtime.G

func GetG

func GetG() G

func (G) AttachStack

func (g G) AttachStack(stack *Stack)

func (G) DetachStack

func (g G) DetachStack()

func (G) GetOrAttachStack

func (g G) GetOrAttachStack() *Stack

func (G) GetStack

func (g G) GetStack() *Stack

type Stack

type Stack struct {

	// Begin is fixed after stack creation; safe to read without mu for
	// computing relative nanoseconds outside the lock.
	Begin      time.Time
	End        time.Time
	MaxEntryID int

	Roots []*Entry
	Top   *Entry
	Depth int

	Data map[interface{}]interface{}
	// contains filtered or unexported fields
}

Stack is a per-goroutine call tree. All tree mutations and export snapshots go through mu so concurrent Push (child) vs Export (parent) is race-free under -race (see race_export / issue #341 follow-up Phase 1).

IMPORTANT: never call instrumented functions (e.g. time.Time methods that may trap) while holding mu — trap re-enters GetData and deadlocks.

func Get

func Get() *Stack

func GetOrAttach

func GetOrAttach() *Stack

func (*Stack) AppendGoChild added in v1.2.3

func (c *Stack) AppendGoChild(beginNs int64, getStack func() *Stack)

AppendGoChild attaches a synthetic "go" node under the current Top under lock.

func (*Stack) Finish added in v1.2.3

func (c *Stack) Finish(cur *Entry, oldTop *Entry, end time.Time, setStackEnd bool, finish func(*Entry))

Finish completes an entry, restores Top, decrements Depth under lock. finish must not call instrumented functions (no time.Time methods, no traps).

func (*Stack) GetData

func (c *Stack) GetData(key interface{}) interface{}

func (*Stack) NewEntry

func (c *Stack) NewEntry(begin time.Time, fnName string) *Entry

func (*Stack) Push

func (c *Stack) Push(cur *Entry) *Entry

push returns the old top

func (*Stack) PushNew added in v1.2.3

func (c *Stack) PushNew(begin time.Time, fnName string, setup func(*Entry)) (cur *Entry, oldTop *Entry)

PushNew creates an entry, pushes it, runs setup, and increments Depth under one lock so the tree is never observed half-updated by Export. MaxEntryID is bumped twice (newEntry + push), matching historical NewEntry+Push.

func (*Stack) SetData

func (c *Stack) SetData(key, value interface{})

func (*Stack) SetEndIfZero added in v1.2.3

func (c *Stack) SetEndIfZero(t time.Time)

SetEndIfZero records stack end time once (goroutine exit).

func (*Stack) Snapshot added in v1.2.3

func (c *Stack) Snapshot() (begin, end time.Time, roots []*Entry)

Snapshot copies the tree for race-free export. GetStack funcs still point at the live Stack; callers Export those under their own locks. Must not invoke instrumented code while holding mu.

type StackArgs

type StackArgs []interface{}

Jump to

Keyboard shortcuts

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