mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-23 00:51:29 +00:00
36 lines
494 B
Go
36 lines
494 B
Go
|
//go:build debug
|
||
|
|
||
|
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()
|
||
|
}
|