profile

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package profile provides lightweight wall-time stage profiling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEnabled

func IsEnabled(p Profiler) bool

IsEnabled reports whether p is an active (non-disabled) Profiler. Use to gate expensive metric-collection work that should only run under --profile.

Types

type Profiler

type Profiler interface {
	Stage(name string) func()
	Observe(name string, files, bytes int64)
	Summary(w io.Writer, totalLabel string)
}

Profiler records wall-time stage durations and optional file-transfer metrics. Call Stage to start a named stage and call the returned closure to end it. Use as: defer p.Stage("foo")() Call Observe after a stage to attach file/byte counts to its summary row.

func Disabled

func Disabled() Profiler

Disabled returns a no-op Profiler that records and emits nothing.

func OrDisabled

func OrDisabled(p Profiler) Profiler

OrDisabled returns p if non-nil, otherwise Disabled(). Use at package boundaries where p may come from an unset Deps field.

type Recorder

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

Recorder is a Profiler that accumulates wall-time durations per named stage. Repeated calls to Stage or Observe with the same name add to the existing total.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns a production Recorder using the real clock.

func (*Recorder) Observe

func (r *Recorder) Observe(name string, files, bytes int64)

Observe records file and byte counts for name, adding to any existing totals.

func (*Recorder) Stage

func (r *Recorder) Stage(name string) func()

Stage starts timing name and returns a done closure.

func (*Recorder) Summary

func (r *Recorder) Summary(w io.Writer, totalLabel string)

Summary writes a timing table to w, sorted by duration descending. The row with the longest duration is marked with ◀. Files and bytes columns are shown only when at least one stage has non-zero counts.

Jump to

Keyboard shortcuts

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