Documentation
¶
Index ¶
- Constants
- func AddTimingComponent(ctx context.Context, duration time.Duration, f ...any) (childCtx context.Context)
- func AttachTrailer(ctx context.Context) error
- func CleanData(data *Data)
- func DurationStr(d time.Duration, precision string) string
- func Encode(data *Data, buf *bytes.Buffer) error
- func FlattenData(data *Data)
- func LogDuration(start time.Time, f ...any)
- 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 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 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 ¶
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 ¶
DurationStr converts the duration to the specified precision.
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 ¶
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 UnaryProfiler ¶
func UnaryProfiler() grpc.UnaryServerInterceptor
Sets the profiler data from the context as a trailer in the response.