profiling

package
v0.9.280 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: AGPL-3.0 Imports: 23 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 AddIO added in v0.9.269

func AddIO(ctx context.Context, n int64)

AddIO adds n bytes to the IO metric in the profiling data stored in the context.

func AddIOCategory added in v0.9.276

func AddIOCategory(ctx context.Context, n int64, category string, f ...any)

func AddIOComponent added in v0.9.269

func AddIOComponent(ctx context.Context, n int64, f ...any)

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 AddTimingParallelComponent added in v0.9.269

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

func AttachTrailer

func AttachTrailer(ctx context.Context) error

Attaches profiling data from the context as a grpc trailer.

func Clean added in v0.9.276

func Clean(data *Data)

Clean collapses any empty wrappers in the profiling data. Empty wrappers are those that have no duration, no IO, 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 Flatten added in v0.9.276

func Flatten(data *Data)

Flatten 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 IO added in v0.9.269

func IO[T any](ctx context.Context, w T, f ...any) T

IO wraps an io.ReadCloser, io.WriteCloser, or io.ReadWriteCloser to profile its I/O operations as part of profiling data of current context. The returned type will be the same as the input type.

func IOCategory added in v0.9.269

func IOCategory[T any](ctx context.Context, w T, category string, f ...any) T

IOCategory wraps an io.ReadCloser, io.WriteCloser, or io.ReadWriteCloser to profile its I/O operations under a specific category in the profiling data of the current context. The returned type will be the same as the input type.

func IOComponent added in v0.9.269

func IOComponent[T any](ctx context.Context, w T, f ...any) T

IO wraps an io.ReadCloser, io.WriteCloser, or io.ReadWriteCloser to profile its I/O operations as a component of the profiling data of the current context. The returned type will be the same as the input type.

func IOParallelCategory added in v0.9.269

func IOParallelCategory[T any](ctx context.Context, w T, category string, f ...any) T

IOParallelCategory is same as IOCategory but marks the component as parallel. Parallel components' durations are not counted towards their parent's duration. However, their I/O is still counted towards total.

func IOParallelComponent added in v0.9.269

func IOParallelComponent[T any](ctx context.Context, w T, f ...any) T

IOParallelComponent is same as IOComponent but marks the component as parallel. Parallel components' durations are not counted towards their parent's duration. However, their I/O is still counted towards total.

func IORedundantCategory added in v0.9.276

func IORedundantCategory[T any](ctx context.Context, w T, category string, f ...any) T

IORedundantCategory is same as IOCategory but marks the component as redundant. Redundant components are not counted towards their parent's duration or I/O.

func IORedundantComponent added in v0.9.276

func IORedundantComponent[T any](ctx context.Context, w T, f ...any) T

IORedundantComponent is same as IOComponent but marks the component as redundant. Redundant components are not counted towards their parent's duration or I/O.

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 Print added in v0.9.276

func Print(data *Data, categoryColors ...map[string]text.Colors)

Print prints the profiling data in a very readable format.

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 StartTimingParallelCategory added in v0.9.269

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

func StartTimingParallelComponent added in v0.9.269

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

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  `json:"name"`
	Components []*Data `json:"components,omitempty"`

	Duration int64 `json:"duration,omitempty"`
	IO       int64 `json:"io,omitempty"`

	Parallel  bool `json:"parallel,omitempty"`
	Redundant bool `json:"redundant,omitempty"`
}

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