lxd: github.com/lxc/lxd/shared/log15/stack Index | Files

package stack

import "github.com/lxc/lxd/shared/log15/stack"

Package stack implements utilities to capture, manipulate, and format call stacks.

Index

Package Files

stack.go stack_pool.go

type Call Uses

type Call uintptr

Call records a single function invocation from a goroutine stack. It is a wrapper for the program counter values returned by runtime.Caller and runtime.Callers and consumed by runtime.FuncForPC.

func (Call) Format Uses

func (pc Call) Format(s fmt.State, c rune)

Format implements fmt.Formatter with support for the following verbs.

%s    source file
%d    line number
%n    function name
%v    equivalent to %s:%d

It accepts the '+' and '#' flags for most of the verbs as follows.

%+s   path of source file relative to the compile time GOPATH
%#s   full path of source file
%+n   import path qualified function name
%+v   equivalent to %+s:%d
%#v   equivalent to %#s:%d

type Trace Uses

type Trace []Call

Trace records a sequence of function invocations from a goroutine stack.

func Callers Uses

func Callers() Trace

Callers returns a Trace for the current goroutine with element 0 identifying the calling function.

func (Trace) Format Uses

func (pcs Trace) Format(s fmt.State, c rune)

Format implements fmt.Formatter by printing the Trace as square brackes ([, ]) surrounding a space separated list of Calls each formatted with the supplied verb and options.

func (Trace) TrimAbove Uses

func (pcs Trace) TrimAbove(pc Call) Trace

TrimAbove returns a slice of the Trace with all entries above pc removed.

func (Trace) TrimAboveName Uses

func (pcs Trace) TrimAboveName(name string) Trace

TrimAboveName returns a slice of the Trace with all entries above the highest with function name name removed.

func (Trace) TrimBelow Uses

func (pcs Trace) TrimBelow(pc Call) Trace

TrimBelow returns a slice of the Trace with all entries below pc removed.

func (Trace) TrimBelowName Uses

func (pcs Trace) TrimBelowName(name string) Trace

TrimBelowName returns a slice of the Trace with all entries below the lowest with function name name removed.

func (Trace) TrimRuntime Uses

func (pcs Trace) TrimRuntime() Trace

TrimRuntime returns a slice of the Trace with the topmost entries from the go runtime removed. It considers any calls originating from files under GOROOT as part of the runtime.

Bugs

Subtracting one from pc is a work around for https://code.google.com/p/go/issues/detail?id=7690. The idea for this work around comes from rsc's initial patch at https://codereview.appspot.com/84100043/#ps20001, but as noted in the issue discussion, it is not a complete fix since it doesn't handle some cases involving signals. Just the same, it handles all of the other cases I have tested.

Package stack imports 5 packages (graph) and is imported by 7 packages. Updated 2017-11-13. Refresh now. Tools for package owners.