Documentation
¶
Index ¶
- Constants
- func AddIO(ctx context.Context, n int64)
- func AddIOCategory(ctx context.Context, n int64, category string, f ...any)
- func AddIOComponent(ctx context.Context, n int64, f ...any)
- func AddTimingComponent(ctx context.Context, duration time.Duration, f ...any) (childCtx context.Context)
- func AddTimingParallelComponent(ctx context.Context, duration time.Duration, f ...any) (childCtx context.Context)
- func AttachTrailer(ctx context.Context) error
- func Clean(data *Data)
- func DurationStr(d time.Duration, precision string) string
- func Encode(data *Data, buf *bytes.Buffer) error
- func Flatten(data *Data)
- func IO[T any](ctx context.Context, w T, f ...any) T
- func IOCategory[T any](ctx context.Context, w T, category string, f ...any) T
- func IOComponent[T any](ctx context.Context, w T, f ...any) T
- func IOParallelCategory[T any](ctx context.Context, w T, category string, f ...any) T
- func IOParallelComponent[T any](ctx context.Context, w T, f ...any) T
- func IORedundantCategory[T any](ctx context.Context, w T, category string, f ...any) T
- func IORedundantComponent[T any](ctx context.Context, w T, f ...any) T
- func LogDuration(start time.Time, f ...any)
- func Print(data *Data, categoryColors ...map[string]text.Colors)
- func StartTiming(ctx context.Context, f ...any) (childCtx context.Context, end func())
- func StartTimingCategory(ctx context.Context, category string, f ...any) (childCtx context.Context, end func())
- func StartTimingComponent(ctx context.Context, f ...any) (childCtx context.Context, end func())
- func StartTimingParallelCategory(ctx context.Context, category string, f ...any) (childCtx context.Context, end func())
- func StartTimingParallelComponent(ctx context.Context, f ...any) (childCtx context.Context, end func())
- func UnaryProfiler() grpc.UnaryServerInterceptor
- type Data
Constants ¶
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
AddIO adds n bytes to the IO metric in the profiling data stored in the context.
func AddIOCategory ¶ added in v0.9.276
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 AttachTrailer ¶
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 ¶
DurationStr converts the duration to the specified precision.
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
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
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
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
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
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
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
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 ¶
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 ¶
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 ¶
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 StartTimingParallelComponent ¶ added in v0.9.269
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.