profiling

package
v0.9.257 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const PROFILING_METADATA_KEY = "profiling-bin" // bin is required by gRPC when sending binary data

Variables

This section is empty.

Functions

func AddTimingComponent

func AddTimingComponent(ctx context.Context, duration time.Duration, f ...any) (childCtx context.Context)

AddTimingComponent is just like StartTimingComponent, but for adding a duration directly.

func AttachTrailer

func AttachTrailer(ctx context.Context) error

Attaches profiling data from the context as a grpc trailer.

func CleanData

func CleanData(data *Data)

CleanData collapses any empty wrappers in the profiling data. Empty wrappers are those that have no duration, no name, and only components.

func DurationStr

func DurationStr(d time.Duration, precision string) string

DurationStr converts the duration to the specified precision.

func Encode

func Encode(data *Data, buf *bytes.Buffer) error

func FlattenData

func FlattenData(data *Data)

FlattenData flattens the profiling data into a single list of components. This is such that the duration of each component is purely the time spent in that component excluding the time spent in its children.

func LogDuration

func LogDuration(start time.Time, f ...any)

LogDuration logs the elapsed time since start. Use with defer to log the time spent in a function If no f is provided, uses the caller.

func StartTiming

func StartTiming(ctx context.Context, f ...any) (childCtx context.Context, end func())

StartTiming starts a timer and returns a function that should be called to end the timer. Uses the profiling data in ctx to store the data, and returns a child context that should be used by the children of the function. If no f is provided, uses the caller to get the function name. This should only be called for the top most leader in the tree.

func StartTimingCategory

func StartTimingCategory(ctx context.Context, category string, f ...any) (childCtx context.Context, end func())

StartTimingCategory starts a timer and returns a function that should be called to end the timer. Instead of directly inserting a component like StartTimingComponent, this adds the data as a child component to an empty component (category component) whose name is matching the category provided. Returns childCtx, which should be used by the children of the new component. If no data found in passed ctx, just returns noops, as the parent is not being profiled.

func StartTimingComponent

func StartTimingComponent(ctx context.Context, f ...any) (childCtx context.Context, end func())

StartTimingComponent starts a timer and returns a function that should be called to end the timer. Unlike StartTiming, this adds the data as a new component of the current data in ctx. Returns childCtx, which should be used by the children of the new component. If no data found in passed ctx, just returns noops, as the parent is not being profiled.

func UnaryProfiler

func UnaryProfiler() grpc.UnaryServerInterceptor

Sets the profiler data from the context as a trailer in the response.

Types

type Data

type Data struct {
	Name       string
	Components []*Data

	Duration int64
}

Data is a struct that represents a profiling data tree.

func Decode

func Decode(data string) (*Data, error)

func FromTrailer

func FromTrailer(trailer metadata.MD) (*Data, error)

Jump to

Keyboard shortcuts

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