pprof.go 476 B

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