added support for string type
[govpp.git] / vendor / github.com / pkg / profile / example_test.go
1 package profile_test
2
3 import (
4         "flag"
5         "os"
6
7         "github.com/pkg/profile"
8 )
9
10 func ExampleStart() {
11         // start a simple CPU profile and register
12         // a defer to Stop (flush) the profiling data.
13         defer profile.Start().Stop()
14 }
15
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()
20 }
21
22 func ExampleMemProfile() {
23         // use memory profiling, rather than the default cpu profiling.
24         defer profile.Start(profile.MemProfile).Stop()
25 }
26
27 func ExampleMemProfileRate() {
28         // use memory profiling with custom rate.
29         defer profile.Start(profile.MemProfileRate(2048)).Stop()
30 }
31
32 func ExampleProfilePath() {
33         // set the location that the profile will be written to
34         defer profile.Start(profile.ProfilePath(os.Getenv("HOME"))).Stop()
35 }
36
37 func ExampleNoShutdownHook() {
38         // disable the automatic shutdown hook.
39         defer profile.Start(profile.NoShutdownHook).Stop()
40 }
41
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]")
45         flag.Parse()
46         switch *mode {
47         case "cpu":
48                 defer profile.Start(profile.CPUProfile).Stop()
49         case "mem":
50                 defer profile.Start(profile.MemProfile).Stop()
51         case "mutex":
52                 defer profile.Start(profile.MutexProfile).Stop()
53         case "block":
54                 defer profile.Start(profile.BlockProfile).Stop()
55         default:
56                 // do nothing
57         }
58 }