runtime

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: ISC Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// GetBufferPool retrieves a buffer from the pool, creating one if necessary.
	GetBufferPool = _pool.Get
)

Functions

func Take

func Take(skip int) string

Take returns a string representation of the current stacktrace.

skip is the number of frames to skip before recording the stack trace. skip=0 identifies the caller of Take.

Types

type Caller

type Caller struct {
	Function string
	File     string
	Line     int
}

func GetStackTrace

func GetStackTrace(addCaller, addStack bool, skip int) (*Caller, string, error)

GetStackTrace return Caller and stack string, you can only use stack or caller

type Depth

type Depth int

Depth specifies how deep of a stack trace should be captured.

const (
	// First captures only the first frame.
	First Depth = iota

	// Full captures the entire call stack, allocating more
	// storage for it if needed.
	Full
)

type Formatter

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

Formatter formats a stack trace into a readable string representation.

func NewFormatter

func NewFormatter(b *buffer.Buffer) Formatter

NewFormatter builds a new Formatter.

func (*Formatter) FormatFrame

func (sf *Formatter) FormatFrame(frame runtime.Frame)

FormatFrame formats the given frame.

func (*Formatter) FormatStack

func (sf *Formatter) FormatStack(stack *Stack)

FormatStack formats all remaining frames in the provided stacktrace -- minus the final runtime.main/runtime.goexit frame.

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

A Pool is a generic wrapper around sync.Pool to provide strongly-typed object pooling.

Note that SA6002 (ref: https://staticcheck.io/docs/checks/#SA6002) will not be detected, so all internal pool use must take care to only store pointer types.

func NewPool

func NewPool[T any](fn func() T) *Pool[T]

NewPool returns a new Pool for T, and will use fn to construct new Ts when the pool is empty.

func (*Pool[T]) Get

func (p *Pool[T]) Get() T

Get gets a T from the pool, or creates a new one if the pool is empty.

func (*Pool[T]) Put

func (p *Pool[T]) Put(x T)

Put returns x into the pool.

type Stack

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

Stack is a captured stack trace.

func Capture

func Capture(skip int, depth Depth) *Stack

Capture captures a stack trace of the specified depth, skipping the provided number of frames. skip=0 identifies the caller of Capture.

The caller must call Free on the returned stacktrace after using it.

func (*Stack) Count

func (st *Stack) Count() int

Count reports the total number of frames in this stacktrace. Count DOES NOT change as Next is called.

func (*Stack) Free

func (st *Stack) Free()

Free releases resources associated with this stacktrace and returns it back to the pool.

func (*Stack) Next

func (st *Stack) Next() (_ runtime.Frame, more bool)

Next returns the next frame in the stack trace, and a boolean indicating whether there are more after it.

Jump to

Keyboard shortcuts

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