-
Notifications
You must be signed in to change notification settings - Fork 145
/
component.go
55 lines (45 loc) · 1.29 KB
/
component.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package profilingrecorder
import (
"context"
"runtime"
profile "github.com/bygui86/multi-profile/v2"
"go.uber.org/dig"
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/wasp/packages/daemon"
)
func init() {
Component = &app.Component{
Name: "profilingRecorder",
Params: params,
IsEnabled: func(_ *dig.Container) bool { return ParamsProfilingRecorder.Enabled },
Run: run,
}
}
var Component *app.Component
func run() error {
runtime.SetMutexProfileFraction(5)
runtime.SetBlockProfileRate(5)
runtime.SetCPUProfileRate(5)
profConfig := &profile.Config{
Path: "./profiles",
EnableInterruptHook: true,
}
profs := make([]*profile.Profile, 7)
profs[0] = profile.CPUProfile(profConfig).Start()
profs[1] = profile.MemProfile(profConfig).Start()
profs[2] = profile.GoroutineProfile(profConfig).Start()
profs[3] = profile.MutexProfile(profConfig).Start()
profs[4] = profile.BlockProfile(profConfig).Start()
profs[5] = profile.TraceProfile(profConfig).Start()
profs[6] = profile.ThreadCreationProfile(profConfig).Start()
err := Component.Daemon().BackgroundWorker(Component.Name, func(ctx context.Context) {
<-ctx.Done()
for _, p := range profs {
p.Stop()
}
}, daemon.PriorityProfilingRecorder)
if err != nil {
panic(err)
}
return nil
}