forked from dgraph-io/dgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
41 lines (35 loc) · 779 Bytes
/
profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package x
import (
"fmt"
"os"
"runtime"
"github.com/pkg/profile"
"github.com/spf13/viper"
)
type stopper interface {
Stop()
}
func StartProfile(conf *viper.Viper) stopper {
profileMode := conf.GetString("profile_mode")
switch profileMode {
case "cpu":
return profile.Start(profile.CPUProfile)
case "mem":
return profile.Start(profile.MemProfile)
case "mutex":
return profile.Start(profile.MutexProfile)
case "block":
blockRate := conf.GetInt("block_rate")
runtime.SetBlockProfileRate(blockRate)
return profile.Start(profile.BlockProfile)
case "":
// do nothing
return noOpStopper{}
default:
fmt.Printf("Invalid profile mode: %q\n", profileMode)
os.Exit(1)
return noOpStopper{}
}
}
type noOpStopper struct{}
func (noOpStopper) Stop() {}