utrace

package
v0.0.0-...-6e35a90 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxUserSymbolsCount is the max number of symbols probed at the same time
	MaxUserSymbolsCount = uint32(100)
	// MaxKernelSymbolsCount is the max number of kernel symbols probed at the same time
	MaxKernelSymbolsCount = uint32(500)
)
View Source
const PathMax = 350

PathMax - Maximum path length of the binary path handled by utrace

Variables

View Source
var (
	// NotEnoughDataErr indicates that the data retrieved from the perf map is not long enough
	NotEnoughDataErr = errors.New("not enough data")
	// EmptyPatternsErr indicates that both the kernel function and userspace symbol patterns are empty
	EmptyPatternsErr = errors.New("empty patterns")
	// EmptyBinaryPathErr indicates that a userspace symbol pattern was provided but without a binary path
	EmptyBinaryPathErr = errors.New("empty binary path")
	// NoPatternProvidedErr indicates that no function pattern was provided
	NoPatternProvidedErr = errors.New("no function pattern or hook point was provided")
)
View Source
var ByteOrder binary.ByteOrder

ByteOrder holds the hosts byte order

View Source
var (
	// SymbolNotFound is used to notify that a symbol could not be resolved
	SymbolNotFound = elf.Symbol{Name: "[symbol_not_found]"}
)

Functions

func GetHostByteOrder

func GetHostByteOrder() binary.ByteOrder

GetHostByteOrder guesses the hosts byte order

func RandomStringWithLen

func RandomStringWithLen(n int) string

RandomStringWithLen returns a random string of specified length containing upper- and lowercase runes.

Types

type BinaryCookie

type BinaryCookie uint32

BinaryCookie is a unique identifier used to select a TracedBinary

type CombinedID

type CombinedID uint64

CombinedID is a unique identifier used to select a combined stack trace (user and kernel)

type Func

type Func struct {
	Type           FuncType
	Symbol         elf.Symbol
	Count          uint64
	AverageLatency time.Duration
	Binary         *TracedBinary
	// contains filtered or unexported fields
}

Func contains the data collected by utrace for a function

func NewFunc

func NewFunc(symbol elf.Symbol, binary *TracedBinary) Func

NewFunc instanciates a new Func

func (*Func) GetStackTrace

func (f *Func) GetStackTrace(stackID CombinedID) *StackTrace

GetStackTrace returns a stack trace from its StackID

func (*Func) GetStackTracesByHits

func (f *Func) GetStackTracesByHits() []*StackTrace

GetStackTracesByHits returns the list of stack traces by hits count

type FuncID

type FuncID int32

FuncID is the id of a function traced in kernel space

type FuncType

type FuncType string

FuncType is the type of a traced function

const (
	// Kernel is used for kernel symbols
	Kernel FuncType = "kernel"
	// User is used for user space symbols
	User FuncType = "user"
)

type Options

type Options struct {
	FuncPattern       *regexp.Regexp
	KernelFuncPattern *regexp.Regexp
	Tracepoints       []string
	PerfEvents        []string
	Latency           bool
	StackTraces       bool
	Binary            []string
	PIDFilter         []int
}

Options contains the parameters of UTrace

type Report

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

Report contains the statistics generated by UTRace

func NewReport

func NewReport(duration time.Duration) Report

NewReport instanciates a new Report

func (*Report) GetDuration

func (r *Report) GetDuration() time.Duration

GetDuration returns the duration of the trace

func (*Report) GetFunc

func (r *Report) GetFunc(id FuncID) Func

GetFunc returns a Func by its FuncID

func (*Report) GetFunctionsByHits

func (r *Report) GetFunctionsByHits() map[BinaryCookie][]Func

GetFunctionsByHits returns the list of traced functions ordered by their hits count

func (*Report) GetFunctionsByLatency

func (r *Report) GetFunctionsByLatency() map[BinaryCookie][]Func

GetFunctionsByLatency returns the list of traced functions ordered by their latency

func (*Report) GetStackTraceCount

func (r *Report) GetStackTraceCount() StackTraceCount

GetStackTraceCount returns the total number of stack traces collected from the kernel

type StackID

type StackID uint32

StackID is a unique identifier used to select a stack trace

type StackTrace

type StackTrace struct {
	Count            int
	Binary           *TracedBinary
	UserStacktrace   []StackTraceNode
	KernelStackTrace []StackTraceNode
}

StackTrace contains the ordered list of symbols of a stack trace

func NewStackTrace

func NewStackTrace(count int, binary *TracedBinary) *StackTrace

NewStackTrace returns a new StackTrace initialized with the provided count

type StackTraceCount

type StackTraceCount struct {
	Kernel     uint64
	LostKernel uint64
	User       uint64
	LostUser   uint64
}

StackTraceCount holds the amount of traces that were collected or lost

type StackTraceNode

type StackTraceNode struct {
	Type   FuncType
	FuncID FuncID
	Offset SymbolAddr
	Symbol elf.Symbol
}

StackTraceNode represents a node of a stack trace

type SymbolAddr

type SymbolAddr uint64

SymbolAddr is the address of a symbol

type TraceEvent

type TraceEvent struct {
	Pid           uint32
	Tid           uint32
	UserStackID   StackID
	KernelStackID StackID
	FuncID        FuncID
	Cookie        BinaryCookie
}

TraceEvent is a kernel trace event retrieved from a perf map

func (*TraceEvent) UnmarshalBinary

func (te *TraceEvent) UnmarshalBinary(data []byte) (int, error)

UnmarshalBinary unmarshals the binary representation of a trace event

type TracedBinary

type TracedBinary struct {
	Path         string
	ResolvedPath string
	Inode        uint64
	Size         int64
	Cookie       BinaryCookie
	Pids         []int
	// contains filtered or unexported fields
}

type TracedSymbol

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

type UTrace

type UTrace struct {

	// TracedBinaries is the list of userspace binaries for which we are collecting stack traces
	TracedBinaries map[BinaryCookie]*TracedBinary
	// contains filtered or unexported fields
}

UTrace is the main UTrace structure

func NewUTrace

func NewUTrace(options Options) *UTrace

NewUTrace creates a new UTrace instance

func (*UTrace) ResolveKernelSymbolAndOffset

func (u *UTrace) ResolveKernelSymbolAndOffset(address SymbolAddr) StackTraceNode

ResolveKernelSymbolAndOffset returns the symbol of the kernel function in which a given address lives, as well as the offset inside that function

func (*UTrace) ResolveUserSymbolAndOffset

func (u *UTrace) ResolveUserSymbolAndOffset(address SymbolAddr, binary *TracedBinary) StackTraceNode

ResolveUserSymbolAndOffset returns the symbol of the function in which a given address lives, as well as the offset inside that function

func (*UTrace) Start

func (u *UTrace) Start() error

Start hooks on the requested symbols and begins tracing

func (*UTrace) Stop

func (u *UTrace) Stop() (Report, error)

Stop shuts down UTrace

func (*UTrace) TraceEventsHandler

func (u *UTrace) TraceEventsHandler(Cpu int, data []byte, perfMap *manager.PerfMap, m *manager.Manager)

TraceEventsHandler handles perf events from the kernel

Jump to

Keyboard shortcuts

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