github.com/sagernet/sing-box@v1.9.0-rc.20/experimental/libbox/pprof.go (about)

     1  package libbox
     2  
     3  import (
     4  	"net"
     5  	"net/http"
     6  	_ "net/http/pprof"
     7  	"strconv"
     8  )
     9  
    10  type PProfServer struct {
    11  	server *http.Server
    12  }
    13  
    14  func NewPProfServer(port int) *PProfServer {
    15  	return &PProfServer{
    16  		&http.Server{
    17  			Addr: ":" + strconv.Itoa(port),
    18  		},
    19  	}
    20  }
    21  
    22  func (s *PProfServer) Start() error {
    23  	ln, err := net.Listen("tcp", s.server.Addr)
    24  	if err != nil {
    25  		return err
    26  	}
    27  	go s.server.Serve(ln)
    28  	return nil
    29  }
    30  
    31  func (s *PProfServer) Close() error {
    32  	return s.server.Close()
    33  }