2020-06-13 07:29:32 +00:00
|
|
|
// +build prof
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-17 07:06:34 +00:00
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"runtime/pprof"
|
2020-06-13 07:29:32 +00:00
|
|
|
|
|
|
|
_ "net/http/pprof"
|
|
|
|
|
2020-06-17 07:06:34 +00:00
|
|
|
_ "github.com/ianlancetaylor/cgosymbolizer"
|
|
|
|
|
2020-06-13 07:29:32 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-06-17 07:06:34 +00:00
|
|
|
// go func() {
|
|
|
|
// if err := http.ListenAndServe("localhost:42069", nil); err != nil {
|
|
|
|
// log.Error(errors.Wrap(err, "Failed to start profiling HTTP server"))
|
|
|
|
// }
|
|
|
|
// }()
|
|
|
|
|
|
|
|
runtime.SetBlockProfileRate(1)
|
|
|
|
|
|
|
|
f, _ := os.Create("/tmp/cchat.pprof")
|
|
|
|
p := pprof.Lookup("block")
|
|
|
|
|
|
|
|
destructor = func() {
|
|
|
|
log.Println("==destructor==")
|
|
|
|
|
|
|
|
if err := p.WriteTo(f, 2); err != nil {
|
|
|
|
log.Println("Profile writeTo error:", err)
|
2020-06-13 07:29:32 +00:00
|
|
|
}
|
2020-06-17 07:06:34 +00:00
|
|
|
|
|
|
|
f.Close()
|
|
|
|
}
|
2020-06-13 07:29:32 +00:00
|
|
|
}
|