profile: github.com/pkg/profile Index | Examples | Files

package profile

import "github.com/pkg/profile"

Package profile provides a simple way to manage runtime/pprof profiling of your Go application.

Index

Examples

Package Files

mutex.go profile.go trace.go

Constants

const DefaultMemProfileRate = 4096

DefaultMemProfileRate is the default memory profiling rate. See also http://golang.org/pkg/runtime/#pkg-variables

func BlockProfile Uses

func BlockProfile(p *Profile)

BlockProfile enables block (contention) profiling. It disables any previous profiling settings.

func CPUProfile Uses

func CPUProfile(p *Profile)

CPUProfile enables cpu profiling. It disables any previous profiling settings.

Code:

// CPU profiling is the default profiling mode, but you can specify it
// explicitly for completeness.
defer profile.Start(profile.CPUProfile).Stop()

func MemProfile Uses

func MemProfile(p *Profile)

MemProfile enables memory profiling. It disables any previous profiling settings.

Code:

// use memory profiling, rather than the default cpu profiling.
defer profile.Start(profile.MemProfile).Stop()

func MemProfileRate Uses

func MemProfileRate(rate int) func(*Profile)

MemProfileRate enables memory profiling at the preferred rate. It disables any previous profiling settings.

Code:

// use memory profiling with custom rate.
defer profile.Start(profile.MemProfileRate(2048)).Stop()

func MutexProfile Uses

func MutexProfile(p *Profile)

MutexProfile enables mutex profiling. It disables any previous profiling settings.

Mutex profiling is a no-op before go1.8.

func NoShutdownHook Uses

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.

Code:

// disable the automatic shutdown hook.
defer profile.Start(profile.NoShutdownHook).Stop()

func ProfilePath Uses

func ProfilePath(path string) func(*Profile)

ProfilePath controls the base path where various profiling files are written. If blank, the base path will be generated by ioutil.TempDir.

Code:

// set the location that the profile will be written to
defer profile.Start(profile.ProfilePath(os.Getenv("HOME"))).Stop()

func Quiet Uses

func Quiet(p *Profile)

Quiet suppresses informational messages during profiling.

func Start Uses

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:

// start a simple CPU profile and register
// a defer to Stop (flush) the profiling data.
defer profile.Start().Stop()

Code:

// 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 TraceProfile Uses

func TraceProfile(p *Profile)

Trace profile controls if execution tracing will be enabled. It disables any previous profiling settings.

Code:

// use execution tracing, rather than the default cpu profiling.
defer profile.Start(profile.TraceProfile).Stop()

type Profile Uses

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

Profile represents an active profiling session.

func (*Profile) Stop Uses

func (p *Profile) Stop()

Stop stops the profile and flushes any unwritten data.

Package profile imports 9 packages (graph) and is imported by 109 packages. Updated 2018-07-03. Refresh now. Tools for package owners.