...
1 package profilex
2
3 import (
4 "os"
5
6 "github.com/pkg/profile"
7 )
8
9 type noop struct{}
10
11
12 func (p *noop) Stop() {}
13
14
15 func Profile() interface {
16 Stop()
17 } {
18 switch os.Getenv("PROFILING") {
19 case "cpu":
20 return profile.Start(profile.CPUProfile, profile.NoShutdownHook)
21 case "mem":
22 return profile.Start(profile.MemProfile, profile.NoShutdownHook)
23 case "mutex":
24 return profile.Start(profile.MutexProfile, profile.NoShutdownHook)
25 case "block":
26 return profile.Start(profile.BlockProfile, profile.NoShutdownHook)
27 }
28 return new(noop)
29 }
30
31
32 func HelpMessage() string {
33 return `- PROFILING: Set "PROFILING=cpu" to enable cpu profiling and "PROFILING=mem" to enable memory profiling.
34 It is not possible to do both at the same time. Profiling is disabled per default.
35
36 Example: PROFILING=cpu`
37 }
38
View as plain text