Documentation
¶
Overview ¶
Package xprof.
Extends the original source code https://pkg.go.dev/github.com/pkg/profile
Index ¶
- Constants
- func Block(p *Prof)
- func CPU(p *Prof)
- func Go(p *Prof)
- func Mem(p *Prof)
- func MemAllocs(p *Prof)
- func MemHeap(p *Prof)
- func MemRate(rate int) func(*Prof)
- func Mutex(p *Prof)
- func NoShutdownHook(p *Prof)
- func Quiet(p *Prof)
- func Start(path string, options ...func(*Prof)) interface{ ... }
- func Thread(p *Prof)
- func Trace(p *Prof)
- type Prof
Examples ¶
Constants ¶
const DefaultMemProfileRate = 4096
DefaultMemProfileRate is the default memory profiling rate. See also http://golang.org/pkg/runtime/#pkg-variables
const Usage = "enable profiling mode, one of [cpu, mem, mutex, block]"
Usage text for flag package.
Variables ¶
This section is empty.
Functions ¶
func Block ¶
func Block(p *Prof)
Block enables block (contention) profiling. It disables any previous profiling settings.
func CPU ¶
func CPU(p *Prof)
CPU enables cpu profiling. It disables any previous profiling settings.
Example ¶
// CPU profiling is the default profiling mode, but you can specify it
// explicitly for completeness.
defer Start("", CPU).Stop()
func Go ¶
func Go(p *Prof)
Go enables goroutine profiling. It disables any previous profiling settings.
func Mem ¶
func Mem(p *Prof)
Mem enables memory profiling. It disables any previous profiling settings.
Example ¶
// use memory profiling, rather than the default cpu profiling.
defer Start("", Mem).Stop()
func MemAllocs ¶
func MemAllocs(p *Prof)
MemAllocs changes which type of memory to profile allocations.
Example ¶
// use allocs memory profiling.
defer Start("", MemAllocs).Stop()
func MemHeap ¶
func MemHeap(p *Prof)
MemHeap changes which type of memory profiling to profile the heap.
Example ¶
// use heap memory profiling.
defer Start("", MemHeap).Stop()
func MemRate ¶
MemRate enables memory profiling at the preferred rate. It disables any previous profiling settings.
Example ¶
// use memory profiling with custom rate.
defer Start("", MemRate(2048)).Stop()
func Mutex ¶
func Mutex(p *Prof)
Mutex enables mutex profiling. It disables any previous profiling settings.
func NoShutdownHook ¶
func NoShutdownHook(p *Prof)
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.
Example ¶
// disable the automatic shutdown hook.
defer Start("", NoShutdownHook).Stop()
func Start ¶
Start starts a new profiling session. The caller should call the Stop method on the value returned to cleanly stop profiling.
Example ¶
// start a simple CPU profile and register
// a defer to Stop (flush) the profiling data.
defer Start("").Stop()
Example (WithFlags) ¶
// use the flags package to selectively enable profiling.
mode := flag.String("mode", "", "enable profiling mode, one of [cpu, mem, mutex, block]")
flag.Parse()
switch *mode {
case "cpu":
defer Start("", CPU).Stop()
case "mem":
defer Start("", Mem).Stop()
case "mutex":
defer Start("", Mutex).Stop()
case "block":
defer Start("", Block).Stop()
default:
// do nothing
}