-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
40 lines (34 loc) · 845 Bytes
/
main.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
package main
import (
"net/http"
"os"
"runtime/pprof"
"github.com/felixge/fgprof"
"github.com/rabbitmq/omq/cmd"
"github.com/rabbitmq/omq/pkg/log"
)
func main() {
if os.Getenv("OMQ_PPROF") == "true" {
cpuFile, err := os.Create("omq-cpu.pprof")
if err != nil {
log.Error("can't create omq-cpu.pprof", "error", err)
}
defer pprof.StopCPUProfile()
_ = pprof.StartCPUProfile(cpuFile)
}
if os.Getenv("OMQ_FGPROF") == "true" {
http.DefaultServeMux.Handle("/debug/fgprof", fgprof.Handler())
go func() {
_ = http.ListenAndServe(":6060", nil)
}()
}
cmd.Execute()
if os.Getenv("OMQ_PPROF") == "true" {
memFile, err := os.Create("omq-memory.pprof")
if err != nil {
log.Error("can't create omq-memory.pprof", "error", err)
}
_ = pprof.WriteHeapProfile(memFile)
defer func() { _ = memFile.Close() }()
}
}