Documentation ¶
Overview ¶
Package wzprof provides pprof-based capabilities to Wazero-based hosts.
Index ¶
- func Flag(flag *bool, factory experimental.FunctionListenerFactory) experimental.FunctionListenerFactory
- func Handler(sampleRate float64, profilers ...Profiler) http.Handler
- func Sample(sampleRate float64, factory experimental.FunctionListenerFactory) experimental.FunctionListenerFactory
- func WriteProfile(path string, prof *profile.Profile) error
- type CPUProfiler
- func (p *CPUProfiler) Count() int
- func (p *CPUProfiler) Desc() string
- func (p *CPUProfiler) Name() string
- func (p *CPUProfiler) NewFunctionListener(def api.FunctionDefinition) experimental.FunctionListener
- func (p *CPUProfiler) NewHandler(sampleRate float64) http.Handler
- func (p *CPUProfiler) SampleType() []*profile.ValueType
- func (p *CPUProfiler) StartProfile() bool
- func (p *CPUProfiler) StopProfile(sampleRate float64) *profile.Profile
- type CPUProfilerOption
- type MemoryProfiler
- func (p *MemoryProfiler) Count() int
- func (p *MemoryProfiler) Desc() string
- func (p *MemoryProfiler) Name() string
- func (p *MemoryProfiler) NewFunctionListener(def api.FunctionDefinition) experimental.FunctionListener
- func (p *MemoryProfiler) NewHandler(sampleRate float64) http.Handler
- func (p *MemoryProfiler) NewProfile(sampleRate float64) *profile.Profile
- func (p *MemoryProfiler) SampleType() []*profile.ValueType
- type MemoryProfilerOption
- type Profiler
- type Profiling
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flag ¶ added in v0.1.5
func Flag(flag *bool, factory experimental.FunctionListenerFactory) experimental.FunctionListenerFactory
Flag returns a function listener factory which creates listeners where calls to their Before/After methods are gated by the boolean flag pointed at by the first argument.
The sampling mechanism is similar to the one implemented by Sample but it gives the application control over when the listeners are enabled instead of leaving the selection up to a probabilistic model.
func Handler ¶
Handler returns a http handler which responds with the pprof-formatted profile named by the request. For example, "/debug/pprof/heap" serves the "heap" profile.
Handler responds to a request for "/debug/pprof/" with an HTML page listing the available profiles.
func Sample ¶
func Sample(sampleRate float64, factory experimental.FunctionListenerFactory) experimental.FunctionListenerFactory
Sample returns a function listener factory which creates listeners where calls to their Before/After methods is sampled at the given sample rate.
Giving a zero or negative sampling rate disables the function listeners entirely.
Giving a sampling rate of one or more disables sampling, function listeners are invoked for all function calls.
Types ¶
type CPUProfiler ¶
type CPUProfiler struct {
// contains filtered or unexported fields
}
CPUProfiler is the implementation of a performance profiler recording samples of CPU time spent in functions of a WebAssembly module.
The profiler generates samples of two types: - "sample" counts the number of function calls. - "cpu" records the time spent in function calls (in nanoseconds).
func (*CPUProfiler) Count ¶
func (p *CPUProfiler) Count() int
Count returns the number of execution stacks currently recorded in p.
func (*CPUProfiler) Desc ¶
func (p *CPUProfiler) Desc() string
Desc returns a description copied from net/http/pprof.
func (*CPUProfiler) Name ¶
func (p *CPUProfiler) Name() string
Name returns "profile" to match the name of the CPU profiler in pprof.
func (*CPUProfiler) NewFunctionListener ¶
func (p *CPUProfiler) NewFunctionListener(def api.FunctionDefinition) experimental.FunctionListener
NewFunctionListener returns a function listener suited to record CPU timings of calls to the function passed as argument.
func (*CPUProfiler) NewHandler ¶
func (p *CPUProfiler) NewHandler(sampleRate float64) http.Handler
NewHandler returns a http handler allowing the profiler to be exposed on a pprof-compatible http endpoint.
The sample rate is a value between 0 and 1 used to scale the profile results based on the sampling rate applied to the profiler so the resulting values remain representative.
The symbolizer passed as argument is used to resolve names of program locations recorded in the profile.
func (*CPUProfiler) SampleType ¶
func (p *CPUProfiler) SampleType() []*profile.ValueType
SampleType returns the set of value types present in samples recorded by the CPU profiler.
func (*CPUProfiler) StartProfile ¶
func (p *CPUProfiler) StartProfile() bool
StartProfile begins recording the CPU profile. The method returns a boolean to indicate whether starting the profile succeeded (e.g. false is returned if it was already started).
func (*CPUProfiler) StopProfile ¶
func (p *CPUProfiler) StopProfile(sampleRate float64) *profile.Profile
StopProfile stops recording and returns the CPU profile. The method returns nil if recording of the CPU profile wasn't started.
type CPUProfilerOption ¶
type CPUProfilerOption func(*CPUProfiler)
CPUProfilerOption is a type used to represent configuration options for CPUProfiler instances created by NewCPUProfiler.
func HostTime ¶
func HostTime(enable bool) CPUProfilerOption
HostTime confiures a CPU time profiler to account for time spent in calls to host functions.
Default to false.
func TimeFunc ¶
func TimeFunc(time func() int64) CPUProfilerOption
TimeFunc configures the time function used by the CPU profiler to collect monotonic timestamps.
By default, the system's monotonic time is used.
type MemoryProfiler ¶
type MemoryProfiler struct {
// contains filtered or unexported fields
}
MemoryProfiler is the implementation of a performance profiler recording samples of memory allocation and utilization.
The profiler generates the following samples: - "alloc_objects" records the locations where objects are allocated - "alloc_space" records the locations where bytes are allocated - "inuse_objects" records the allocation of active objects - "inuse_space" records the bytes used by active objects
"alloc_objects" and "alloc_space" are all time counters since the start of the program, while "inuse_objects" and "inuse_space" capture the current state of the program at the time the profile is taken.
func (*MemoryProfiler) Count ¶
func (p *MemoryProfiler) Count() int
Count returns the number of allocation stacks recorded in p.
func (*MemoryProfiler) Desc ¶
func (p *MemoryProfiler) Desc() string
Desc returns a description copied from net/http/pprof.
func (*MemoryProfiler) Name ¶
func (p *MemoryProfiler) Name() string
Name returns "allocs" to match the name of the memory profiler in pprof.
func (*MemoryProfiler) NewFunctionListener ¶
func (p *MemoryProfiler) NewFunctionListener(def api.FunctionDefinition) experimental.FunctionListener
NewFunctionListener returns a function listener suited to install a hook on functions responsible for memory allocation.
The listener recognizes multiple memory allocation functions used by compilers and libraries. It uses the function name to detect memory allocators, currently supporting libc, Go, and TinyGo.
func (*MemoryProfiler) NewHandler ¶
func (p *MemoryProfiler) NewHandler(sampleRate float64) http.Handler
NewHandler returns a http handler allowing the profiler to be exposed on a pprof-compatible http endpoint.
The sample rate is a value between 0 and 1 used to scale the profile results based on the sampling rate applied to the profiler so the resulting values remain representative.
The symbolizer passed as argument is used to resolve names of program locations recorded in the profile.
func (*MemoryProfiler) NewProfile ¶
func (p *MemoryProfiler) NewProfile(sampleRate float64) *profile.Profile
NewProfile takes a snapshot of the current memory allocation state and builds a profile representing the state of the program memory.
func (*MemoryProfiler) SampleType ¶
func (p *MemoryProfiler) SampleType() []*profile.ValueType
SampleType returns the set of value types present in samples recorded by the memory profiler.
type MemoryProfilerOption ¶
type MemoryProfilerOption func(*MemoryProfiler)
MemoryProfilerOption is a type used to represent configuration options for MemoryProfiler instances created by NewMemoryProfiler.
func InuseMemory ¶
func InuseMemory(enable bool) MemoryProfilerOption
InuseMemory is a memory profiler option which enables tracking of allocated and freed objects to generate snapshots of the current state of a program memory.
type Profiler ¶
type Profiler interface { experimental.FunctionListenerFactory // Name of the profiler. Name() string // Desc is a human-readable description of the profiler. Desc() string // Count the number of execution stacks recorded in the profiler. Count() int // SampleType returns the set of value types present in samples recorded by // the profiler. SampleType() []*profile.ValueType // NewHandler returns a new http handler suited to expose profiles on a // pprof endpoint. NewHandler(sampleRate float64) http.Handler }
Profiler is an interface implemented by all profiler types available in this package.
type Profiling ¶ added in v0.1.5
type Profiling struct {
// contains filtered or unexported fields
}
Profiling mechanism for a given WASM binary. Entry point to generate Profilers.
func ProfilingFor ¶ added in v0.1.5
ProfilingFor a given wasm binary. The resulting Profiling needs to be prepared after Wazero module compilation.
func (*Profiling) CPUProfiler ¶ added in v0.1.5
func (p *Profiling) CPUProfiler(options ...CPUProfilerOption) *CPUProfiler
CPUProfiler constructs a new instance of CPUProfiler using the given time function to record the CPU time consumed.
func (*Profiling) MemoryProfiler ¶ added in v0.1.5
func (p *Profiling) MemoryProfiler(options ...MemoryProfilerOption) *MemoryProfiler
MemoryProfiler constructs a new instance of MemoryProfiler using the given time function to record the profile execution time.