Documentation ¶
Overview ¶
Package pprof provides the profiling command-line options and adapts to go tool pprof.
Examples:
if err := cmdr.Exec(buildRootCmd(), pprof.GetCmdrProfilingOptions(...), ); err != nil { log.Fatalf("error occurs in app running: %+v\n", err) }
Examples:
func buildRootCmd() (rootCmd *cmdr.RootCommand) { root := cmdr.Root(appName, cmdr.Version) rootCmd = root.RootCommand() pprof.AttachToCmdr(root) return }
Examples:
func buildRootCmd() (rootCmd *cmdr.RootCommand) { root := cmdr.Root(appName, cmdr.Version). Copyright(copyright, "hedzr") rootCmd = root.RootCommand() pprof.AttachToCmdr(root.RootCmdOpt(), ...) return }
Index ¶
- Constants
- func AttachToCmdr(root *cmdr.RootCmdOpt, types ...string)
- func EnableCPUProfile(cpuProfilePath string) (closer func())
- func EnableMemProfile(memProfilePath string) (closer func())
- func GetCmdrProfilingOptions(types ...string) cmdr.ExecOption
- func Start(types ProfType, opts ...ProfOpt) (Stop func())
- type ProfOpt
- func WithBlockProfName(filename string) ProfOpt
- func WithCPUProfName(filename string) ProfOpt
- func WithGoRoutineProfName(filename string) ProfOpt
- func WithMemProfName(filename string) ProfOpt
- func WithMemProfileRate(rate int) ProfOpt
- func WithMemProfileType(typ string) ProfOpt
- func WithMutexProfName(filename string) ProfOpt
- func WithOutputDirectory(path string) ProfOpt
- func WithThreadCreateProfName(filename string) ProfOpt
- func WithTraceProfName(filename string) ProfOpt
- func WithTypes(types ...ProfType) ProfOpt
- type ProfType
Constants ¶
const DefaultMemProfileRate = 4096
DefaultMemProfileRate is the default memory profiling rate. See also http://golang.org/pkg/runtime/#pkg-variables
Variables ¶
This section is empty.
Functions ¶
func AttachToCmdr ¶
func AttachToCmdr(root *cmdr.RootCmdOpt, types ...string)
AttachToCmdr attaches the profiling options to root command.
For example:
cmdr.Exec(buildRootCmd()) func buildRootCmd() (rootCmd *cmdr.RootCommand) { root := cmdr.Root(appName, cmdr.Version). Copyright(copyright, "hedzr"). Description(desc, longDesc). Examples(examples) rootCmd = root.RootCommand() pprof.AttachToCmdr(root.RootCmdOpt()) return }
The variadic param `types` allows which profiling types are enabled by default, such as `cpu`, `mem`. While end-user enables profiling with `app -ep`, those profiles will be created and written. The available type names are: "cpu", "mem", "mutex", "block", "thread-create", "trace", and "go-routine".
func EnableCPUProfile ¶
func EnableCPUProfile(cpuProfilePath string) (closer func())
EnableCPUProfile enables cpu profiling. And review the pprof result in a web ui:
go tool pprof -http=:8555 ./cpu.pprof
Now you can open 'http://localhost:8555/ui' in a browser
func EnableMemProfile ¶
func EnableMemProfile(memProfilePath string) (closer func())
EnableMemProfile enables memory profiling. And review the pprof result in a web ui:
go tool pprof -http=:8555 ./mem.pprof
Now you can open 'http://localhost:8555/ui' in a browser
func GetCmdrProfilingOptions ¶
func GetCmdrProfilingOptions(types ...string) cmdr.ExecOption
GetCmdrProfilingOptions returns an opt for cmdr.Exec(root, opts...). And, it adds profiling options to cmdr system.
For example:
cmdr.Exec(buildRootCmd(), profile.GetCmdrProfilingOptions(), )
The variadic param `types` allows which profiling types are enabled by default, such as `cpu`, `mem`. While end-user enables profiling with `app -ep`, those profiles will be created and written. The available type names are: "cpu", "mem", "mutex", "block", "thread-create", "trace", and "go-routine".
Types ¶
type ProfOpt ¶
type ProfOpt func(*profile)
ProfOpt provides a wrapped functional options type for Start(...)
func WithGoRoutineProfName ¶
WithGoRoutineProfName ..
func WithMemProfileRate ¶
WithMemProfileRate enables memory profiling with a special rate
func WithMemProfileType ¶
WithMemProfileType specify the typename of memory profiling, "heap" or "allocs"
func WithOutputDirectory ¶
WithOutputDirectory specify a directory for writing profiles. Default is '.'.
func WithThreadCreateProfName ¶
WithThreadCreateProfName ..
type ProfType ¶
type ProfType int
ProfType represents the profile type
const ( // CPUProf represents cpu profiling CPUProf ProfType = 1 // MemProf represents memory profiling MemProf ProfType = 2 // MutexProf represents mutex profiling MutexProf ProfType = 4 // BlockProf represents block profiling BlockProf ProfType = 8 // ThreadCreateProf represents thread creation profiling ThreadCreateProf ProfType = 16 // TraceProf represents trace profiling TraceProf ProfType = 32 // GoRoutineProf represents go-routine profiling GoRoutineProf ProfType = 64 )