Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enforce profiling.Prepare to enhance symbolization selection #104

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions wzprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type Profiling struct {
symbols symbolizer
stackIterator func(mod api.Module, def api.FunctionDefinition, wasmsi experimental.StackIterator) experimental.StackIterator

lang language
lang language
prepareCalled bool // Flag to indicate if Prepare has been called
}

type language int8
Expand Down Expand Up @@ -95,18 +96,6 @@ func ProfilingFor(wasm []byte) *Profiling {
return r
}

// CPUProfiler constructs a new instance of CPUProfiler using the given time
// function to record the CPU time consumed.
func (p *Profiling) CPUProfiler(options ...CPUProfilerOption) *CPUProfiler {
return newCPUProfiler(p, options...)
}

// MemoryProfiler constructs a new instance of MemoryProfiler using the given
// time function to record the profile execution time.
func (p *Profiling) MemoryProfiler(options ...MemoryProfilerOption) *MemoryProfiler {
return newMemoryProfiler(p, options...)
}

// Prepare selects the most appropriate analysis functions for the guest
// code in the provided module.
func (p *Profiling) Prepare(mod wazero.CompiledModule) error {
Expand Down Expand Up @@ -147,9 +136,31 @@ func (p *Profiling) Prepare(mod wazero.CompiledModule) error {
}
p.symbols = buildDwarfSymbolizer(dwarf)
}

// Set the flag to true if Prepare succeeds
p.prepareCalled = true

return nil
}
iamrajiv marked this conversation as resolved.
Show resolved Hide resolved

// CPUProfiler constructs a new instance of CPUProfiler using the given time
// function to record the CPU time consumed.
func (p *Profiling) CPUProfiler(options ...CPUProfilerOption) *CPUProfiler {
if !p.prepareCalled {
panic("Profiling.Prepare must be called before creating a CPU profiler")
}
return newCPUProfiler(p, options...)
}

// MemoryProfiler constructs a new instance of MemoryProfiler using the given
// time function to record the profile execution time.
func (p *Profiling) MemoryProfiler(options ...MemoryProfilerOption) *MemoryProfiler {
if !p.prepareCalled {
panic("Profiling.Prepare must be called before creating a Memory profiler")
}
return newMemoryProfiler(p, options...)
}

// profilingListener wraps a FunctionListener to adapt its stack iterator to the
// appropriate implementation according to the module support.
type profilingListener struct {
Expand Down
Loading