sing-box/experimental/libbox/pprof.go

36 lines
504 B
Go
Raw Permalink Normal View History

2023-03-15 06:56:06 +00:00
//go:build linux || darwin
2022-10-25 04:55:00 +00:00
package libbox
import (
"net"
"net/http"
_ "net/http/pprof"
"strconv"
)
type PProfServer struct {
server *http.Server
}
func NewPProfServer(port int) *PProfServer {
return &PProfServer{
&http.Server{
Addr: ":" + strconv.Itoa(port),
},
}
}
func (s *PProfServer) Start() error {
ln, err := net.Listen("tcp", s.server.Addr)
if err != nil {
return err
}
go s.server.Serve(ln)
return nil
}
func (s *PProfServer) Close() error {
return s.server.Close()
}