mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-26 08:11:55 -06:00
Add PPROFLISTEN (#1019)
* Add PPROFLISTEN env var * Direct logging to more useful places * Space
This commit is contained in:
parent
0c892d59fa
commit
32624697fd
|
@ -15,8 +15,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "net/http/pprof"
|
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common/basecomponent"
|
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||||
"github.com/matrix-org/dendrite/common/keydb"
|
"github.com/matrix-org/dendrite/common/keydb"
|
||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
|
|
|
@ -42,6 +42,8 @@ import (
|
||||||
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
_ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BaseDendrite is a base for creating new instances of dendrite. It parses
|
// BaseDendrite is a base for creating new instances of dendrite. It parses
|
||||||
|
@ -71,6 +73,7 @@ const HTTPClientTimeout = time.Second * 30
|
||||||
func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
|
func NewBaseDendrite(cfg *config.Dendrite, componentName string) *BaseDendrite {
|
||||||
common.SetupStdLogging()
|
common.SetupStdLogging()
|
||||||
common.SetupHookLogging(cfg.Logging, componentName)
|
common.SetupHookLogging(cfg.Logging, componentName)
|
||||||
|
common.SetupPprof()
|
||||||
|
|
||||||
closer, err := cfg.SetupTracing("Dendrite" + componentName)
|
closer, err := cfg.SetupTracing("Dendrite" + componentName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -79,6 +80,17 @@ func callerPrettyfier(f *runtime.Frame) (string, string) {
|
||||||
return funcname, filename
|
return funcname, filename
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetupPprof starts a pprof listener. We use the DefaultServeMux here because it is
|
||||||
|
// simplest, and it gives us the freedom to run pprof on a separate port.
|
||||||
|
func SetupPprof() {
|
||||||
|
if hostPort := os.Getenv("PPROFLISTEN"); hostPort != "" {
|
||||||
|
logrus.Warn("Starting pprof on ", hostPort)
|
||||||
|
go func() {
|
||||||
|
logrus.WithError(http.ListenAndServe(hostPort, nil)).Error("Failed to setup pprof listener")
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetupStdLogging configures the logging format to standard output. Typically, it is called when the config is not yet loaded.
|
// SetupStdLogging configures the logging format to standard output. Typically, it is called when the config is not yet loaded.
|
||||||
func SetupStdLogging() {
|
func SetupStdLogging() {
|
||||||
logrus.SetReportCaller(true)
|
logrus.SetReportCaller(true)
|
||||||
|
|
Loading…
Reference in a new issue