1
0
Fork 0
forked from External/mediamtx

pprof: change capitalization

This commit is contained in:
aler9 2021-03-27 12:23:19 +01:00
parent a57f3d04a7
commit c40fdbae7c
4 changed files with 20 additions and 20 deletions

View file

@ -59,8 +59,8 @@ type Conf struct {
ReadBufferCount int `yaml:"readBufferCount"` ReadBufferCount int `yaml:"readBufferCount"`
Metrics bool `yaml:"metrics"` Metrics bool `yaml:"metrics"`
MetricsPort int `yaml:"metricsPort"` MetricsPort int `yaml:"metricsPort"`
Pprof bool `yaml:"pprof"` PPROF bool `yaml:"pprof"`
PprofPort int `yaml:"pprofPort"` PPROFPort int `yaml:"pprofPort"`
RunOnConnect string `yaml:"runOnConnect"` RunOnConnect string `yaml:"runOnConnect"`
RunOnConnectRestart bool `yaml:"runOnConnectRestart"` RunOnConnectRestart bool `yaml:"runOnConnectRestart"`
@ -143,7 +143,7 @@ func (conf *Conf) fillAndCheck() error {
conf.MetricsPort = 9998 conf.MetricsPort = 9998
} }
if conf.PprofPort == 0 { if conf.PPROFPort == 0 {
conf.MetricsPort = 9999 conf.MetricsPort = 9999
} }

View file

@ -17,25 +17,25 @@ type Parent interface {
Log(logger.Level, string, ...interface{}) Log(logger.Level, string, ...interface{})
} }
// Pprof is a performance metrics exporter. // PPROF is a performance metrics exporter.
type Pprof struct { type PPROF struct {
listener net.Listener listener net.Listener
server *http.Server server *http.Server
} }
// New allocates a Pprof. // New allocates a PPROF.
func New( func New(
listenIP string, listenIP string,
port int, port int,
parent Parent, parent Parent,
) (*Pprof, error) { ) (*PPROF, error) {
address := listenIP + ":" + strconv.FormatInt(int64(port), 10) address := listenIP + ":" + strconv.FormatInt(int64(port), 10)
listener, err := net.Listen("tcp", address) listener, err := net.Listen("tcp", address)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pp := &Pprof{ pp := &PPROF{
listener: listener, listener: listener,
} }
@ -49,12 +49,12 @@ func New(
return pp, nil return pp, nil
} }
// Close closes a Pprof. // Close closes a PPROF.
func (pp *Pprof) Close() { func (pp *PPROF) Close() {
pp.server.Shutdown(context.Background()) pp.server.Shutdown(context.Background())
} }
func (pp *Pprof) run() { func (pp *PPROF) run() {
err := pp.server.Serve(pp.listener) err := pp.server.Serve(pp.listener)
if err != http.ErrServerClosed { if err != http.ErrServerClosed {
panic(err) panic(err)

16
main.go
View file

@ -31,7 +31,7 @@ type program struct {
stats *stats.Stats stats *stats.Stats
logger *logger.Logger logger *logger.Logger
metrics *metrics.Metrics metrics *metrics.Metrics
pprof *pprof.Pprof pprof *pprof.PPROF
serverRTSPPlain *serverrtsp.Server serverRTSPPlain *serverrtsp.Server
serverRTSPTLS *serverrtsp.Server serverRTSPTLS *serverrtsp.Server
serverRTMP *serverrtmp.Server serverRTMP *serverrtmp.Server
@ -179,11 +179,11 @@ func (p *program) createResources(initial bool) error {
} }
} }
if p.conf.Pprof { if p.conf.PPROF {
if p.pprof == nil { if p.pprof == nil {
p.pprof, err = pprof.New( p.pprof, err = pprof.New(
p.conf.ListenIP, p.conf.ListenIP,
p.conf.PprofPort, p.conf.PPROFPort,
p) p)
if err != nil { if err != nil {
return err return err
@ -301,12 +301,12 @@ func (p *program) closeResources(newConf *conf.Conf) {
closeMetrics = true closeMetrics = true
} }
closePprof := false closePPROF := false
if newConf == nil || if newConf == nil ||
newConf.Pprof != p.conf.Pprof || newConf.PPROF != p.conf.PPROF ||
newConf.ListenIP != p.conf.ListenIP || newConf.ListenIP != p.conf.ListenIP ||
newConf.PprofPort != p.conf.PprofPort { newConf.PPROFPort != p.conf.PPROFPort {
closePprof = true closePPROF = true
} }
closeServerPlain := false closeServerPlain := false
@ -406,7 +406,7 @@ func (p *program) closeResources(newConf *conf.Conf) {
p.serverRTSPPlain = nil p.serverRTSPPlain = nil
} }
if closePprof && p.pprof != nil { if closePPROF && p.pprof != nil {
p.pprof.Close() p.pprof.Close()
p.pprof = nil p.pprof = nil
} }

View file

@ -25,7 +25,7 @@ metrics: no
# port of the metrics listener. # port of the metrics listener.
metricsPort: 9998 metricsPort: 9998
# enable pprof to monitor performances. # enable pprof-compatible endpoint to monitor performances.
pprof: no pprof: no
# port of the pprof listener. # port of the pprof listener.
pprofPort: 9999 pprofPort: 9999