package profile
import "github.com/pkg/profile"
Package profile provides a simple way to manage runtime/pprof profiling of your Go application.
Index ¶
- Constants
- func BlockProfile(p *Profile)
- func CPUProfile(p *Profile)
- func ClockProfile(p *Profile)
- func GoroutineProfile(p *Profile)
- func MemProfile(p *Profile)
- func MemProfileAllocs(p *Profile)
- func MemProfileHeap(p *Profile)
- func MemProfileRate(rate int) func(*Profile)
- func MutexProfile(p *Profile)
- func NoShutdownHook(p *Profile)
- func ProfilePath(path string) func(*Profile)
- func Quiet(p *Profile)
- func Start(options ...func(*Profile)) interface { Stop() }
- func ThreadcreationProfile(p *Profile)
- func TraceProfile(p *Profile)
- type Profile
Examples ¶
- CPUProfile
- MemProfile
- MemProfileAllocs
- MemProfileHeap
- MemProfileRate
- NoShutdownHook
- ProfilePath
- Start
- Start (WithFlags)
- TraceProfile
Constants ¶
const DefaultMemProfileRate = 4096
DefaultMemProfileRate is the default memory profiling rate. See also http://golang.org/pkg/runtime/#pkg-variables
Functions ¶
func BlockProfile ¶
func BlockProfile(p *Profile)
BlockProfile enables block (contention) profiling. It disables any previous profiling settings.
func CPUProfile ¶
func CPUProfile(p *Profile)
CPUProfile enables cpu profiling. It disables any previous profiling settings.
func ClockProfile ¶
func ClockProfile(p *Profile)
ClockProfile enables wall clock (fgprof) profiling. It disables any previous profiling settings.
func GoroutineProfile ¶
func GoroutineProfile(p *Profile)
GoroutineProfile enables goroutine profiling. It disables any previous profiling settings.
func MemProfile ¶
func MemProfile(p *Profile)
MemProfile enables memory profiling. It disables any previous profiling settings.
func MemProfileAllocs ¶
func MemProfileAllocs(p *Profile)
MemProfileAllocs changes which type of memory to profile allocations.
func MemProfileHeap ¶
func MemProfileHeap(p *Profile)
MemProfileHeap changes which type of memory profiling to profile the heap.
func MemProfileRate ¶
MemProfileRate enables memory profiling at the preferred rate. It disables any previous profiling settings.
func MutexProfile ¶
func MutexProfile(p *Profile)
MutexProfile enables mutex profiling. It disables any previous profiling settings.
func NoShutdownHook ¶
func NoShutdownHook(p *Profile)
NoShutdownHook controls whether the profiling package should hook SIGINT to write profiles cleanly. Programs with more sophisticated signal handling should set this to true and ensure the Stop() function returned from Start() is called during shutdown.
func ProfilePath ¶
ProfilePath controls the base path where various profiling files are written. If blank, the base path will be generated by ioutil.TempDir.
func Quiet ¶
func Quiet(p *Profile)
Quiet suppresses informational messages during profiling.
func Start ¶
func Start(options ...func(*Profile)) interface { Stop() }
Start starts a new profiling session.
The caller should call the Stop method on the value returned
to cleanly stop profiling.
Code:play
Code:play
Example¶
package main
import (
"github.com/pkg/profile"
)
func main() {
// start a simple CPU profile and register
// a defer to Stop (flush) the profiling data.
defer profile.Start().Stop()
}
Example (WithFlags)¶
package main
import (
"flag"
"github.com/pkg/profile"
)
func main() {
// use the flags package to selectively enable profiling.
mode := flag.String("profile.mode", "", "enable profiling mode, one of [cpu, mem, mutex, block]")
flag.Parse()
switch *mode {
case "cpu":
defer profile.Start(profile.CPUProfile).Stop()
case "mem":
defer profile.Start(profile.MemProfile).Stop()
case "mutex":
defer profile.Start(profile.MutexProfile).Stop()
case "block":
defer profile.Start(profile.BlockProfile).Stop()
default:
// do nothing
}
}
func ThreadcreationProfile ¶
func ThreadcreationProfile(p *Profile)
ThreadcreationProfile enables thread creation profiling.. It disables any previous profiling settings.
func TraceProfile ¶
func TraceProfile(p *Profile)
Trace profile enables execution tracing. It disables any previous profiling settings.
Types ¶
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
Profile represents an active profiling session.
func (*Profile) Stop ¶
func (p *Profile) Stop()
Stop stops the profile and flushes any unwritten data.
Source Files ¶
- Version
- v1.7.0 (latest)
- Published
- Oct 20, 2022
- Platform
- js/wasm
- Imports
- 10 packages
- Last checked
- 1 month ago –
Tools for package owners.