2020-06-13 07:29:32 +00:00
|
|
|
// +build prof
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "net/http/pprof"
|
|
|
|
|
2020-06-17 07:06:34 +00:00
|
|
|
_ "github.com/ianlancetaylor/cgosymbolizer"
|
2020-06-13 07:29:32 +00:00
|
|
|
)
|
|
|
|
|
2020-08-20 23:53:13 +00:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
const ProfileAddr = "localhost:49583"
|
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
func init() {
|
2020-08-20 23:53:13 +00:00
|
|
|
C.HeapProfilerStart()
|
|
|
|
destructor = func() { C.HeapProfilerStop() }
|
|
|
|
|
|
|
|
// runtime.SetBlockProfileRate(1)
|
|
|
|
|
2020-06-17 07:06:34 +00:00
|
|
|
// go func() {
|
2020-08-20 23:53:13 +00:00
|
|
|
// log.Println("Listening to profiler at", ProfileAddr)
|
|
|
|
|
|
|
|
// if err := http.ListenAndServe(ProfileAddr, nil); err != nil {
|
2020-06-17 07:06:34 +00:00
|
|
|
// log.Error(errors.Wrap(err, "Failed to start profiling HTTP server"))
|
|
|
|
// }
|
|
|
|
// }()
|
|
|
|
|
2020-07-18 07:16:47 +00:00
|
|
|
// f, _ := os.Create("/tmp/cchat.pprof")
|
|
|
|
// p := pprof.Lookup("block")
|
2020-06-17 07:06:34 +00:00
|
|
|
|
2020-07-18 07:16:47 +00:00
|
|
|
// destructor = func() {
|
|
|
|
// log.Println("==destructor==")
|
|
|
|
|
|
|
|
// if err := p.WriteTo(f, 2); err != nil {
|
|
|
|
// log.Println("Profile writeTo error:", err)
|
|
|
|
// }
|
2020-06-17 07:06:34 +00:00
|
|
|
|
2020-07-18 07:16:47 +00:00
|
|
|
// f.Close()
|
|
|
|
// }
|
2020-06-17 07:06:34 +00:00
|
|
|
|
2020-08-20 23:53:13 +00:00
|
|
|
// f, _ := os.Create("/tmp/cchat.pprof")
|
|
|
|
// if err := pprof.StartCPUProfile(f); err != nil {
|
|
|
|
// panic(err)
|
|
|
|
// }
|
2020-07-18 07:16:47 +00:00
|
|
|
|
2020-08-20 23:53:13 +00:00
|
|
|
// destructor = func() {
|
|
|
|
// pprof.StopCPUProfile()
|
|
|
|
// f.Close()
|
|
|
|
// }
|
2020-06-13 07:29:32 +00:00
|
|
|
}
|