7 "github.com/pkg/profile"
11 // start a simple CPU profile and register
12 // a defer to Stop (flush) the profiling data.
13 defer profile.Start().Stop()
16 func ExampleCPUProfile() {
17 // CPU profiling is the default profiling mode, but you can specify it
18 // explicitly for completeness.
19 defer profile.Start(profile.CPUProfile).Stop()
22 func ExampleMemProfile() {
23 // use memory profiling, rather than the default cpu profiling.
24 defer profile.Start(profile.MemProfile).Stop()
27 func ExampleMemProfileRate() {
28 // use memory profiling with custom rate.
29 defer profile.Start(profile.MemProfileRate(2048)).Stop()
32 func ExampleProfilePath() {
33 // set the location that the profile will be written to
34 defer profile.Start(profile.ProfilePath(os.Getenv("HOME"))).Stop()
37 func ExampleNoShutdownHook() {
38 // disable the automatic shutdown hook.
39 defer profile.Start(profile.NoShutdownHook).Stop()
42 func ExampleStart_withFlags() {
43 // use the flags package to selectively enable profiling.
44 mode := flag.String("profile.mode", "", "enable profiling mode, one of [cpu, mem, mutex, block]")
48 defer profile.Start(profile.CPUProfile).Stop()
50 defer profile.Start(profile.MemProfile).Stop()
52 defer profile.Start(profile.MutexProfile).Stop()
54 defer profile.Start(profile.BlockProfile).Stop()