mediamtx/internal/core/pprof.go

61 lines
1.0 KiB
Go
Raw Normal View History

package core
import (
"net/http"
2020-11-05 11:30:25 +00:00
// start pprof
_ "net/http/pprof"
2023-05-16 14:14:20 +00:00
"github.com/bluenviron/mediamtx/internal/conf"
"github.com/bluenviron/mediamtx/internal/httpserv"
2023-05-16 14:14:20 +00:00
"github.com/bluenviron/mediamtx/internal/logger"
)
type pprofParent interface {
logger.Writer
2020-10-19 20:17:48 +00:00
}
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)
2020-10-19 20:17:48 +00:00
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...)
2020-10-19 20:17:48 +00:00
}