2021-07-24 13:55:42 +00:00
|
|
|
package core
|
2020-08-30 12:10:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2020-11-05 11:30:25 +00:00
|
|
|
|
|
|
|
// start pprof
|
2020-08-30 12:10:05 +00:00
|
|
|
_ "net/http/pprof"
|
2020-12-08 11:21:06 +00:00
|
|
|
|
2023-05-16 14:14:20 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/conf"
|
2023-07-30 21:03:00 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/httpserv"
|
2023-05-16 14:14:20 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
2020-08-30 12:10:05 +00:00
|
|
|
)
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
type pprofParent interface {
|
2023-05-04 18:16:41 +00:00
|
|
|
logger.Writer
|
2020-10-19 20:17:48 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
type pprof struct {
|
2021-11-15 19:13:54 +00:00
|
|
|
parent pprofParent
|
|
|
|
|
2023-07-30 21:03:00 +00:00
|
|
|
httpServer *httpserv.WrappedServer
|
2020-08-30 12:10:05 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
func newPPROF(
|
2021-04-24 16:25:19 +00:00
|
|
|
address string,
|
2023-04-11 18:47:19 +00:00
|
|
|
readTimeout conf.StringDuration,
|
2021-07-24 13:55:42 +00:00
|
|
|
parent pprofParent,
|
|
|
|
) (*pprof, error) {
|
|
|
|
pp := &pprof{
|
2021-11-15 19:13:54 +00:00
|
|
|
parent: parent,
|
2020-08-30 12:10:05 +00:00
|
|
|
}
|
|
|
|
|
2023-07-30 21:03:00 +00:00
|
|
|
network, address := restrictNetwork("tcp", address)
|
|
|
|
|
2023-05-16 18:12:45 +00:00
|
|
|
var err error
|
2023-07-30 21:03:00 +00:00
|
|
|
pp.httpServer, err = httpserv.NewWrappedServer(
|
|
|
|
network,
|
2023-05-16 18:12:45 +00:00
|
|
|
address,
|
|
|
|
readTimeout,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
http.DefaultServeMux,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-08-30 12:10:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 18:16:41 +00:00
|
|
|
pp.Log(logger.Info, "listener opened on "+address)
|
2020-10-19 20:17:48 +00:00
|
|
|
|
2020-08-30 12:10:05 +00:00
|
|
|
return pp, nil
|
|
|
|
}
|
|
|
|
|
2021-07-24 13:55:42 +00:00
|
|
|
func (pp *pprof) close() {
|
2023-05-04 18:16:41 +00:00
|
|
|
pp.Log(logger.Info, "listener is closing")
|
2023-07-30 21:03:00 +00:00
|
|
|
pp.httpServer.Close()
|
2021-11-15 19:13:54 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 18:16:41 +00:00
|
|
|
func (pp *pprof) Log(level logger.Level, format string, args ...interface{}) {
|
2021-11-15 19:13:54 +00:00
|
|
|
pp.parent.Log(level, "[pprof] "+format, args...)
|
2020-10-19 20:17:48 +00:00
|
|
|
}
|