trace

package
v1.0.37 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 16 Imported by: 1

README

Trace

Trace is a powerful tool to visualize the execution of go programs.

It helps you understand what's your code do in depth, literally.

Example

Documentation

Index

Constants

View Source
const DefaultAppearanceLimit = 100

default appearance limit on repeative functions

View Source
const DefaultSizeLimit = 16 * 1024

default size to shrink 16K

Variables

This section is empty.

Functions

func Begin added in v1.0.23

func Begin() func()

func Collect added in v1.0.6

func Collect(f func())

executes f and collect its trace by default trace output will be controlled by XGO_TRACE_OUTPUT

func Enable added in v1.0.3

func Enable() func()

Enable setup the trace interceptor if called from init, the interceptor is enabled globally. Otherwise locally

func MarshalAnyJSON added in v1.0.20

func MarshalAnyJSON(v interface{}) ([]byte, error)

MarshalAnyJSON marshals aribitray go value `v` to JSON, when it encounters unmarshalable values like func, chan, it will bypass these values.

func Options added in v1.0.6

func Options() *collectOpts

func SetMarshalStack added in v1.0.2

func SetMarshalStack(fn func(root *Root) ([]byte, error))

func WriteFile added in v1.0.17

func WriteFile(name string, data []byte, perm fs.FileMode) error

Types

type ErrSilent added in v1.0.23

type ErrSilent struct {
	Data interface{}
}

make json err silent

func (*ErrSilent) MarshalJSON added in v1.0.23

func (c *ErrSilent) MarshalJSON() (data []byte, err error)

type ExportOptions added in v1.0.23

type ExportOptions struct {
	// suppress error when marshalling
	// arguments and results
	DisableErrSilent bool
	SizeLimit        int // 0: default limit 16K
	AppearanceLimit  int // 0: default limit 100

	FilterStack func(stack *StackExport) *StackExport

	FilterRoot  func(root *RootExport) *RootExport
	MarshalRoot func(root *RootExport) ([]byte, error)
	// contains filtered or unexported fields
}

allow skip some packages

for example: google.golang.org/protobuf/internal/order

type FuncInfoExport added in v1.0.3

type FuncInfoExport struct {
	// FullName string
	Kind         FuncKind
	Pkg          string
	IdentityName string
	Name         string
	RecvType     string
	RecvPtr      bool

	// interface method?
	Interface bool
	Generic   bool
	Closure   bool
	Stdlib    bool

	File string
	Line int

	RecvName string
	ArgNames []string
	ResNames []string

	// is first argument ctx
	FirstArgCtx bool
	// last last result error
	LastResultErr bool
}

func ExportFuncInfo added in v1.0.3

func ExportFuncInfo(c *core.FuncInfo, opts *ExportOptions) *FuncInfoExport

type FuncKind added in v1.0.36

type FuncKind string
const (
	FuncKind_Func   FuncKind = "func"
	FuncKind_Var    FuncKind = "var"
	FuncKind_VarPtr FuncKind = "var_ptr"
	FuncKind_Const  FuncKind = "const"
)

type LimitSize added in v1.0.23

type LimitSize struct {
	Data  interface{}
	Limit int
}

make json err silent

func (*LimitSize) MarshalJSON added in v1.0.23

func (c *LimitSize) MarshalJSON() ([]byte, error)

type Root

type Root struct {
	// current executed function
	Top      *Stack
	Begin    time.Time
	Children []*Stack
}

func (*Root) Export added in v1.0.3

func (c *Root) Export(opts *ExportOptions) *RootExport

type RootExport added in v1.0.3

type RootExport struct {
	// current executed function
	Begin    time.Time
	Children []*StackExport
}

type Stack

type Stack struct {
	FuncInfo *core.FuncInfo

	Begin int64 // us
	End   int64 // us

	Args     core.Object
	Results  core.Object
	Panic    bool
	Error    error
	Children []*Stack
}

func (*Stack) Export added in v1.0.3

func (c *Stack) Export(opts *ExportOptions) *StackExport

type StackExport added in v1.0.3

type StackExport struct {
	FuncInfo *FuncInfoExport

	Begin int64 // us
	End   int64 // us

	Args    interface{}
	Results interface{}
	Panic   bool
	Error   string

	Children []*StackExport
}

Jump to

Keyboard shortcuts

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