mediamtx/internal/core/pprof.go
2023-07-30 23:03:00 +02:00

61 lines
1.0 KiB
Go

package core
import (
"net/http"
// start pprof
_ "net/http/pprof"
"github.com/bluenviron/mediamtx/internal/conf"
"github.com/bluenviron/mediamtx/internal/httpserv"
"github.com/bluenviron/mediamtx/internal/logger"
)
type pprofParent interface {
logger.Writer
}
type pprof struct {
parent pprofParent
httpServer *httpserv.WrappedServer
}
func newPPROF(
address string,
readTimeout conf.StringDuration,
parent pprofParent,
) (*pprof, error) {
pp := &pprof{
parent: parent,
}
network, address := restrictNetwork("tcp", address)
var err error
pp.httpServer, err = httpserv.NewWrappedServer(
network,
address,
readTimeout,
"",
"",
http.DefaultServeMux,
)
if err != nil {
return nil, err
}
pp.Log(logger.Info, "listener opened on "+address)
return pp, nil
}
func (pp *pprof) close() {
pp.Log(logger.Info, "listener is closing")
pp.httpServer.Close()
}
func (pp *pprof) Log(level logger.Level, format string, args ...interface{}) {
pp.parent.Log(level, "[pprof] "+format, args...)
}