libpf

package
v0.0.0-...-3b12f0d Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackageTypeDeb = iota
	PackageTypeRPM
	PackageTypeCustomSymbols
	PackageTypeAPK
)
View Source
const (
	SourcePackageTypeDeb = iota
	SourcePackageTypeRPM
)
View Source
const (
	CodeIndexingPackageTypeDeb    = "deb"
	CodeIndexingPackageTypeRpm    = "rpm"
	CodeIndexingPackageTypeCustom = "custom"
	CodeIndexingPackageTypeApk    = "apk"
)
View Source
const (
	FileTypeNative = iota
	FileTypePython
)
View Source
const SymbolNameUnknown = ""

SymbolNameUnknown is the value returned by SymbolMap functions when address has no symbol info.

View Source
const SymbolValueInvalid = SymbolValue(0)

SymbolValueInvalid is the value returned by SymbolMap functions when symbol was not found.

Variables

View Source
var LocalFSPackageID = PackageID{
	basehash.New128(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF),
}

LocalFSPackageID is a fake package identifier, indicating that a particular file was not part of a package, but was extracted directly from a local filesystem.

View Source
var UnknownKernelFileID = NewFileID(math.MaxUint64-2, math.MaxUint64-2)

UnknownKernelFileID is used as 128-bit FileID when the host agent isn't able to derive a FileID for a kernel frame.

View Source
var UnsymbolizedFileID = NewFileID(math.MaxUint64, math.MaxUint64)

UnsymbolizedFileID is used as 128-bit FileID when symbolization fails.

Functions

func AddJitter

func AddJitter(baseDuration time.Duration, jitter float64) time.Duration

AddJitter adds +/- jitter (jitter is [0..1]) to baseDuration

func AtomicUpdateMaxUint32

func AtomicUpdateMaxUint32(store *atomic.Uint32, newValue uint32)

AtomicUpdateMaxUint32 updates the value in store using atomic memory primitives. newValue will only be placed in store if newValue is larger than the current value in store. To avoid inconsistency parallel updates to store should be avoided.

func CheckCanceled

func CheckCanceled(err1, err2 error) error

CheckCanceled tries to match the first error with context canceled/deadline exceeded and returns it. If no match is found, the second error is returned.

func CheckError

func CheckError(err error, errList ...error) bool

CheckError tries to match err with an error in the passed slice and returns true if a match is found.

func ComputeFileCRC32

func ComputeFileCRC32(filePath string) (int32, error)

ComputeFileCRC32 computes the CRC32 hash of a file

func ComputeFileSHA256

func ComputeFileSHA256(filePath string) (string, error)

func DecToUint64

func DecToUint64(str string) uint64

DecToUint64 is a convenience function to extract a decimal string to a uint64 and not worry about errors. Essentially a "mustConvertDecToUint64".

func GetURLWithoutQueryParams

func GetURLWithoutQueryParams(url string) string

GetURLWithoutQueryParams returns an URL with all query parameters removed For example, http://hello.com/abc?a=1&b=2 becomes http://hello.com/abc

func HashString

func HashString(s string) uint64

HashString turns a string into a 64-bit hash.

func HashStrings

func HashStrings(strs ...string) []byte

HashStrings turns a list of strings into a 128-bit hash.

func HexToUint64

func HexToUint64(str string) uint64

HexToUint64 is a convenience function to extract a hex string to a uint64 and not worry about errors. Essentially a "mustConvertHexToUint64".

func Int64ToTime

func Int64ToTime(t int64) time.Time

Int64ToTime converts an int64 to a time.Time. It preserves the "zero-ness" across the conversion, which means 0 is converted to a zero time.Time (instead of the Unix epoch).

func IsValidString

func IsValidString(s string) bool

IsValidString checks if string is UTF-8-encoded and only contains expected characters.

func MapKeysToSlice

func MapKeysToSlice[K comparable, V any](m map[K]V) []K

MapKeysToSlice creates a slice from a map's keys.

func MapSlice

func MapSlice[T, V any](in []T, mapf func(T) V) []V

MapSlice returns a new slice by mapping given function over the input slice.

func MapValuesToSlice

func MapValuesToSlice[K comparable, V any](m map[K]V) []V

MapValuesToSlice creates a slice from a map's values.

func NextPowerOfTwo

func NextPowerOfTwo(v uint32) uint32

NextPowerOfTwo returns the next highest power of 2 for a given value v or v, if v is a power of 2.

func NowAsUInt32

func NowAsUInt32() uint32

NowAsUInt32 is a convenience function to avoid code repetition

func SleepWithJitter

func SleepWithJitter(baseDuration time.Duration, jitter float64)

SleepWithJitter sleeps for baseDuration +/- jitter (jitter is [0..1])

func SleepWithJitterAndContext

func SleepWithJitterAndContext(ctx context.Context, duration time.Duration, jitter float64) error

SleepWithJitterAndContext blocks for duration +/- jitter (jitter is [0..1]) or until ctx is canceled.

func SliceAllEqual

func SliceAllEqual[T comparable](s []T, value T) bool

SliceAllEqual checks whether all items in a slice have a given value.

func SliceFrom

func SliceFrom(data any) []byte

SliceFrom converts a Go struct pointer or slice to []byte to read data into

func SlicesEqual

func SlicesEqual[T comparable](a, b []T) bool

SlicesEqual checks whether two slices are element-wise equal.

func TimeToInt64

func TimeToInt64(t time.Time) int64

TimeToInt64 converts a time.Time to an int64. It preserves the "zero-ness" across the conversion, which means a zero Time is converted to 0.

func VersionUint

func VersionUint(major, minor, patch uint32) uint32

VersionUint returns a single integer composed of major, minor, patch.

func WriteTempFile

func WriteTempFile(data []byte, directory, prefix string) (string, error)

WriteTempFile writes a data buffer to a temporary file on the filesystem. It is the callers responsibility to clean up that file again. The function returns the filename if successful.

Types

type Address

type Address uint64

Address represents an address, or offset within a process

func (Address) Hash

func (adr Address) Hash() uint64

func (Address) Hash32

func (adr Address) Hash32() uint32

Hash32 returns a 32 bits hash of the input. It's main purpose is to be used as key for caching.

type AddressOrLineno

type AddressOrLineno uint64

AddressOrLineno represents a line number in an interpreted file or an offset into a native file. TODO(thomasdullien): check with regards to JSON marshaling/demarshaling.

type CodeIndexingMessage

type CodeIndexingMessage struct {
	SourcePackageName    string `json:"sourcePackageName"`
	SourcePackageVersion string `json:"sourcePackageVersion"`
	MirrorName           string `json:"mirrorName"`
	ForceRetry           bool   `json:"forceRetry"`
}

type FileID

type FileID struct {
	basehash.Hash128
}

FileID is used for unique identifiers for files

func FileIDFromBase64

func FileIDFromBase64(s string) (FileID, error)

FileIDFromBase64 converts a base64url encoded file ID into its binary representation. We store binary fields as keywords as base64 URL encoded strings. But when retrieving binary fields, ES sends them as base64 STD encoded strings.

func FileIDFromBytes

func FileIDFromBytes(b []byte) (FileID, error)

FileIDFromBytes parses a byte slice into the internal data representation for a file ID.

func FileIDFromString

func FileIDFromString(s string) (FileID, error)

FileIDFromString parses a hexadecimal notation of a file ID into the internal data representation.

func NewFileID

func NewFileID(hi, lo uint64) FileID

func (FileID) Compare

func (f FileID) Compare(other FileID) int

Compare returns an integer comparing two hashes lexicographically. The result will be 0 if f == other, -1 if f < other, and +1 if f > other.

func (FileID) Equal

func (f FileID) Equal(other FileID) bool

func (FileID) Hash32

func (f FileID) Hash32() uint32

Hash32 returns a 32 bits hash of the input. It's main purpose is to be used as key for caching.

func (FileID) Less

func (f FileID) Less(other FileID) bool

type FileType

type FileType int32

The different types of packages that we process

type FrameID

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

FrameID represents a frame as an address in an executable file or as a line in a source code file.

func NewFrameID

func NewFrameID(fileID FileID, addressOrLineno AddressOrLineno) FrameID

NewFrameID creates a new FrameID from the fileId and address or line.

func NewFrameIDFromBytes

func NewFrameIDFromBytes(bytes []byte) (FrameID, error)

NewFrameIDFromBytes creates a new FrameID from a byte array of length 24.

func NewFrameIDFromString

func NewFrameIDFromString(frameEncoded string) (FrameID, error)

NewFrameIDFromString creates a new FrameID from its JSON string representation.

func (FrameID) AddressOrLine

func (f FrameID) AddressOrLine() AddressOrLineno

AddressOrLine returns the addressOrLine part of the frameID.

func (*FrameID) AsIP

func (f *FrameID) AsIP() net.IP

AsIP returns the FrameID as a net.IP type to be used for the PC range in profiling-symbols-*.

func (FrameID) Bytes

func (f FrameID) Bytes() []byte

Bytes returns the frameid as byte sequence.

func (FrameID) EncodeTo

func (f FrameID) EncodeTo(dst []byte)

EncodeTo encodes the frame ID into the base64 encoded representation and stores it in the provided destination byte array. The length of the destination must be at least EncodedLen().

func (FrameID) EncodedLen

func (FrameID) EncodedLen() int

EncodedLen returns the length of the FrameID's base64 representation.

func (FrameID) FileID

func (f FrameID) FileID() FileID

FileID returns the fileID part of the frameID.

func (FrameID) Hash

func (f FrameID) Hash() uint64

Hash calculates a hash from the frameid. xxh3 is 4x faster than fnv.

func (FrameID) Hash32

func (f FrameID) Hash32() uint32

Hash32 returns a 32 bits hash of the input. It's main purpose is to be used as key for caching.

func (FrameID) String

func (f FrameID) String() string

String returns the base64 encoded representation.

type FrameMetadata

type FrameMetadata struct {
	FileID         FileID
	AddressOrLine  AddressOrLineno
	LineNumber     SourceLineno
	FunctionOffset uint32
	FunctionName   string
	Filename       string
}

type FrameType

type FrameType int

FrameType defines the type of frame. This usually corresponds to the interpreter type that emitted it, but can additionally contain meta-information like error frames.

A frame type can represent one of the following things:

  • A successfully unwound frame. This is represented simply as the `InterpType` ID.
  • A partial (non-critical failure), indicated by ORing the `InterpType` ID with the error bit.
  • A fatal failure that caused further unwinding to be aborted. This is indicated using the special value support.FrameMarkerAbort (0xFF). It thus also contains the error bit, but does not fit into the `InterpType` enum.
const (
	// UnknownFrame indicates a frame of an unknown interpreter.
	// If this appears, it's likely a bug somewhere.
	UnknownFrame FrameType = support.FrameMarkerUnknown
	// PHPFrame identifies PHP interpreter frames.
	PHPFrame FrameType = support.FrameMarkerPHP
	// PHPJITFrame identifies PHP JIT interpreter frames.
	PHPJITFrame FrameType = support.FrameMarkerPHPJIT
	// PythonFrame identifies the Python interpreter frames.
	PythonFrame FrameType = support.FrameMarkerPython
	// NativeFrame identifies native frames.
	NativeFrame FrameType = support.FrameMarkerNative
	// KernelFrame identifies kernel frames.
	KernelFrame FrameType = support.FrameMarkerKernel
	// HotSpotFrame identifies Java HotSpot VM frames.
	HotSpotFrame FrameType = support.FrameMarkerHotSpot
	// RubyFrame identifies the Ruby interpreter frames.
	RubyFrame FrameType = support.FrameMarkerRuby
	// PerlFrame identifies the Perl interpreter frames.
	PerlFrame FrameType = support.FrameMarkerPerl
	// V8Frame identifies the V8 interpreter frames.
	V8Frame FrameType = support.FrameMarkerV8
	// AbortFrame identifies frames that report that further unwinding was aborted due to an error.
	AbortFrame FrameType = support.FrameMarkerAbort
)

Convenience shorthands to create various frame types.

Code should not compare against the constants below directly, but instead use the provided methods to query the required information (IsError, Interpreter, ...) to improve forward compatibility and clarify intentions.

func (FrameType) Error

func (ty FrameType) Error() FrameType

Error adds the error bit into the frame type.

func (FrameType) Interpreter

func (ty FrameType) Interpreter() InterpType

Interpreter returns the interpreter that produced the frame.

func (FrameType) IsError

func (ty FrameType) IsError() bool

IsError checks whether the frame is an error frame.

func (FrameType) IsInterpType

func (ty FrameType) IsInterpType(ity InterpType) bool

IsInterpType checks whether the frame type belongs to the given interpreter.

func (FrameType) String

func (ty FrameType) String() string

String implements the Stringer interface.

type InterpType

type InterpType int

InterpType variables can hold one of the interpreter type values defined below.

const (
	// UnknownInterp signifies that the interpreter is unknown.
	UnknownInterp InterpType = support.FrameMarkerUnknown
	// PHP identifies the PHP interpreter.
	PHP InterpType = support.FrameMarkerPHP
	// PHPJIT identifies PHP JIT processes.
	PHPJIT InterpType = support.FrameMarkerPHPJIT
	// Python identifies the Python interpreter.
	Python InterpType = support.FrameMarkerPython
	// Native identifies native code.
	Native InterpType = support.FrameMarkerNative
	// Kernel identifies kernel code.
	Kernel InterpType = support.FrameMarkerKernel
	// HotSpot identifies the Java HotSpot VM.
	HotSpot InterpType = support.FrameMarkerHotSpot
	// Ruby identifies the Ruby interpreter.
	Ruby InterpType = support.FrameMarkerRuby
	// Perl identifies the Perl interpreter.
	Perl InterpType = support.FrameMarkerPerl
	// V8 identifies the V8 interpreter.
	V8 InterpType = support.FrameMarkerV8
)

func (InterpType) Frame

func (i InterpType) Frame() FrameType

Frame converts the interpreter type into the corresponding frame type.

func (InterpType) String

func (i InterpType) String() string

String converts the frame type int to the related string value to be displayed in the UI.

type InterpVersion

type InterpVersion string

InterpVersion represents the version of an interpreter

type KTime

type KTime int64

KTime stores a time value, retrieved from a monotonic clock, in nanoseconds

func GetKTime

func GetKTime() KTime

GetKTime gets the current time in same nanosecond format as bpf_ktime_get_ns() eBPF call This relies runtime.nanotime to use CLOCK_MONOTONIC. If this changes, this needs to be adjusted accordingly. Using this internal is superior in performance, as it is able to use the vDSO to query the time without syscall.

type OnDiskFileIdentifier

type OnDiskFileIdentifier struct {
	DeviceID uint64 // dev_t as reported by stat.
	InodeNum uint64 // ino_t should fit into 64 bits
}

OnDiskFileIdentifier can be used as unique identifier for a file. It is a structure to identify a particular file on disk by deviceID and inode number.

func GetOnDiskFileIdentifier

func GetOnDiskFileIdentifier(filename string) (OnDiskFileIdentifier, error)

GetOnDiskFileIdentifier builds a unique identifier of a given filename based on the information we can extract from stat.

func (OnDiskFileIdentifier) Hash32

func (odfi OnDiskFileIdentifier) Hash32() uint32

type PID

type PID int32

PID represent Unix Process ID (pid_t)

func (PID) Hash32

func (p PID) Hash32() uint32

type PackageID

type PackageID struct {
	basehash.Hash128
}

PackageID is used for unique identifiers for packages

func PackageIDFromBytes

func PackageIDFromBytes(b []byte) (PackageID, error)

PackageIDFromBytes parses a byte slice into the internal data representation for a PackageID.

func PackageIDFromString

func PackageIDFromString(str string) (PackageID, error)

PackageIDFromString returns a PackageID from its string representation.

func (PackageID) Equal

func (h PackageID) Equal(other PackageID) bool

Equal returns true if both PackageIDs are equal.

func (PackageID) String

func (h PackageID) String() string

String returns the string representation for the package ID.

type PackageType

type PackageType int32

The different types of packages that we process

func (PackageType) String

func (t PackageType) String() string

type Range

type Range struct {
	Start uint64
	End   uint64
}

Range describes a range with Start and End values.

type Set

type Set[T comparable] map[T]Void

Set is a convenience alias for a map with a `Void` key.

func SliceToSet

func SliceToSet[T comparable](s []T) Set[T]

SliceToSet creates a set from a slice, deduplicating it.

func (Set[T]) ToSlice

func (s Set[T]) ToSlice() []T

ToSlice converts the Set keys into a slice.

type SourceLineno

type SourceLineno uint64

SourceLineno represents a line number within a source file. It is intended to be used for the source line numbers associated with offsets in native code, or for source line numbers in interpreted code.

type SourcePackageType

type SourcePackageType int32

The different types of source package objects that we process

type Symbol

type Symbol struct {
	Name    SymbolName
	Address SymbolValue
	Size    int
}

Symbol represents the name of a symbol

type SymbolFinder

type SymbolFinder interface {
	LookupSymbol(symbolName SymbolName) (*Symbol, error)

	LookupSymbolAddress(symbolName SymbolName) (SymbolValue, error)
}

SymbolFinder implements a way to find symbol data

type SymbolMap

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

SymbolMap represents collections of symbols that can be resolved or reverse mapped

func (*SymbolMap) Add

func (symmap *SymbolMap) Add(s Symbol)

Add a symbol to the map

func (*SymbolMap) Finalize

func (symmap *SymbolMap) Finalize()

Finalize symbol map by sorting and constructing the nameToSymbol table after all symbols are inserted via Add() calls

func (*SymbolMap) Len

func (symmap *SymbolMap) Len() int

Len returns the number of elements in the map.

func (*SymbolMap) LookupByAddress

func (symmap *SymbolMap) LookupByAddress(val SymbolValue) (SymbolName, Address, bool)

LookupByAddress translates the address to a symbolic information. Return empty string and absolute address if it did not match any symbol.

func (*SymbolMap) LookupSymbol

func (symmap *SymbolMap) LookupSymbol(symbolName SymbolName) (*Symbol, error)

LookupSymbol obtains symbol information. Returns nil and an error if not found.

func (*SymbolMap) LookupSymbolAddress

func (symmap *SymbolMap) LookupSymbolAddress(symbolName SymbolName) (SymbolValue, error)

LookupSymbolAddress returns the address of a symbol. Returns SymbolValueInvalid and error if not found.

func (*SymbolMap) ScanAllNames

func (symmap *SymbolMap) ScanAllNames(cb func(SymbolName))

ScanAllNames calls the provided callback with all the symbol names in the map.

type SymbolName

type SymbolName string

SymbolName represents the name of a symbol

type SymbolValue

type SymbolValue uint64

SymbolValue represents the value associated with a symbol, e.g. either an offset or an absolute address

type Trace

type Trace struct {
	Files      []FileID
	Linenos    []AddressOrLineno
	FrameTypes []FrameType
	Hash       TraceHash
}

Trace represents a stack trace. Each tuple (Files[i], Linenos[i]) represents a stack frame via the file ID and line number at the offset i in the trace. The information for the most recently called function is at offset 0.

func (*Trace) AppendFrame

func (trace *Trace) AppendFrame(ty FrameType, file FileID, addrOrLine AddressOrLineno)

AppendFrame appends a frame to the columnar frame array.

type TraceAndCounts

type TraceAndCounts struct {
	Hash          TraceHash
	Timestamp     UnixTime32
	Count         uint16
	Comm          string
	PodName       string
	ContainerName string
}

type TraceHash

type TraceHash struct {
	basehash.Hash128
}

TraceHash represents the unique hash of a trace

func NewTraceHash

func NewTraceHash(hi, lo uint64) TraceHash

func TraceHashFromBytes

func TraceHashFromBytes(b []byte) (TraceHash, error)

TraceHashFromBytes parses a byte slice of a trace hash into the internal data representation.

func TraceHashFromString

func TraceHashFromString(s string) (TraceHash, error)

TraceHashFromString parses a hexadecimal notation of a trace hash into the internal data representation.

func (TraceHash) EncodeTo

func (h TraceHash) EncodeTo(dst []byte)

EncodeTo encodes the hash into the base64 encoded representation and stores it in the provided destination byte array. The length of the destination must be at least EncodedLen().

func (TraceHash) EncodedLen

func (TraceHash) EncodedLen() int

EncodedLen returns the length of the hash's base64 representation.

func (TraceHash) Equal

func (h TraceHash) Equal(other TraceHash) bool

func (TraceHash) Hash32

func (h TraceHash) Hash32() uint32

Hash32 returns a 32 bits hash of the input. It's main purpose is to be used for LRU caching.

func (TraceHash) Less

func (h TraceHash) Less(other TraceHash) bool

type UnixTime32

type UnixTime32 uint32

UnixTime32 is another type to represent seconds since epoch. In most cases 32bit time values are good enough until year 2106. Our time series database backend uses this type for TimeStamps as well, so there is no need to use a different type than uint32. Also, Go's semantics on map[time.Time] are particularly nasty footguns, and since the code is mostly dealing with UNIX timestamps, we may as well use uint32s instead. To restore some semblance of type safety, we declare a type alias here.

func (*UnixTime32) MarshalJSON

func (t *UnixTime32) MarshalJSON() ([]byte, error)

type Void

type Void struct{}

Void allows to use maps as sets without memory allocation for the values. From the "Go Programming Language":

The struct type with no fields is called the empty struct, written struct{}. It has size zero
and carries no information but may be useful nonetheless. Some Go programmers
use it instead of bool as the value type of a map that represents a set, to emphasize
that only the keys are significant, but the space saving is marginal and the syntax more
cumbersome, so we generally avoid it.

Directories

Path Synopsis
This package contains a series of helper functions that are useful for ARM disassembly.
This package contains a series of helper functions that are useful for ARM disassembly.
Package basehash provides basic types to implement hash identifiers.
Package basehash provides basic types to implement hash identifiers.
Package freelru is a wrapper around go-freelru.LRU with additional statistics embedded and can be used as a drop in replacement.
Package freelru is a wrapper around go-freelru.LRU with additional statistics embedded and can be used as a drop in replacement.
Package hash provides the same hash primitives as used by the eBPF.
Package hash provides the same hash primitives as used by the eBPF.
lpm package provides helpers for calculating prefix lists from ranges
lpm package provides helpers for calculating prefix lists from ranges
stackdeltatypes
Package stackdeltatypes provides types used to represent stack delta information as constructed by `nativeunwind.GetIntervalStructures` This information is a post-processed form of the stack delta information that is used in all relevant packages.
Package stackdeltatypes provides types used to represent stack delta information as constructed by `nativeunwind.GetIntervalStructures` This information is a post-processed form of the stack delta information that is used in all relevant packages.
nopanicslicereader provides little convenience utilities to read "native" endian values from a slice at given offset.
nopanicslicereader provides little convenience utilities to read "native" endian values from a slice at given offset.
Package periodiccaller allows periodic calls of functions.
Package periodiccaller allows periodic calls of functions.
package pfelf implements functions for processing of ELF files and extracting data from them.
package pfelf implements functions for processing of ELF files and extracting data from them.
remotememory provides access to memory space of a process.
remotememory provides access to memory space of a process.
successfailurecounter provides a wrapper to atomically increment success or failure counters.
successfailurecounter provides a wrapper to atomically increment success or failure counters.
Package vc provides buildtime information.
Package vc provides buildtime information.
Package xsync provides thin wrappers around locking primitives in an effort towards better documenting the relationship between locks and the data they protect.
Package xsync provides thin wrappers around locking primitives in an effort towards better documenting the relationship between locks and the data they protect.

Jump to

Keyboard shortcuts

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